001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.jaxws.message;
020:
021: import org.apache.axiom.soap.SOAP12Constants;
022:
023: import javax.xml.namespace.QName;
024:
025: /**
026: * Agnostic representation of SOAP 1.1 and SOAP 1.2 fault code values.
027: *
028: * @see XMLFault
029: */
030: public enum XMLFaultCode {
031: // Rendered as qnames with the following local names
032: // (the namespace is the corresponding envelope namespace)
033: SENDER, // SOAP 1.2 Sender SOAP 1.1 Client
034: RECEIVER, // SOAP 1.2 Receiver SOAP 1.1 Server
035: MUSTUNDERSTAND, // SOAP 1.2 MustUnderstand SOAP 1.1 MustUnderstand
036: DATAENCODINGUNKNOWN, // SOAP 1.2 DataEncodingUnknown SOAP 1.1 Server
037: VERSIONMISMATCH; // SOAP 1.2 VersionMismatch SOAP 1.1 VersionMismatch
038:
039: // Utility Methods
040:
041: /**
042: * Return QName for the given protocol
043: *
044: * @param namespace of the envelope for the protocol
045: * @return
046: */
047: public QName toQName(String namespace) {
048: String localPart = null;
049: if (namespace
050: .equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
051: // SOAP 1.2
052: switch (this ) {
053: case SENDER:
054: localPart = "Sender";
055: break;
056: case RECEIVER:
057: localPart = "Receiver";
058: break;
059: case MUSTUNDERSTAND:
060: localPart = "MustUnderstand";
061: break;
062: case DATAENCODINGUNKNOWN:
063: localPart = "DataEncodingUnknown";
064: break;
065: case VERSIONMISMATCH:
066: localPart = "VersionMismatch";
067: break;
068: }
069:
070: } else {
071: // Assume SOAP 1.1
072: switch (this ) {
073: case SENDER:
074: localPart = "Client";
075: break;
076: case RECEIVER:
077: localPart = "Server";
078: break;
079: case MUSTUNDERSTAND:
080: localPart = "MustUnderstand";
081: break;
082: case DATAENCODINGUNKNOWN:
083: localPart = "Server";
084: break;
085: case VERSIONMISMATCH:
086: localPart = "VersionMismatch";
087: break;
088: }
089: }
090: return new QName(namespace, localPart);
091: }
092:
093: /**
094: * get the XMLPart corresponding to this specified QName
095: *
096: * @param qName
097: * @return corresponding XMLPart
098: */
099: public static XMLFaultCode fromQName(QName qName) {
100: if (qName == null) {
101: // Spec indicates that the default is receiver
102: return RECEIVER;
103: }
104: String namespace = qName.getNamespaceURI();
105: String localPart = qName.getLocalPart();
106: XMLFaultCode xmlFaultCode = RECEIVER;
107: // Due to problems in the OM, sometimes that qname is not retrieved correctly.
108: // So use the localName to find the XMLFaultCode
109: if (localPart.equalsIgnoreCase("Sender")) { // SOAP 1.2
110: xmlFaultCode = SENDER;
111: } else if (localPart.equalsIgnoreCase("Receiver")) { // SOAP 1.2
112: xmlFaultCode = RECEIVER;
113: } else if (localPart.equalsIgnoreCase("Client")) { // SOAP 1.1
114: xmlFaultCode = SENDER;
115: } else if (localPart.equalsIgnoreCase("Server")) { // SOAP 1.1
116: xmlFaultCode = RECEIVER;
117: } else if (localPart.equalsIgnoreCase("MustUnderstand")) { // Both
118: xmlFaultCode = MUSTUNDERSTAND;
119: } else if (localPart.equalsIgnoreCase("DataEncodingUnknown")) { // SOAP 1.2
120: xmlFaultCode = DATAENCODINGUNKNOWN;
121: } else if (localPart.equalsIgnoreCase("VersionMismatch")) { // Both
122: xmlFaultCode = VERSIONMISMATCH;
123: }
124: /*
125: * TODO: Due to problems in the OM, sometimes that qname is not retrieved correctly.
126: if (namespace.equals(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
127: // SOAP 1.2
128: if (localPart.equals("Sender")) {
129: xmlFaultCode = SENDER;
130: } else if (localPart.equals("Receiver")) {
131: xmlFaultCode = RECEIVER;
132: } else if (localPart.equals("MustUnderstand")) {
133: xmlFaultCode = MUSTUNDERSTAND;
134: } else if (localPart.equals("DataEncodingUnknown")) {
135: xmlFaultCode = DATAENCODINGUNKNOWN;
136: } else if (localPart.equals("VersionMismatch")) {
137: xmlFaultCode = VERSIONMISMATCH;
138: }
139: } else {
140: // SOAP 1.1
141: if (localPart.equals("Client")) {
142: xmlFaultCode = SENDER;
143: } else if (localPart.equals("Server")) {
144: xmlFaultCode = RECEIVER;
145: } else if (localPart.equals("MustUnderstand")) {
146: xmlFaultCode = MUSTUNDERSTAND;
147: } else if (localPart.equals("VersionMismatch")) {
148: xmlFaultCode = VERSIONMISMATCH;
149: }
150: }
151: */
152: return xmlFaultCode;
153: }
154: }
|