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.addressing.wsdl;
020:
021: import org.apache.axis2.addressing.AddressingConstants;
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024:
025: import javax.wsdl.Definition;
026: import javax.wsdl.Fault;
027: import javax.wsdl.Input;
028: import javax.wsdl.Operation;
029: import javax.wsdl.Output;
030: import javax.wsdl.PortType;
031: import javax.wsdl.extensions.AttributeExtensible;
032: import javax.xml.namespace.QName;
033: import java.util.List;
034:
035: /**
036: * The WSDL11ActionHelper provides 3 static methods to determine the correct wsa:Action value from
037: * a wsdl4j Input/Output/Fault object. It first attempts to access the wsaw:Action attribute and if
038: * that is not found uses the WSDL11DefaultActionPatternHelper to generate and Action based on the
039: * Default Action Pattern for WSDL1.1 at http://www.w3.org/TR/2006/WD-ws-addr-wsdl-20060216/#defactionwsdl11
040: */
041: public class WSDL11ActionHelper {
042:
043: private static final Log log = LogFactory
044: .getLog(WSDL11ActionHelper.class);
045: private static final QName submissionWSAWNS = new QName(
046: AddressingConstants.Submission.WSA_NAMESPACE,
047: AddressingConstants.WSA_ACTION);
048: private static final QName finalWSANS = new QName(
049: AddressingConstants.Final.WSA_NAMESPACE,
050: AddressingConstants.WSA_ACTION);
051: private static final QName finalWSAWNS = new QName(
052: AddressingConstants.Final.WSAW_NAMESPACE,
053: AddressingConstants.WSA_ACTION);
054:
055: /**
056: * getActionFromInputElement
057: *
058: * @param def the wsdl:definitions which contains the wsdl:portType
059: * @param wsdl4jPortType the wsdl:portType which contains the wsdl:operation
060: * @param op the wsdl:operation which contains the input element
061: * @param input the input element to be examined to generate the wsa:Action
062: * @return either the wsaw:Action from the input element or an action generated using the DefaultActionPattern
063: */
064: public static String getActionFromInputElement(Definition def,
065: PortType wsdl4jPortType, Operation op, Input input) {
066: String result = getWSAWActionExtensionAttribute(input);
067: if (result == null) {
068: result = WSDL11DefaultActionPatternHelper
069: .generateActionFromInputElement(def,
070: wsdl4jPortType, op, input);
071: }
072: log.trace(result);
073: return result;
074: }
075:
076: /**
077: * getActionFromOutputElement
078: *
079: * @param def the wsdl:definitions which contains the wsdl:portType
080: * @param wsdl4jPortType the wsdl:portType which contains the wsdl:operation
081: * @param op the wsdl:operation which contains the output element
082: * @param output the input element to be examined to generate the wsa:Action
083: * @return either the wsaw:Action from the output element or an action generated using the DefaultActionPattern
084: */
085: public static String getActionFromOutputElement(Definition def,
086: PortType wsdl4jPortType, Operation op, Output output) {
087: String result = getWSAWActionExtensionAttribute(output);
088: if (result == null) {
089: result = WSDL11DefaultActionPatternHelper
090: .generateActionFromOutputElement(def,
091: wsdl4jPortType, op, output);
092: }
093: log.trace(result);
094: return result;
095: }
096:
097: /**
098: * getActionFromFaultElement
099: *
100: * @param def the wsdl:definitions which contains the wsdl:portType
101: * @param wsdl4jPortType the wsdl:portType which contains the wsdl:operation
102: * @param op the wsdl:operation which contains the fault element
103: * @param fault the fault element to be examined to generate the wsa:Action
104: * @return either the wsaw:Action from the fault element or an action generated using the DefaultActionPattern
105: */
106: public static String getActionFromFaultElement(Definition def,
107: PortType wsdl4jPortType, Operation op, Fault fault) {
108: String result = getWSAWActionExtensionAttribute(fault);
109: if (result == null) {
110: result = WSDL11DefaultActionPatternHelper
111: .generateActionFromFaultElement(def,
112: wsdl4jPortType, op, fault);
113: }
114: log.trace(result);
115: return result;
116: }
117:
118: private static String getWSAWActionExtensionAttribute(
119: AttributeExtensible ae) {
120: // Search first for a wsaw:Action using the submission namespace
121: Object attribute = ae.getExtensionAttribute(submissionWSAWNS);
122: // Then if that did not exist one using the w3c namespace
123: if (attribute == null) {
124: attribute = ae.getExtensionAttribute(finalWSAWNS);
125: }
126: // Then finally if that did not exist, try the 2005/08 NS
127: // (Included here because it's needed for Apache Muse)
128: if (attribute == null) {
129: attribute = ae.getExtensionAttribute(finalWSANS);
130: }
131:
132: // wsdl4j may return a String, QName or a List of either
133: // If it is a list, extract the first element
134: if (attribute instanceof List) {
135: List l = (List) attribute;
136: if (l.size() > 0) {
137: attribute = l.get(0);
138: } else {
139: attribute = null;
140: }
141: }
142:
143: // attribute must now be a QName or String or null
144: // If it is a QName, take the LocalPart as a String
145: if (attribute instanceof QName) {
146: QName qn = (QName) attribute;
147: attribute = qn.getLocalPart();
148: }
149:
150: if ((attribute instanceof String)) {
151: String result = (String) attribute;
152: log.trace(result);
153: return result;
154: } else {
155: if (log.isTraceEnabled()) {
156: log.trace("No wsaw:Action attribute found");
157: }
158: return null;
159: }
160: }
161:
162: public static String getInputActionFromStringInformation(
163: String messageExchangePattern, String targetNamespace,
164: String portTypeName, String operationName, String inputName) {
165: return WSDL11DefaultActionPatternHelper
166: .getInputActionFromStringInformation(
167: messageExchangePattern, targetNamespace,
168: portTypeName, operationName, inputName);
169: }
170:
171: public static String getOutputActionFromStringInformation(
172: String messageExchangePattern, String targetNamespace,
173: String portTypeName, String operationName, String outputName) {
174: return WSDL11DefaultActionPatternHelper
175: .getOutputActionFromStringInformation(
176: messageExchangePattern, targetNamespace,
177: portTypeName, operationName, outputName);
178: }
179:
180: public static String getFaultActionFromStringInformation(
181: String targetNamespace, String portTypeName,
182: String operationName, String faultName) {
183: return WSDL11DefaultActionPatternHelper
184: .getFaultActionFromStringInformation(targetNamespace,
185: portTypeName, operationName, faultName);
186: }
187:
188: }
|