001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.staxutils;
019:
020: import javax.xml.namespace.NamespaceContext;
021: import javax.xml.namespace.QName;
022: import javax.xml.stream.Location;
023: import javax.xml.stream.XMLStreamConstants;
024: import javax.xml.stream.XMLStreamException;
025: import javax.xml.stream.XMLStreamReader;
026:
027: public class DepthXMLStreamReader implements XMLStreamReader {
028:
029: protected XMLStreamReader reader;
030: private int depth;
031:
032: public DepthXMLStreamReader(XMLStreamReader r) {
033: this .reader = r;
034: }
035:
036: public XMLStreamReader getReader() {
037: return this .reader;
038: }
039:
040: public int getDepth() {
041: return depth;
042: }
043:
044: public void close() throws XMLStreamException {
045: reader.close();
046: }
047:
048: public int getAttributeCount() {
049: return reader.getAttributeCount();
050: }
051:
052: public String getAttributeLocalName(int arg0) {
053: return reader.getAttributeLocalName(arg0);
054: }
055:
056: public QName getAttributeName(int arg0) {
057: return reader.getAttributeName(arg0);
058: }
059:
060: public String getAttributeNamespace(int arg0) {
061: return reader.getAttributeNamespace(arg0);
062: }
063:
064: public String getAttributePrefix(int arg0) {
065: return reader.getAttributePrefix(arg0);
066: }
067:
068: public String getAttributeType(int arg0) {
069: return reader.getAttributeType(arg0);
070: }
071:
072: public String getAttributeValue(int arg0) {
073: return reader.getAttributeValue(arg0);
074: }
075:
076: public String getAttributeValue(String arg0, String arg1) {
077: return reader.getAttributeValue(arg0, arg1);
078: }
079:
080: public String getCharacterEncodingScheme() {
081: return reader.getCharacterEncodingScheme();
082: }
083:
084: public String getElementText() throws XMLStreamException {
085: String ret = reader.getElementText();
086: depth--;
087: return ret;
088: }
089:
090: public String getEncoding() {
091: return reader.getEncoding();
092: }
093:
094: public int getEventType() {
095: return reader.getEventType();
096: }
097:
098: public String getLocalName() {
099: return reader.getLocalName();
100: }
101:
102: public Location getLocation() {
103: return reader.getLocation();
104: }
105:
106: public QName getName() {
107: return reader.getName();
108: }
109:
110: public NamespaceContext getNamespaceContext() {
111: return reader.getNamespaceContext();
112: }
113:
114: public int getNamespaceCount() {
115: return reader.getNamespaceCount();
116: }
117:
118: public String getNamespacePrefix(int arg0) {
119: return reader.getNamespacePrefix(arg0);
120: }
121:
122: public String getNamespaceURI() {
123: return reader.getNamespaceURI();
124: }
125:
126: public String getNamespaceURI(int arg0) {
127:
128: return reader.getNamespaceURI(arg0);
129: }
130:
131: public String getNamespaceURI(String arg0) {
132: return reader.getNamespaceURI(arg0);
133: }
134:
135: public String getPIData() {
136: return reader.getPIData();
137: }
138:
139: public String getPITarget() {
140: return reader.getPITarget();
141: }
142:
143: public String getPrefix() {
144: return reader.getPrefix();
145: }
146:
147: public Object getProperty(String arg0)
148: throws IllegalArgumentException {
149:
150: return reader.getProperty(arg0);
151: }
152:
153: public String getText() {
154: return reader.getText();
155: }
156:
157: public char[] getTextCharacters() {
158: return reader.getTextCharacters();
159: }
160:
161: public int getTextCharacters(int arg0, char[] arg1, int arg2,
162: int arg3) throws XMLStreamException {
163: return reader.getTextCharacters(arg0, arg1, arg2, arg3);
164: }
165:
166: public int getTextLength() {
167: return reader.getTextLength();
168: }
169:
170: public int getTextStart() {
171: return reader.getTextStart();
172: }
173:
174: public String getVersion() {
175: return reader.getVersion();
176: }
177:
178: public boolean hasName() {
179: return reader.hasName();
180: }
181:
182: public boolean hasNext() throws XMLStreamException {
183: return reader.hasNext();
184: }
185:
186: public boolean hasText() {
187: return reader.hasText();
188: }
189:
190: public boolean isAttributeSpecified(int arg0) {
191: return reader.isAttributeSpecified(arg0);
192: }
193:
194: public boolean isCharacters() {
195: return reader.isCharacters();
196: }
197:
198: public boolean isEndElement() {
199: return reader.isEndElement();
200: }
201:
202: public boolean isStandalone() {
203: return reader.isStandalone();
204: }
205:
206: public boolean isStartElement() {
207: return reader.isStartElement();
208: }
209:
210: public boolean isWhiteSpace() {
211: return reader.isWhiteSpace();
212: }
213:
214: public int next() throws XMLStreamException {
215: int next = reader.next();
216:
217: if (next == START_ELEMENT) {
218: depth++;
219: } else if (next == END_ELEMENT) {
220: depth--;
221: }
222:
223: return next;
224: }
225:
226: public int nextTag() throws XMLStreamException {
227: int eventType = next();
228: while ((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace())
229: || (eventType == XMLStreamConstants.CDATA && isWhiteSpace())
230: // skip whitespace
231: || eventType == XMLStreamConstants.SPACE
232: || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
233: || eventType == XMLStreamConstants.COMMENT) {
234: eventType = next();
235: }
236: if (eventType != XMLStreamConstants.START_ELEMENT
237: && eventType != XMLStreamConstants.END_ELEMENT) {
238: throw new XMLStreamException("expected start or end tag",
239: getLocation());
240: }
241: return eventType;
242: }
243:
244: public void require(int arg0, String arg1, String arg2)
245: throws XMLStreamException {
246: reader.require(arg0, arg1, arg2);
247: }
248:
249: public boolean standaloneSet() {
250: return reader.standaloneSet();
251: }
252:
253: public int hashCode() {
254: return reader.hashCode();
255: }
256:
257: public boolean equals(Object arg0) {
258: return reader.equals(arg0);
259: }
260:
261: public String toString() {
262: return reader.toString();
263: }
264: }
|