KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis2 > clientapi > StreamWrapper


1 package org.apache.axis2.clientapi;
2
3 import javax.xml.namespace.NamespaceContext JavaDoc;
4 import javax.xml.namespace.QName JavaDoc;
5 import javax.xml.stream.Location;
6 import javax.xml.stream.XMLStreamException;
7 import javax.xml.stream.XMLStreamReader;
8
9 /*
10 * Copyright 2004,2005 The Apache Software Foundation.
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License");
13 * you may not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS,
20 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 *
24 *
25 */

26 public class StreamWrapper implements XMLStreamReader{
27
28     private XMLStreamReader realReader = null;
29     private static final int STATE_SWITCHED = 0;
30     private static final int STATE_INIT = 1;
31     private static final int STATE_SWITHC_AT_NEXT = 2;
32
33     private int state = STATE_INIT;
34     private int prevState = state;
35
36     public StreamWrapper(XMLStreamReader realReader) {
37         if (realReader==null){
38             throw new UnsupportedOperationException JavaDoc("Reader cannot be null");
39         }
40         this.realReader = realReader;
41     }
42
43     public Object JavaDoc getProperty(String JavaDoc s) throws IllegalArgumentException JavaDoc {
44         if(prevState!=STATE_INIT){
45             return realReader.getProperty(s);
46         }else{
47             throw new IllegalArgumentException JavaDoc();
48         }
49     }
50
51     public int next() throws XMLStreamException {
52
53         prevState = state;
54
55         if (state==STATE_SWITCHED){
56             return realReader.next();
57         }else if (state==STATE_INIT){
58             if (realReader.getEventType()==START_DOCUMENT){
59                 state = STATE_SWITCHED;
60                 return realReader.getEventType();
61             }else{
62                 state = STATE_SWITHC_AT_NEXT;
63                 return START_DOCUMENT;
64             }
65         }else if (state==STATE_SWITHC_AT_NEXT) {
66             state = STATE_SWITCHED;
67             return realReader.getEventType();
68         }else{
69             throw new UnsupportedOperationException JavaDoc();
70         }
71
72     }
73
74     public void require(int i, String JavaDoc s, String JavaDoc s1) throws XMLStreamException {
75         if(prevState!=STATE_INIT){
76             realReader.require(i, s, s1);
77         }
78     }
79
80     public String JavaDoc getElementText() throws XMLStreamException {
81         if(prevState!=STATE_INIT){
82             return realReader.getElementText();
83         }else{
84             throw new XMLStreamException();
85         }
86     }
87
88     public int nextTag() throws XMLStreamException {
89         if(prevState!=STATE_INIT){
90             return realReader.nextTag();
91         }else{
92             throw new XMLStreamException();
93         }
94     }
95
96     public boolean hasNext() throws XMLStreamException {
97         if(prevState!=STATE_INIT){
98             return realReader.hasNext();
99         }else{
100           return true;
101         }
102     }
103
104     public void close() throws XMLStreamException {
105         if(prevState!=STATE_INIT){
106             realReader.close();
107         }else{
108             throw new XMLStreamException();
109         }
110     }
111
112     public String JavaDoc getNamespaceURI(String JavaDoc s) {
113         if(prevState!=STATE_INIT){
114             return realReader.getNamespaceURI(s);
115         }else{
116             return null;
117         }
118     }
119
120     public boolean isStartElement() {
121         if(prevState!=STATE_INIT){
122             return realReader.isStartElement();
123         }else{
124             return false;
125         }
126     }
127
128     public boolean isEndElement() {
129         if(prevState!=STATE_INIT){
130             return realReader.isEndElement();
131         }else{
132             return false;
133         }
134     }
135
136     public boolean isCharacters() {
137         if(prevState!=STATE_INIT){
138             return realReader.isCharacters();
139         }else{
140             return false;
141         }
142     }
143
144     public boolean isWhiteSpace() {
145         if(prevState!=STATE_INIT){
146             return realReader.isWhiteSpace();
147         }else{
148             return false;
149         }
150     }
151
152     public String JavaDoc getAttributeValue(String JavaDoc s, String JavaDoc s1) {
153         if(prevState!=STATE_INIT){
154             return realReader.getAttributeValue(s,s1);
155         }else{
156             return null;
157         }
158     }
159
160     public int getAttributeCount() {
161         if(prevState!=STATE_INIT){
162             return realReader.getAttributeCount();
163         }else{
164             return 0;
165         }
166     }
167
168     public QName JavaDoc getAttributeName(int i) {
169         if(prevState!=STATE_INIT){
170             return realReader.getAttributeName(i);
171         }else{
172             return null;
173         }
174     }
175
176     public String JavaDoc getAttributeNamespace(int i) {
177         if(prevState!=STATE_INIT){
178             return realReader.getAttributeNamespace(i);
179         }else{
180             return null;
181         }
182     }
183
184     public String JavaDoc getAttributeLocalName(int i) {
185         if(prevState!=STATE_INIT){
186             return realReader.getAttributeLocalName(i);
187         }else{
188             return null;
189         }
190     }
191
192     public String JavaDoc getAttributePrefix(int i) {
193         if(prevState!=STATE_INIT){
194             return realReader.getAttributePrefix(i);
195         }else{
196             return null;
197         }
198     }
199
200     public String JavaDoc getAttributeType(int i) {
201         if(prevState!=STATE_INIT){
202             return realReader.getAttributeType(i);
203         }else{
204             return null;
205         }
206     }
207
208     public String JavaDoc getAttributeValue(int i) {
209         if(prevState!=STATE_INIT){
210             return realReader.getAttributeValue(i);
211         }else{
212             return null;
213         }
214     }
215
216     public boolean isAttributeSpecified(int i) {
217         if(prevState!=STATE_INIT){
218             return realReader.isAttributeSpecified(i);
219         }else{
220             return false;
221         }
222     }
223
224     public int getNamespaceCount() {
225         if(prevState!=STATE_INIT){
226             return realReader.getNamespaceCount();
227         }else{
228             return 0;
229         }
230     }
231
232     public String JavaDoc getNamespacePrefix(int i) {
233         if(prevState!=STATE_INIT){
234             return realReader.getNamespacePrefix(i);
235         }else{
236             return null;
237         }
238     }
239
240     public String JavaDoc getNamespaceURI(int i) {
241         if(prevState!=STATE_INIT){
242             return realReader.getNamespaceURI(i);
243         }else{
244             return null;
245         }
246     }
247
248     public NamespaceContext JavaDoc getNamespaceContext() {
249         if(prevState!=STATE_INIT){
250             return realReader.getNamespaceContext();
251         }else{
252             return null;
253         }
254     }
255
256     public int getEventType() {
257         if(prevState==STATE_INIT){
258             return START_DOCUMENT;
259         }else{
260             return realReader.getEventType();
261         }
262     }
263
264     public String JavaDoc getText() {
265         if(prevState!=STATE_INIT){
266             return realReader.getText();
267         }else{
268             return null;
269         }
270     }
271
272     public char[] getTextCharacters() {
273         if(prevState!=STATE_INIT){
274             return realReader.getTextCharacters();
275         }else{
276             return new char[0] ;
277         }
278     }
279
280     public int getTextCharacters(int i, char[] chars, int i1, int i2) throws XMLStreamException {
281         if(prevState!=STATE_INIT){
282             return realReader.getTextCharacters(i,chars,i1,i2);
283         }else{
284             return 0 ;
285         }
286     }
287
288     public int getTextStart() {
289         if(prevState!=STATE_INIT){
290             return realReader.getTextStart();
291         }else{
292             return 0 ;
293         }
294     }
295
296     public int getTextLength() {
297         if(prevState!=STATE_INIT){
298             return realReader.getTextStart();
299         }else{
300             return 0 ;
301         }
302     }
303
304     public String JavaDoc getEncoding() {
305         if(prevState!=STATE_INIT){
306             return realReader.getEncoding();
307         }else{
308             return null ;
309         }
310     }
311
312     public boolean hasText() {
313         if(prevState!=STATE_INIT){
314             return realReader.hasText();
315         }else{
316             return false ;
317         }
318     }
319
320     public Location getLocation() {
321         if(prevState!=STATE_INIT){
322             return realReader.getLocation();
323         }else{
324             return null ;
325         }
326     }
327
328     public QName JavaDoc getName() {
329         if(prevState!=STATE_INIT){
330             return realReader.getName();
331         }else{
332             return null ;
333         }
334     }
335
336     public String JavaDoc getLocalName() {
337         if(prevState!=STATE_INIT){
338             return realReader.getLocalName();
339         }else{
340             return null ;
341         }
342     }
343
344     public boolean hasName() {
345         if(prevState!=STATE_INIT){
346             return realReader.hasName();
347         }else{
348             return false ;
349         }
350     }
351
352     public String JavaDoc getNamespaceURI() {
353         if(prevState!=STATE_INIT){
354             return realReader.getNamespaceURI();
355         }else{
356             return null ;
357         }
358     }
359
360     public String JavaDoc getPrefix() {
361         if(prevState!=STATE_INIT){
362             return realReader.getPrefix();
363         }else{
364             return null ;
365         }
366     }
367
368     public String JavaDoc getVersion() {
369         if(prevState!=STATE_INIT){
370             return realReader.getVersion();
371         }else{
372             return null ;
373         }
374     }
375
376     public boolean isStandalone() {
377         if(prevState!=STATE_INIT){
378             return realReader.isStandalone();
379         }else{
380             return false ;
381         }
382     }
383
384     public boolean standaloneSet() {
385         if(prevState!=STATE_INIT){
386             return realReader.standaloneSet();
387         }else{
388             return false ;
389         }
390     }
391
392     public String JavaDoc getCharacterEncodingScheme() {
393         if(prevState!=STATE_INIT){
394             return realReader.getCharacterEncodingScheme();
395         }else{
396             return null ;
397         }
398     }
399
400     public String JavaDoc getPITarget() {
401         if(prevState!=STATE_INIT){
402             return realReader.getPITarget();
403         }else{
404             return null ;
405         }
406     }
407
408     public String JavaDoc getPIData() {
409         if(prevState!=STATE_INIT){
410             return realReader.getPIData();
411         }else{
412             return null ;
413         }
414     }
415 }
416
Popular Tags