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 com.sun.xml.bind.marshaller.NamespacePrefixMapper;
026: import com.sun.xml.wss.impl.MessageConstants;
027:
028: /**
029: *
030: * @author K.Venugopal@sun.com
031: */
032: public class WSSNamespacePrefixMapper extends NamespacePrefixMapper {
033:
034: private boolean soap12 = false;
035:
036: /** Creates a new instance of NamespacePrefixMapper */
037: public WSSNamespacePrefixMapper() {
038: }
039:
040: /** Creates a new instance of NamespacePrefixMapper */
041: public WSSNamespacePrefixMapper(boolean soap12) {
042: this .soap12 = soap12;
043: }
044:
045: public String getPreferredPrefix(String namespaceUri,
046: String suggestion, boolean requirePrefix) {
047: if (MessageConstants.WSSE_NS.equals(namespaceUri)) {
048: return MessageConstants.WSSE_PREFIX;
049: }
050:
051: if (MessageConstants.WSSE11_NS.equals(namespaceUri)) {
052: return MessageConstants.WSSE11_PREFIX;
053: }
054: if (MessageConstants.XENC_NS.equals(namespaceUri)) {
055: return MessageConstants.XENC_PREFIX;
056: }
057: if (MessageConstants.DSIG_NS.equals(namespaceUri)) {
058: return MessageConstants.DSIG_PREFIX;
059: }
060: if (MessageConstants.WSU_NS.equals(namespaceUri)) {
061: return MessageConstants.WSU_PREFIX;
062: }
063: if (MessageConstants.WSSC_NS.equals(namespaceUri)) {
064: return MessageConstants.WSSC_PREFIX;
065: }
066: if ("http://www.w3.org/2001/10/xml-exc-c14n#"
067: .equals(namespaceUri)) {
068: return "exc14n";
069: }
070: if (MessageConstants.SOAP_1_1_NS.equals(namespaceUri)) {
071: return "S";
072: }
073:
074: if (MessageConstants.SOAP_1_2_NS.equals(namespaceUri)) {
075: return "S";
076: }
077: if ("http://www.w3.org/2001/XMLSchema-instance"
078: .equals(namespaceUri)) {
079: return "xsi";
080: }
081: return null;
082: }
083:
084: public String[] getPreDeclaredNamespaceUris() {
085: return new String[] {};
086: }
087:
088: public String[] getContextualNamespaceDecls() {
089: if (!soap12) {
090: return new String[] { MessageConstants.WSSE_PREFIX,
091: MessageConstants.WSSE_NS,
092: MessageConstants.WSSE11_PREFIX,
093: MessageConstants.WSSE11_NS,
094: MessageConstants.XENC_PREFIX,
095: MessageConstants.XENC_NS,
096: MessageConstants.DSIG_PREFIX,
097: MessageConstants.DSIG_NS,
098: MessageConstants.WSU_PREFIX,
099: MessageConstants.WSU_NS,
100: MessageConstants.WSSC_PREFIX,
101: MessageConstants.WSSC_NS, "exc14n",
102: "http://www.w3.org/2001/10/xml-exc-c14n#", "S",
103: MessageConstants.SOAP_1_1_NS };
104: } else {
105: return new String[] { MessageConstants.WSSE_PREFIX,
106: MessageConstants.WSSE_NS,
107: MessageConstants.WSSE11_PREFIX,
108: MessageConstants.WSSE11_NS,
109: MessageConstants.XENC_PREFIX,
110: MessageConstants.XENC_NS,
111: MessageConstants.DSIG_PREFIX,
112: MessageConstants.DSIG_NS,
113: MessageConstants.WSU_PREFIX,
114: MessageConstants.WSU_NS,
115: MessageConstants.WSSC_PREFIX,
116: MessageConstants.WSSC_NS, "exc14n",
117: "http://www.w3.org/2001/10/xml-exc-c14n#", "S",
118: MessageConstants.SOAP_1_2_NS };
119: }
120: }
121:
122: }
|