1/* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package com.android.layoutlib.bridge.remote.server.adapters; 18 19import com.android.layout.remote.api.RemoteXmlPullParser; 20import com.android.layout.remote.util.RemoteInputStreamAdapter; 21import com.android.tools.layoutlib.annotations.NotNull; 22 23import org.xmlpull.v1.XmlPullParser; 24import org.xmlpull.v1.XmlPullParserException; 25 26import java.io.IOException; 27import java.io.InputStream; 28import java.io.Reader; 29import java.rmi.RemoteException; 30 31class RemoteXmlPullParserAdapter implements XmlPullParser { 32 protected RemoteXmlPullParser mDelegate; 33 34 RemoteXmlPullParserAdapter(@NotNull RemoteXmlPullParser remote) { 35 mDelegate = remote; 36 } 37 38 @Override 39 public void setFeature(String name, boolean state) throws XmlPullParserException { 40 try { 41 mDelegate.setFeature(name, state); 42 } catch (RemoteException e) { 43 throw new RuntimeException(e); 44 } 45 } 46 47 @Override 48 public boolean getFeature(String name) { 49 try { 50 return mDelegate.getFeature(name); 51 } catch (RemoteException e) { 52 throw new RuntimeException(e); 53 } 54 } 55 56 @Override 57 public void setProperty(String name, Object value) throws XmlPullParserException { 58 try { 59 mDelegate.setProperty(name, value); 60 } catch (RemoteException e) { 61 throw new RuntimeException(e); 62 } 63 } 64 65 @Override 66 public Object getProperty(String name) { 67 try { 68 return mDelegate.getProperty(name); 69 } catch (RemoteException e) { 70 throw new RuntimeException(e); 71 } 72 } 73 74 @Override 75 public void setInput(Reader in) throws XmlPullParserException { 76 try { 77 mDelegate.setInput(in); 78 } catch (RemoteException e) { 79 throw new RuntimeException(e); 80 } 81 } 82 83 @Override 84 public void setInput(InputStream inputStream, String inputEncoding) 85 throws XmlPullParserException { 86 try { 87 mDelegate.setInput(RemoteInputStreamAdapter.create(inputStream), inputEncoding); 88 } catch (RemoteException e) { 89 throw new RuntimeException(e); 90 } 91 } 92 93 @Override 94 public String getInputEncoding() { 95 try { 96 return mDelegate.getInputEncoding(); 97 } catch (RemoteException e) { 98 throw new RuntimeException(e); 99 } 100 } 101 102 @Override 103 public void defineEntityReplacementText(String entityName, String replacementText) 104 throws XmlPullParserException { 105 try { 106 mDelegate.defineEntityReplacementText(entityName, replacementText); 107 } catch (RemoteException e) { 108 throw new RuntimeException(e); 109 } 110 } 111 112 @Override 113 public int getNamespaceCount(int depth) throws XmlPullParserException { 114 try { 115 return mDelegate.getNamespaceCount(depth); 116 } catch (RemoteException e) { 117 throw new RuntimeException(e); 118 } 119 } 120 121 @Override 122 public String getNamespacePrefix(int pos) throws XmlPullParserException { 123 try { 124 return mDelegate.getNamespacePrefix(pos); 125 } catch (RemoteException e) { 126 throw new RuntimeException(e); 127 } 128 } 129 130 @Override 131 public String getNamespaceUri(int pos) throws XmlPullParserException { 132 try { 133 return mDelegate.getNamespaceUri(pos); 134 } catch (RemoteException e) { 135 throw new RuntimeException(e); 136 } 137 } 138 139 @Override 140 public String getNamespace(String prefix) { 141 try { 142 return mDelegate.getNamespace(prefix); 143 } catch (RemoteException e) { 144 throw new RuntimeException(e); 145 } 146 } 147 148 @Override 149 public int getDepth() { 150 try { 151 return mDelegate.getDepth(); 152 } catch (RemoteException e) { 153 throw new RuntimeException(e); 154 } 155 } 156 157 @Override 158 public String getPositionDescription() { 159 try { 160 return mDelegate.getPositionDescription(); 161 } catch (RemoteException e) { 162 throw new RuntimeException(e); 163 } 164 } 165 166 @Override 167 public int getLineNumber() { 168 try { 169 return mDelegate.getLineNumber(); 170 } catch (RemoteException e) { 171 throw new RuntimeException(e); 172 } 173 } 174 175 @Override 176 public int getColumnNumber() { 177 try { 178 return mDelegate.getColumnNumber(); 179 } catch (RemoteException e) { 180 throw new RuntimeException(e); 181 } 182 } 183 184 @Override 185 public boolean isWhitespace() throws XmlPullParserException { 186 try { 187 return mDelegate.isWhitespace(); 188 } catch (RemoteException e) { 189 throw new RuntimeException(e); 190 } 191 } 192 193 @Override 194 public String getText() { 195 try { 196 return mDelegate.getText(); 197 } catch (RemoteException e) { 198 throw new RuntimeException(e); 199 } 200 } 201 202 @Override 203 public char[] getTextCharacters(int[] holderForStartAndLength) { 204 try { 205 return mDelegate.getTextCharacters(holderForStartAndLength); 206 } catch (RemoteException e) { 207 throw new RuntimeException(e); 208 } 209 } 210 211 @Override 212 public String getNamespace() { 213 try { 214 return mDelegate.getNamespace(); 215 } catch (RemoteException e) { 216 throw new RuntimeException(e); 217 } 218 } 219 220 @Override 221 public String getName() { 222 try { 223 return mDelegate.getName(); 224 } catch (RemoteException e) { 225 throw new RuntimeException(e); 226 } 227 } 228 229 @Override 230 public String getPrefix() { 231 try { 232 return mDelegate.getPrefix(); 233 } catch (RemoteException e) { 234 throw new RuntimeException(e); 235 } 236 } 237 238 @Override 239 public boolean isEmptyElementTag() throws XmlPullParserException { 240 try { 241 return mDelegate.isEmptyElementTag(); 242 } catch (RemoteException e) { 243 throw new RuntimeException(e); 244 } 245 } 246 247 @Override 248 public int getAttributeCount() { 249 try { 250 return mDelegate.getAttributeCount(); 251 } catch (RemoteException e) { 252 throw new RuntimeException(e); 253 } 254 } 255 256 @Override 257 public String getAttributeNamespace(int index) { 258 try { 259 return mDelegate.getAttributeNamespace(index); 260 } catch (RemoteException e) { 261 throw new RuntimeException(e); 262 } 263 } 264 265 @Override 266 public String getAttributeName(int index) { 267 try { 268 return mDelegate.getAttributeName(index); 269 } catch (RemoteException e) { 270 throw new RuntimeException(e); 271 } 272 } 273 274 @Override 275 public String getAttributePrefix(int index) { 276 try { 277 return mDelegate.getAttributePrefix(index); 278 } catch (RemoteException e) { 279 throw new RuntimeException(e); 280 } 281 } 282 283 @Override 284 public String getAttributeType(int index) { 285 try { 286 return mDelegate.getAttributeType(index); 287 } catch (RemoteException e) { 288 throw new RuntimeException(e); 289 } 290 } 291 292 @Override 293 public boolean isAttributeDefault(int index) { 294 try { 295 return mDelegate.isAttributeDefault(index); 296 } catch (RemoteException e) { 297 throw new RuntimeException(e); 298 } 299 } 300 301 @Override 302 public String getAttributeValue(int index) { 303 try { 304 return mDelegate.getAttributeValue(index); 305 } catch (RemoteException e) { 306 throw new RuntimeException(e); 307 } 308 } 309 310 @Override 311 public String getAttributeValue(String namespace, String name) { 312 try { 313 return mDelegate.getAttributeValue(namespace, name); 314 } catch (RemoteException e) { 315 throw new RuntimeException(e); 316 } 317 } 318 319 @Override 320 public int getEventType() throws XmlPullParserException { 321 try { 322 return mDelegate.getEventType(); 323 } catch (RemoteException e) { 324 throw new RuntimeException(e); 325 } 326 } 327 328 @Override 329 public int next() throws XmlPullParserException, IOException { 330 return mDelegate.next(); 331 } 332 333 @Override 334 public int nextToken() throws XmlPullParserException, IOException { 335 return mDelegate.nextToken(); 336 } 337 338 @Override 339 public void require(int type, String namespace, String name) 340 throws XmlPullParserException, IOException { 341 mDelegate.require(type, namespace, name); 342 } 343 344 @Override 345 public String nextText() throws XmlPullParserException, IOException { 346 return mDelegate.nextText(); 347 } 348 349 @Override 350 public int nextTag() throws XmlPullParserException, IOException { 351 return mDelegate.nextTag(); 352 } 353} 354