001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.api;
038:
039: import com.sun.xml.bind.util.Which;
040: import com.sun.xml.ws.encoding.soap.SOAP12Constants;
041:
042: import javax.xml.namespace.QName;
043: import javax.xml.soap.MessageFactory;
044: import javax.xml.soap.SOAPConstants;
045: import javax.xml.soap.SOAPException;
046: import javax.xml.soap.SOAPFactory;
047: import javax.xml.ws.soap.SOAPBinding;
048: import java.util.Arrays;
049: import java.util.Collections;
050: import java.util.HashSet;
051: import java.util.Set;
052:
053: /**
054: * Version of SOAP (1.1 and 1.2).
055: *
056: * <p>
057: * This class defines various constants for SOAP 1.1 and SOAP 1.2,
058: * and also defines convenience methods to simplify the processing
059: * of multiple SOAP versions.
060: *
061: * <p>
062: * This constant alows you to do:
063: *
064: * <pre>
065: * SOAPVersion version = ...;
066: * version.someOp(...);
067: * </pre>
068: *
069: * As opposed to:
070: *
071: * <pre>
072: * if(binding is SOAP11) {
073: * doSomeOp11(...);
074: * } else {
075: * doSomeOp12(...);
076: * }
077: * </pre>
078: *
079: * @author Kohsuke Kawaguchi
080: */
081: public enum SOAPVersion {
082: SOAP_11(
083: SOAPBinding.SOAP11HTTP_BINDING,
084: com.sun.xml.ws.encoding.soap.SOAPConstants.URI_ENVELOPE,
085: "text/xml",
086: SOAPConstants.URI_SOAP_ACTOR_NEXT,
087: "actor",
088: javax.xml.soap.SOAPConstants.SOAP_1_1_PROTOCOL,
089: new QName(
090: com.sun.xml.ws.encoding.soap.SOAPConstants.URI_ENVELOPE,
091: "MustUnderstand"), "Client", "Server", Collections
092: .singleton(SOAPConstants.URI_SOAP_ACTOR_NEXT)),
093:
094: SOAP_12(
095: SOAPBinding.SOAP12HTTP_BINDING,
096: SOAP12Constants.URI_ENVELOPE,
097: "application/soap+xml",
098: SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER,
099: "role",
100: javax.xml.soap.SOAPConstants.SOAP_1_2_PROTOCOL,
101: new QName(
102: com.sun.xml.ws.encoding.soap.SOAP12Constants.URI_ENVELOPE,
103: "MustUnderstand"), "Sender", "Receiver",
104: new HashSet<String>(Arrays.asList(
105: SOAPConstants.URI_SOAP_1_2_ROLE_NEXT,
106: SOAPConstants.URI_SOAP_1_2_ROLE_ULTIMATE_RECEIVER)));
107:
108: /**
109: * Binding ID for SOAP/HTTP binding of this SOAP version.
110: *
111: * <p>
112: * Either {@link SOAPBinding#SOAP11HTTP_BINDING} or
113: * {@link SOAPBinding#SOAP12HTTP_BINDING}
114: */
115: public final String httpBindingId;
116:
117: /**
118: * SOAP envelope namespace URI.
119: */
120: public final String nsUri;
121:
122: /**
123: * Content-type. Either "text/xml" or "application/soap+xml".
124: */
125: public final String contentType;
126:
127: /**
128: * SOAP MustUnderstand FaultCode for this SOAP version
129: */
130: public final QName faultCodeMustUnderstand;
131:
132: /**
133: * SAAJ {@link MessageFactory} for this SOAP version.
134: */
135: public final MessageFactory saajMessageFactory;
136:
137: /**
138: * SAAJ {@link SOAPFactory} for this SOAP version.
139: */
140: public final SOAPFactory saajSoapFactory;
141:
142: /**
143: * If the actor/role attribute is absent, this SOAP version assumes this value.
144: */
145: public final String implicitRole;
146:
147: /**
148: * Singleton set that contains {@link #implicitRole}.
149: */
150: public final Set<String> implicitRoleSet;
151:
152: /**
153: * This represents the roles required to be assumed by SOAP binding implementation.
154: */
155: public final Set<String> requiredRoles;
156:
157: /**
158: * "role" (SOAP 1.2) or "actor" (SOAP 1.1)
159: */
160: public final String roleAttributeName;
161:
162: /**
163: * "{nsUri}Client" or "{nsUri}Sender"
164: */
165: public final QName faultCodeClient;
166:
167: /**
168: * "{nsUri}Server" or "{nsUri}Receiver"
169: */
170: public final QName faultCodeServer;
171:
172: private SOAPVersion(String httpBindingId, String nsUri,
173: String contentType, String implicitRole,
174: String roleAttributeName, String saajFactoryString,
175: QName faultCodeMustUnderstand,
176: String faultCodeClientLocalName,
177: String faultCodeServerLocalName, Set<String> requiredRoles) {
178: this .httpBindingId = httpBindingId;
179: this .nsUri = nsUri;
180: this .contentType = contentType;
181: this .implicitRole = implicitRole;
182: this .implicitRoleSet = Collections.singleton(implicitRole);
183: this .roleAttributeName = roleAttributeName;
184: try {
185: saajMessageFactory = MessageFactory
186: .newInstance(saajFactoryString);
187: saajSoapFactory = SOAPFactory
188: .newInstance(saajFactoryString);
189: } catch (SOAPException e) {
190: throw new Error(e);
191: } catch (NoSuchMethodError e) {
192: // SAAJ 1.3 is not in the classpath
193: LinkageError x = new LinkageError(
194: "You are loading old SAAJ from "
195: + Which.which(MessageFactory.class));
196: x.initCause(e);
197: throw x;
198: }
199: this .faultCodeMustUnderstand = faultCodeMustUnderstand;
200: this .requiredRoles = requiredRoles;
201: this .faultCodeClient = new QName(nsUri,
202: faultCodeClientLocalName);
203: this .faultCodeServer = new QName(nsUri,
204: faultCodeServerLocalName);
205: }
206:
207: public String toString() {
208: return httpBindingId;
209: }
210:
211: /**
212: * Returns {@link SOAPVersion} whose {@link #httpBindingId} equals to
213: * the given string.
214: *
215: * This method does not perform input string validation.
216: *
217: * @param binding
218: * for historical reason, we treat null as {@link #SOAP_11},
219: * but you really shouldn't be passing null.
220: * @return always non-null.
221: */
222: public static SOAPVersion fromHttpBinding(String binding) {
223: if (binding == null)
224: return SOAP_11;
225:
226: if (binding.equals(SOAP_12.httpBindingId))
227: return SOAP_12;
228: else
229: return SOAP_11;
230: }
231:
232: /**
233: * Returns {@link SOAPVersion} whose {@link #nsUri} equals to
234: * the given string.
235: *
236: * This method does not perform input string validation.
237: *
238: * @param nsUri
239: * must not be null.
240: * @return always non-null.
241: */
242: public static SOAPVersion fromNsUri(String nsUri) {
243: if (nsUri.equals(SOAP_12.nsUri))
244: return SOAP_12;
245: else
246: return SOAP_11;
247: }
248: }
|