001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the License). You may not use this file except in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * Header Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: package com.sun.xml.ws.security.opt.impl.util;
024:
025: import javax.xml.namespace.NamespaceContext;
026: import javax.xml.namespace.QName;
027: import javax.xml.stream.Location;
028: import javax.xml.stream.XMLStreamConstants;
029: import javax.xml.stream.XMLStreamException;
030: import javax.xml.stream.XMLStreamReader;
031:
032: /**
033: *
034: * @author Ashutosh.Shahi@sun.com
035: */
036: public class FilteredXMLStreamReader implements XMLStreamReader {
037:
038: private XMLStreamReader reader = null;
039: private int startElemCounter = 0;
040:
041: /** Creates a new instance of FilteredXMLStreamReader */
042: public FilteredXMLStreamReader(XMLStreamReader reader) {
043: this .reader = reader;
044: }
045:
046: public int getAttributeCount() {
047: return reader.getAttributeCount();
048: }
049:
050: public int getEventType() {
051: return reader.getEventType();
052: }
053:
054: public int getNamespaceCount() {
055: return reader.getNamespaceCount();
056: }
057:
058: public int getTextLength() {
059: return reader.getTextLength();
060: }
061:
062: public int getTextStart() {
063: return reader.getTextStart();
064: }
065:
066: public int next() throws XMLStreamException {
067: int nextEvent = reader.next();
068: if (nextEvent == XMLStreamReader.START_ELEMENT) {
069: startElemCounter++;
070: if (startElemCounter == 1) {
071: return next();
072: }
073: }
074: if (nextEvent == XMLStreamReader.END_ELEMENT) {
075: startElemCounter--;
076: if (startElemCounter == 1) {
077: return next();
078: }
079: }
080: return nextEvent;
081: }
082:
083: public int nextTag() throws XMLStreamException {
084: int eventType = next();
085: while ((eventType == XMLStreamConstants.CHARACTERS && isWhiteSpace()) // skip whitespace
086: || (eventType == XMLStreamConstants.CDATA && isWhiteSpace()) // skip whitespace
087: || eventType == XMLStreamConstants.SPACE
088: || eventType == XMLStreamConstants.PROCESSING_INSTRUCTION
089: || eventType == XMLStreamConstants.COMMENT) {
090: eventType = next();
091: }
092: if (eventType != XMLStreamConstants.START_ELEMENT
093: && eventType != XMLStreamConstants.END_ELEMENT) {
094: throw new XMLStreamException("expected start or end tag",
095: getLocation());
096: }
097: return eventType;
098: }
099:
100: public void close() throws XMLStreamException {
101: reader.close();
102: }
103:
104: public boolean hasName() {
105: return reader.hasName();
106: }
107:
108: public boolean hasNext() throws XMLStreamException {
109: return reader.hasNext();
110: }
111:
112: public boolean hasText() {
113: return reader.hasText();
114: }
115:
116: public boolean isCharacters() {
117: return reader.isCharacters();
118: }
119:
120: public boolean isEndElement() {
121: return reader.isEndElement();
122: }
123:
124: public boolean isStandalone() {
125: return reader.isStandalone();
126: }
127:
128: public boolean isStartElement() {
129: return reader.isStartElement();
130: }
131:
132: public boolean isWhiteSpace() {
133: return reader.isWhiteSpace();
134: }
135:
136: public boolean standaloneSet() {
137: return reader.standaloneSet();
138: }
139:
140: public char[] getTextCharacters() {
141: return reader.getTextCharacters();
142: }
143:
144: public boolean isAttributeSpecified(int i) {
145: return reader.isAttributeSpecified(i);
146: }
147:
148: public int getTextCharacters(int i, char[] c, int i0, int i1)
149: throws XMLStreamException {
150: return reader.getTextCharacters(i, c, i0, i1);
151: }
152:
153: public String getCharacterEncodingScheme() {
154: return reader.getCharacterEncodingScheme();
155: }
156:
157: public String getElementText() throws XMLStreamException {
158: return reader.getElementText();
159: }
160:
161: public String getEncoding() {
162: return reader.getEncoding();
163: }
164:
165: public String getLocalName() {
166: return reader.getLocalName();
167: }
168:
169: public String getNamespaceURI() {
170: return reader.getNamespaceURI();
171: }
172:
173: public String getPIData() {
174: return reader.getPIData();
175: }
176:
177: public String getPITarget() {
178: return reader.getPITarget();
179: }
180:
181: public String getPrefix() {
182: return reader.getPrefix();
183: }
184:
185: public String getText() {
186: return reader.getText();
187: }
188:
189: public String getVersion() {
190: return reader.getVersion();
191: }
192:
193: public String getAttributeLocalName(int i) {
194: return reader.getAttributeLocalName(i);
195: }
196:
197: public String getAttributeNamespace(int i) {
198: return reader.getAttributeNamespace(i);
199: }
200:
201: public String getAttributePrefix(int i) {
202: return reader.getAttributePrefix(i);
203: }
204:
205: public String getAttributeType(int i) {
206: return reader.getAttributeType(i);
207: }
208:
209: public String getAttributeValue(int i) {
210: return reader.getAttributeValue(i);
211: }
212:
213: public String getNamespacePrefix(int i) {
214: return reader.getNamespacePrefix(i);
215: }
216:
217: public String getNamespaceURI(int i) {
218: return reader.getNamespaceURI(i);
219: }
220:
221: public NamespaceContext getNamespaceContext() {
222: return reader.getNamespaceContext();
223: }
224:
225: public QName getName() {
226: return reader.getName();
227: }
228:
229: public QName getAttributeName(int i) {
230: return reader.getAttributeName(i);
231: }
232:
233: public Location getLocation() {
234: return reader.getLocation();
235: }
236:
237: public Object getProperty(String string)
238: throws IllegalArgumentException {
239: return reader.getProperty(string);
240: }
241:
242: public void require(int i, String string, String string0)
243: throws XMLStreamException {
244: reader.require(i, string, string0);
245: }
246:
247: public String getNamespaceURI(String string) {
248: return reader.getNamespaceURI(string);
249: }
250:
251: public String getAttributeValue(String string, String string0) {
252: return reader.getAttributeValue(string, string0);
253: }
254:
255: }
|