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.wss.impl.dsig;
024:
025: import com.sun.xml.wss.impl.MessageConstants;
026: import java.util.ArrayList;
027: import java.util.HashMap;
028: import java.util.Iterator;
029: import java.util.Map;
030: import javax.xml.namespace.NamespaceContext;
031:
032: /**
033: * Implements NamespaceContext .
034: *
035: * TODO : Performance Improvements.
036: */
037: public class NamespaceContextImpl implements NamespaceContext {
038:
039: HashMap namespaceMap = null;
040:
041: public NamespaceContextImpl() {
042: namespaceMap = new HashMap(10);
043: this .add("SOAP-ENV",
044: "http://schemas.xmlsoap.org/soap/envelope/");
045: this .add("env", "http://schemas.xmlsoap.org/soap/envelope/");
046: this .add("ds", MessageConstants.DSIG_NS);
047: this .add("xenc", MessageConstants.XENC_NS);
048: this .add("wsse", MessageConstants.WSSE_NS);
049: this .add("wsu", MessageConstants.WSU_NS);
050: this .add("saml", MessageConstants.SAML_v1_0_NS);
051: this .add("S11", "http://schemas.xmlsoap.org/soap/envelope/");
052: this .add("S12", "http://www.w3.org/2003/05/soap-envelope");
053: }
054:
055: /**
056: * Add prefix and namespaceuri to be associated with the prefix.
057: * @param prefix Namespace Prefix
058: * @param uri NamespaceURI
059: */
060: public void add(String prefix, String uri) {
061: namespaceMap.put(prefix, uri);
062:
063: }
064:
065: /**
066: *
067: * @param prefix
068: * @return
069: */
070: public String getNamespaceURI(String prefix) {
071: return (String) namespaceMap.get(prefix);
072: }
073:
074: /**
075: *
076: * @param namespaceURI
077: * @return NamespaceURI associated with the prefix
078: */
079: public String getPrefix(String namespaceURI) {
080: Iterator iterator = namespaceMap.keySet().iterator();
081: while (iterator.hasNext()) {
082: String prefix = (String) iterator.next();
083: String uri = (String) namespaceMap.get(prefix);
084: if (namespaceURI.equals(uri))
085: return prefix;
086:
087: }
088: return null;
089: }
090:
091: /**
092: *
093: * @param namespaceURI
094: * @return Iterator to list of prefixes associated with the namespaceURI
095: */
096: public Iterator getPrefixes(String namespaceURI) {
097:
098: ArrayList prefixList = new ArrayList();
099: Iterator iterator = namespaceMap.keySet().iterator();
100: while (iterator.hasNext()) {
101: String prefix = (String) iterator.next();
102:
103: String uri = (String) namespaceMap.get(prefix);
104:
105: if (namespaceURI.equals(uri)) {
106: prefixList.add(prefix);
107: }
108: }
109: return prefixList.iterator();
110: }
111:
112: public Map getMap() {
113: return namespaceMap;
114: }
115: }
|