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.client.adapters;
18
19import com.android.layout.remote.api.RemoteXmlPullParser;
20import com.android.layout.remote.util.RemoteInputStream;
21import com.android.layout.remote.util.StreamUtil;
22import com.android.tools.layoutlib.annotations.NotNull;
23
24import org.xmlpull.v1.XmlPullParser;
25import org.xmlpull.v1.XmlPullParserException;
26
27import java.io.IOException;
28import java.io.Reader;
29import java.rmi.RemoteException;
30import java.rmi.server.UnicastRemoteObject;
31
32public class RemoteXmlPullParserAdapter implements RemoteXmlPullParser {
33    protected XmlPullParser mDelegate;
34
35    protected RemoteXmlPullParserAdapter(@NotNull XmlPullParser delegate) {
36        mDelegate = delegate;
37    }
38
39    public static RemoteXmlPullParser create(@NotNull XmlPullParser delegate)
40            throws RemoteException {
41        return (RemoteXmlPullParser) UnicastRemoteObject.exportObject(
42                new RemoteXmlPullParserAdapter(delegate), 0);
43    }
44
45    @Override
46    public void setFeature(String name, boolean state)
47            throws XmlPullParserException, RemoteException {
48        mDelegate.setFeature(name, state);
49    }
50
51    @Override
52    public boolean getFeature(String name) throws RemoteException {
53        return mDelegate.getFeature(name);
54    }
55
56    @Override
57    public void setProperty(String name, Object value)
58            throws XmlPullParserException, RemoteException {
59        mDelegate.setProperty(name, value);
60    }
61
62    @Override
63    public Object getProperty(String name) throws RemoteException {
64        return mDelegate.getProperty(name);
65    }
66
67    @Override
68    public void setInput(Reader in) throws XmlPullParserException, RemoteException {
69        mDelegate.setInput(in);
70    }
71
72    @Override
73    public void setInput(RemoteInputStream inputStream, String inputEncoding)
74            throws XmlPullParserException, RemoteException {
75        mDelegate.setInput(StreamUtil.getInputStream(inputStream), inputEncoding);
76    }
77
78    @Override
79    public String getInputEncoding() throws RemoteException {
80        return mDelegate.getInputEncoding();
81    }
82
83    @Override
84    public void defineEntityReplacementText(String entityName, String replacementText)
85            throws XmlPullParserException {
86
87    }
88
89    @Override
90    public int getNamespaceCount(int depth) throws XmlPullParserException, RemoteException {
91        return mDelegate.getNamespaceCount(depth);
92    }
93
94    @Override
95    public String getNamespacePrefix(int pos) throws XmlPullParserException, RemoteException {
96        return mDelegate.getNamespacePrefix(pos);
97    }
98
99    @Override
100    public String getNamespaceUri(int pos) throws XmlPullParserException, RemoteException {
101        return mDelegate.getNamespaceUri(pos);
102    }
103
104    @Override
105    public String getNamespace(String prefix) throws RemoteException {
106        return mDelegate.getNamespace(prefix);
107    }
108
109    @Override
110    public int getDepth() throws RemoteException {
111        return mDelegate.getDepth();
112    }
113
114    @Override
115    public String getPositionDescription() throws RemoteException {
116        return mDelegate.getPositionDescription();
117    }
118
119    @Override
120    public int getLineNumber() throws RemoteException {
121        return mDelegate.getLineNumber();
122    }
123
124    @Override
125    public int getColumnNumber() throws RemoteException {
126        return mDelegate.getColumnNumber();
127    }
128
129    @Override
130    public boolean isWhitespace() throws XmlPullParserException, RemoteException {
131        return mDelegate.isWhitespace();
132    }
133
134    @Override
135    public String getText() throws RemoteException {
136        return mDelegate.getText();
137    }
138
139    @Override
140    public char[] getTextCharacters(int[] holderForStartAndLength) throws RemoteException {
141        return mDelegate.getTextCharacters(holderForStartAndLength);
142    }
143
144    @Override
145    public String getNamespace() throws RemoteException {
146        return mDelegate.getNamespace();
147    }
148
149    @Override
150    public String getName() throws RemoteException {
151        return mDelegate.getName();
152    }
153
154    @Override
155    public String getPrefix() throws RemoteException {
156        return mDelegate.getPrefix();
157    }
158
159    @Override
160    public boolean isEmptyElementTag() throws XmlPullParserException, RemoteException {
161        return mDelegate.isEmptyElementTag();
162    }
163
164    @Override
165    public int getAttributeCount() throws RemoteException {
166        return mDelegate.getAttributeCount();
167    }
168
169    @Override
170    public String getAttributeNamespace(int index) throws RemoteException {
171        return mDelegate.getAttributeNamespace(index);
172    }
173
174    @Override
175    public String getAttributeName(int index) throws RemoteException {
176        return mDelegate.getAttributeName(index);
177    }
178
179    @Override
180    public String getAttributePrefix(int index) throws RemoteException {
181        return mDelegate.getAttributePrefix(index);
182    }
183
184    @Override
185    public String getAttributeType(int index) throws RemoteException {
186        return mDelegate.getAttributeType(index);
187    }
188
189    @Override
190    public boolean isAttributeDefault(int index) throws RemoteException {
191        return mDelegate.isAttributeDefault(index);
192    }
193
194    @Override
195    public String getAttributeValue(int index) throws RemoteException {
196        return mDelegate.getAttributeValue(index);
197    }
198
199    @Override
200    public String getAttributeValue(String namespace, String name) throws RemoteException {
201        return mDelegate.getAttributeValue(namespace, name);
202    }
203
204    @Override
205    public int getEventType() throws XmlPullParserException, RemoteException {
206        return mDelegate.getEventType();
207    }
208
209    @Override
210    public int next() throws XmlPullParserException, IOException, RemoteException {
211        return mDelegate.next();
212    }
213
214    @Override
215    public int nextToken() throws XmlPullParserException, IOException, RemoteException {
216        return mDelegate.nextToken();
217    }
218
219    @Override
220    public void require(int type, String namespace, String name)
221            throws XmlPullParserException, IOException, RemoteException {
222        mDelegate.require(type, namespace, name);
223    }
224
225    @Override
226    public String nextText() throws XmlPullParserException, IOException, RemoteException {
227        return mDelegate.nextText();
228    }
229
230    @Override
231    public int nextTag() throws XmlPullParserException, IOException, RemoteException {
232        return mDelegate.nextTag();
233    }
234}
235