001: /*
002:
003: * The contents of this file are subject to the terms
004:
005: * of the Common Development and Distribution License
006:
007: * (the License). You may not use this file except in
008:
009: * compliance with the License.
010:
011: *
012:
013: * You can obtain a copy of the license at
014:
015: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
016:
017: * See the License for the specific language governing
018:
019: * permissions and limitations under the License.
020:
021: *
022:
023: * When distributing Covered Code, include this CDDL
024:
025: * Header Notice in each file and include the License file
026:
027: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
028:
029: * If applicable, add the following below the CDDL Header,
030:
031: * with the fields enclosed by brackets [] replaced by
032:
033: * you own identifying information:
034:
035: * "Portions Copyrighted [year] [name of copyright owner]"
036:
037: *
038:
039: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
040:
041: */
042:
043: package com.sun.xml.ws.security.opt.impl.util;
044:
045: import java.util.ArrayList;
046:
047: import java.util.Iterator;
048:
049: import com.sun.xml.wss.impl.MessageConstants;
050:
051: /**
052:
053: *
054:
055: * @author K.Venugopal@sun.com
056:
057: */
058:
059: public class NamespaceContextEx implements
060: org.jvnet.staxex.NamespaceContextEx {
061:
062: private boolean addedWSSNS = false;
063: private boolean samlNS = false;
064: private boolean dsNS = false;
065: private boolean encNS = false;
066: private boolean scNS = false;
067: private boolean exc14NS = false;
068: private boolean addedWSS11NS = false;
069: private ArrayList<org.jvnet.staxex.NamespaceContextEx.Binding> list = new ArrayList<org.jvnet.staxex.NamespaceContextEx.Binding>();
070:
071: /** Creates a new instance of NamespaceContextEx */
072:
073: public NamespaceContextEx() {
074: this .add("S", "http://schemas.xmlsoap.org/soap/envelope/");
075: addDefaultNSDecl();
076: }
077:
078: public NamespaceContextEx(boolean soap12Version) {
079: if (soap12Version) {
080: this .add("S", "http://www.w3.org/2003/05/soap-envelope");//SOAP 12
081: } else {
082: this .add("S", "http://schemas.xmlsoap.org/soap/envelope/");
083: }
084: addDefaultNSDecl();
085: }
086:
087: private void addDefaultNSDecl() {
088:
089: }
090:
091: public void addWSSNS() {
092: if (!addedWSSNS) {
093: this .add("wsse", MessageConstants.WSSE_NS);
094: this .add("wsu", MessageConstants.WSU_NS);
095: addedWSSNS = true;
096: }
097: }
098:
099: public void addWSS11NS() {
100: if (!addedWSS11NS) {
101: this .add("wsse11", MessageConstants.WSSE11_NS);
102: addedWSS11NS = true;
103: }
104: }
105:
106: public void addSignatureNS() {
107: addWSSNS();
108: if (!dsNS) {
109: this .add("ds", MessageConstants.DSIG_NS);
110: dsNS = true;
111: }
112: }
113:
114: public void addEncryptionNS() {
115: addWSSNS();
116: if (!encNS) {
117: this .add("xenc", MessageConstants.XENC_NS);
118: encNS = true;
119: }
120: }
121:
122: public void addSAMLNS() {
123: if (!samlNS) {
124: this .add("saml", MessageConstants.SAML_v1_0_NS);
125: samlNS = true;
126: }
127: }
128:
129: public void addSCNS() {
130: if (!scNS) {
131: this .add("wsc", MessageConstants.WSSC_NS);
132: scNS = true;
133: }
134: }
135:
136: public void addExc14NS() {
137: if (!exc14NS) {
138: this .add("exc14n",
139: "http://www.w3.org/2001/10/xml-exc-c14n#");
140: exc14NS = true;
141: }
142: }
143:
144: public void add(String prefix, String uri) {
145: list.add(new BindingImpl(prefix, uri));
146: }
147:
148: public Iterator<org.jvnet.staxex.NamespaceContextEx.Binding> iterator() {
149: return list.iterator();
150: }
151:
152: public String getNamespaceURI(String prefix) {
153: for (org.jvnet.staxex.NamespaceContextEx.Binding binding : list) {
154: if (prefix.equals(binding.getPrefix())) {
155: return binding.getNamespaceURI();
156: }
157: }
158: return null;
159: }
160:
161: public String getPrefix(String namespaceURI) {
162: for (org.jvnet.staxex.NamespaceContextEx.Binding binding : list) {
163: if (namespaceURI.equals(binding.getNamespaceURI())) {
164: return binding.getPrefix();
165: }
166: }
167: return null;
168: }
169:
170: public Iterator getPrefixes(final String namespaceURI) {
171: return new Iterator() {
172:
173: int index = 0;
174:
175: public boolean hasNext() {
176: if (index++ < list.size() && move()) {
177: return true;
178: }
179: return false;
180: }
181:
182: public Object next() {
183: return list.get(index).getPrefix();
184: }
185:
186: public void remove() {
187: throw new UnsupportedOperationException();
188: }
189:
190: private boolean move() {
191: boolean found = false;
192: do {
193: if (namespaceURI.equals(list.get(index)
194: .getNamespaceURI())) {
195: found = true;
196: break;
197: } else {
198: index++;
199: }
200: } while (index < list.size());
201: return found;
202: }
203: };
204: }
205:
206: static class BindingImpl implements
207: org.jvnet.staxex.NamespaceContextEx.Binding {
208: private String prefix = "";
209: private String uri = "";
210:
211: public BindingImpl(String prefix, String uri) {
212: this .prefix = prefix;
213: this .uri = uri;
214: }
215:
216: public String getPrefix() {
217: return prefix;
218: }
219:
220: public String getNamespaceURI() {
221: return uri;
222: }
223:
224: }
225:
226: }
|