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 java.util.ArrayList;
026: import java.util.Iterator;
027: import java.util.Map;
028: import javax.xml.XMLConstants;
029: import javax.xml.namespace.NamespaceContext;
030: import javax.xml.namespace.QName;
031: import javax.xml.stream.Location;
032: import javax.xml.stream.XMLStreamException;
033: import javax.xml.stream.XMLStreamReader;
034:
035: public class VerifiedMessageXMLStreamReader implements XMLStreamReader {
036:
037: private XMLStreamReader reader = null;
038: private NamespaceContext _nsCtx = null;
039:
040: /** Creates a new instance of FilteredXMLStreamReader */
041: public VerifiedMessageXMLStreamReader(XMLStreamReader reader,
042: Map<String, String> bodyENVNS) {
043: this .reader = reader;
044: this ._nsCtx = new InternalNamespaceContext(reader
045: .getNamespaceContext(), bodyENVNS);
046: }
047:
048: public int getAttributeCount() {
049: return reader.getAttributeCount();
050: }
051:
052: public int getEventType() {
053: return reader.getEventType();
054: }
055:
056: public int getNamespaceCount() {
057: return reader.getNamespaceCount();
058: }
059:
060: public int getTextLength() {
061: return reader.getTextLength();
062: }
063:
064: public int getTextStart() {
065: return reader.getTextStart();
066: }
067:
068: public int next() throws XMLStreamException {
069: return reader.next();
070: }
071:
072: public int nextTag() throws XMLStreamException {
073: return reader.nextTag();
074: }
075:
076: public void close() throws XMLStreamException {
077: reader.close();
078: }
079:
080: public boolean hasName() {
081: return reader.hasName();
082: }
083:
084: public boolean hasNext() throws XMLStreamException {
085: return reader.hasNext();
086: }
087:
088: public boolean hasText() {
089: return reader.hasText();
090: }
091:
092: public boolean isCharacters() {
093: return reader.isCharacters();
094: }
095:
096: public boolean isEndElement() {
097: return reader.isEndElement();
098: }
099:
100: public boolean isStandalone() {
101: return reader.isStandalone();
102: }
103:
104: public boolean isStartElement() {
105: return reader.isStartElement();
106: }
107:
108: public boolean isWhiteSpace() {
109: return reader.isWhiteSpace();
110: }
111:
112: public boolean standaloneSet() {
113: return reader.standaloneSet();
114: }
115:
116: public char[] getTextCharacters() {
117: return reader.getTextCharacters();
118: }
119:
120: public boolean isAttributeSpecified(int i) {
121: return reader.isAttributeSpecified(i);
122: }
123:
124: public int getTextCharacters(int i, char[] c, int i0, int i1)
125: throws XMLStreamException {
126: return reader.getTextCharacters(i, c, i0, i1);
127: }
128:
129: public String getCharacterEncodingScheme() {
130: return reader.getCharacterEncodingScheme();
131: }
132:
133: public String getElementText() throws XMLStreamException {
134: return reader.getElementText();
135: }
136:
137: public String getEncoding() {
138: return reader.getEncoding();
139: }
140:
141: public String getLocalName() {
142: return reader.getLocalName();
143: }
144:
145: public String getNamespaceURI() {
146: return reader.getNamespaceURI();
147: }
148:
149: public String getPIData() {
150: return reader.getPIData();
151: }
152:
153: public String getPITarget() {
154: return reader.getPITarget();
155: }
156:
157: public String getPrefix() {
158: return reader.getPrefix();
159: }
160:
161: public String getText() {
162: return reader.getText();
163: }
164:
165: public String getVersion() {
166: return reader.getVersion();
167: }
168:
169: public String getAttributeLocalName(int i) {
170: return reader.getAttributeLocalName(i);
171: }
172:
173: public String getAttributeNamespace(int i) {
174: return reader.getAttributeNamespace(i);
175: }
176:
177: public String getAttributePrefix(int i) {
178: return reader.getAttributePrefix(i);
179: }
180:
181: public String getAttributeType(int i) {
182: return reader.getAttributeType(i);
183: }
184:
185: public String getAttributeValue(int i) {
186: return reader.getAttributeValue(i);
187: }
188:
189: public String getNamespacePrefix(int i) {
190: return reader.getNamespacePrefix(i);
191: }
192:
193: public String getNamespaceURI(int i) {
194: return reader.getNamespaceURI(i);
195: }
196:
197: public NamespaceContext getNamespaceContext() {
198: return _nsCtx;
199: }
200:
201: public QName getName() {
202: return reader.getName();
203: }
204:
205: public QName getAttributeName(int i) {
206: return reader.getAttributeName(i);
207: }
208:
209: public Location getLocation() {
210: return reader.getLocation();
211: }
212:
213: public Object getProperty(String string)
214: throws IllegalArgumentException {
215: return reader.getProperty(string);
216: }
217:
218: public void require(int i, String string, String string0)
219: throws XMLStreamException {
220: reader.require(i, string, string0);
221: }
222:
223: public String getNamespaceURI(String string) {
224: return reader.getNamespaceURI(string);
225: }
226:
227: public String getAttributeValue(String string, String string0) {
228: return reader.getAttributeValue(string, string0);
229: }
230:
231: private static final class InternalNamespaceContext implements
232: NamespaceContext {
233:
234: private NamespaceContext parent;
235:
236: private Map<String, String> bodyEnvNs;
237:
238: public InternalNamespaceContext(NamespaceContext parent,
239: Map<String, String> bodyEnvNs) {
240: this .parent = parent;
241: this .bodyEnvNs = bodyEnvNs;
242: }
243:
244: public String getNamespaceURI(String prefix) {
245: String nsUri = parent.getNamespaceURI(prefix);
246: if (nsUri == null || nsUri == XMLConstants.NULL_NS_URI) {
247: nsUri = bodyEnvNs.get(prefix);
248: }
249: return nsUri;
250: }
251:
252: public String getPrefix(String namespaceURI) {
253: if (namespaceURI == null) {
254: return null;
255: }
256: String prefix = parent.getPrefix(namespaceURI);
257: if (prefix == null) {
258: Iterator it = this .bodyEnvNs.keySet().iterator();
259: while (it.hasNext()) {
260: String nextKey = (String) it.next();
261: if (namespaceURI
262: .equals(this .bodyEnvNs.get(nextKey))) {
263: return nextKey;
264: }
265: }
266: }
267: return prefix;
268: }
269:
270: public Iterator getPrefixes(String namespaceURI) {
271: return new InternalIterator(parent
272: .getPrefixes(namespaceURI), this .bodyEnvNs,
273: namespaceURI);
274: }
275:
276: }
277:
278: private static final class InternalIterator implements Iterator {
279: ArrayList<String> arr = new ArrayList<String>();
280: Iterator internal = null;
281:
282: public InternalIterator(Iterator parent,
283: Map<String, String> bodyEnvNs, String namespaceURI) {
284: while (parent.hasNext()) {
285: arr.add((String) parent.next());
286: }
287: if (namespaceURI != null) {
288: Iterator<Map.Entry<String, String>> it = bodyEnvNs
289: .entrySet().iterator();
290: while (it.hasNext()) {
291: Map.Entry<String, String> entry = it.next();
292: if (namespaceURI.equals(entry.getValue())) {
293: arr.add(entry.getKey());
294: }
295: }
296: }
297: internal = arr.iterator();
298: }
299:
300: public boolean hasNext() {
301: return internal.hasNext();
302: }
303:
304: public Object next() {
305: return internal.next();
306: }
307:
308: public void remove() {
309: throw new UnsupportedOperationException(
310: "Remove Not Supported");
311: }
312: }
313: }
|