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.description;
020:
021: import org.apache.axis2.AxisFault;
022: import org.apache.axis2.Constants;
023: import org.apache.axis2.util.PolicyUtil;
024: import org.apache.axis2.util.WSDLSerializationUtil;
025: import org.apache.axis2.wsdl.WSDLConstants;
026: import org.apache.axiom.om.OMElement;
027: import org.apache.axiom.om.OMAbstractFactory;
028: import org.apache.axiom.om.OMFactory;
029: import org.apache.axiom.om.OMNamespace;
030: import org.apache.neethi.Policy;
031:
032: import javax.xml.namespace.QName;
033: import java.util.HashMap;
034: import java.util.Map;
035: import java.util.ArrayList;
036: import java.util.Collection;
037: import java.util.Iterator;
038:
039: /**
040: * An AxisBindingOperation represents a WSDL <bindingOperation>
041: */
042: public class AxisBindingOperation extends AxisDescription {
043:
044: private AxisOperation axisOperation;
045:
046: private QName name;
047:
048: private Map faults;
049:
050: private Map options;
051:
052: public AxisBindingOperation() {
053: options = new HashMap();
054: faults = new HashMap();
055: }
056:
057: public AxisBindingMessage getFault(String name) {
058: return (AxisBindingMessage) faults.get(name);
059: }
060:
061: public void addFault(AxisBindingMessage fault) {
062: this .faults.put(fault.getName(), fault);
063: }
064:
065: public QName getName() {
066: return name;
067: }
068:
069: public void setName(QName name) {
070: this .name = name;
071: }
072:
073: public AxisOperation getAxisOperation() {
074: return axisOperation;
075: }
076:
077: public void setAxisOperation(AxisOperation axisOperation) {
078: this .axisOperation = axisOperation;
079: }
080:
081: public void setProperty(String name, Object value) {
082: options.put(name, value);
083: }
084:
085: public Object getProperty(String name) {
086: Object property = this .options.get(name);
087:
088: AxisBinding parent;
089: if (property == null && (parent = getAxisBinding()) != null) {
090: property = parent.getProperty(name);
091: }
092:
093: if (property == null) {
094: property = WSDL20DefaultValueHolder.getDefaultValue(name);
095: }
096:
097: return property;
098: }
099:
100: public Object getKey() {
101: return null;
102: }
103:
104: public void engageModule(AxisModule axisModule) throws AxisFault {
105: throw new UnsupportedOperationException(
106: "Sorry we do not support this");
107: }
108:
109: public boolean isEngaged(String moduleName) {
110: throw new UnsupportedOperationException(
111: "axisMessage.isEngaged() is not supported");
112:
113: }
114:
115: /**
116: * Generates the bindingOperation element
117: * @param wsdl The WSDL namespace
118: * @param tns The targetnamespace
119: * @param wsoap The SOAP namespace (WSDL 2.0)
120: * @param whttp The HTTP namespace (WSDL 2.0)
121: * @param type Indicates whether the binding is SOAP or HTTP
122: * @param namespaceMap the service's namespace map (prefix -> namespace)
123: * @param serviceName the name of the service
124: * @return The generated binding element
125: */
126: public OMElement toWSDL20(OMNamespace wsdl, OMNamespace tns,
127: OMNamespace wsoap, OMNamespace whttp, String type,
128: Map namespaceMap, String serviceName) {
129: String property;
130: OMFactory omFactory = OMAbstractFactory.getOMFactory();
131: OMElement bindingOpElement = omFactory.createOMElement(
132: WSDL2Constants.OPERATION_LOCAL_NAME, wsdl);
133: bindingOpElement.addAttribute(omFactory.createOMAttribute(
134: WSDL2Constants.ATTRIBUTE_REF, null, tns.getPrefix()
135: + ":" + this .name.getLocalPart()));
136:
137: if (WSDL2Constants.URI_WSDL2_SOAP.equals(type)
138: || Constants.URI_SOAP11_HTTP.equals(type)
139: || Constants.URI_SOAP12_HTTP.equals(type)) {
140: // SOAP Binding specific properties
141: property = (String) this .options
142: .get(WSDL2Constants.ATTR_WSOAP_ACTION);
143: if (property != null) {
144: bindingOpElement.addAttribute(omFactory
145: .createOMAttribute(
146: WSDL2Constants.ATTRIBUTE_ACTION, wsoap,
147: property));
148: }
149: ArrayList soapModules = (ArrayList) this .options
150: .get(WSDL2Constants.ATTR_WSOAP_MODULE);
151: if (soapModules != null && soapModules.size() > 0) {
152: WSDLSerializationUtil.addSOAPModuleElements(omFactory,
153: soapModules, wsoap, bindingOpElement);
154: }
155: property = (String) this .options
156: .get(WSDL2Constants.ATTR_WSOAP_MEP);
157: if (property != null) {
158: bindingOpElement.addAttribute(omFactory
159: .createOMAttribute(
160: WSDL2Constants.ATTRIBUTE_MEP, wsoap,
161: property));
162: }
163: } else if (WSDL2Constants.URI_WSDL2_HTTP.equals(type)) {
164:
165: // HTTP Binding specific properties
166: property = (String) this .options
167: .get(WSDL2Constants.ATTR_WHTTP_INPUT_SERIALIZATION);
168: if (property != null) {
169: bindingOpElement
170: .addAttribute(omFactory
171: .createOMAttribute(
172: WSDL2Constants.ATTRIBUTE_INPUT_SERIALIZATION,
173: whttp, property));
174: }
175: property = (String) this .options
176: .get(WSDL2Constants.ATTR_WHTTP_OUTPUT_SERIALIZATION);
177: if (property != null) {
178: bindingOpElement
179: .addAttribute(omFactory
180: .createOMAttribute(
181: WSDL2Constants.ATTRIBUTE_OUTPUT_SERIALIZATION,
182: whttp, property));
183: }
184: property = (String) this .options
185: .get(WSDL2Constants.ATTR_WHTTP_FAULT_SERIALIZATION);
186: if (property != null) {
187: bindingOpElement
188: .addAttribute(omFactory
189: .createOMAttribute(
190: WSDL2Constants.ATTRIBUTE_FAULT_SERIALIZATION,
191: whttp, property));
192: }
193: Boolean ignoreUncited = (Boolean) this .options
194: .get(WSDL2Constants.ATTR_WHTTP_IGNORE_UNCITED);
195: if (ignoreUncited != null) {
196: bindingOpElement
197: .addAttribute(omFactory
198: .createOMAttribute(
199: WSDL2Constants.ATTRIBUTE_IGNORE_UNCITED,
200: whttp, ignoreUncited.toString()));
201: }
202: property = (String) this .options
203: .get(WSDL2Constants.ATTR_WHTTP_METHOD);
204: if (property != null) {
205: bindingOpElement.addAttribute(omFactory
206: .createOMAttribute(
207: WSDL2Constants.ATTRIBUTE_METHOD, whttp,
208: property));
209: }
210: }
211:
212: // Common properties
213: property = (String) this .options
214: .get(WSDL2Constants.ATTR_WHTTP_LOCATION);
215: if (property != null) {
216: bindingOpElement.addAttribute(omFactory.createOMAttribute(
217: WSDL2Constants.ATTRIBUTE_LOCATION, whttp,
218: serviceName + "/" + property));
219: }
220: property = (String) this .options
221: .get(WSDL2Constants.ATTR_WHTTP_CONTENT_ENCODING);
222: if (property != null) {
223: bindingOpElement.addAttribute(omFactory.createOMAttribute(
224: WSDL2Constants.ATTRIBUTE_CONTENT_ENCODING, whttp,
225: property));
226: }
227: property = (String) this .options
228: .get(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
229: if (property != null) {
230: bindingOpElement.addAttribute(omFactory.createOMAttribute(
231: WSDL2Constants.ATTRIBUTE_QUERY_PARAMETER_SEPERATOR,
232: whttp, property));
233: }
234:
235: // Add the input element
236: AxisBindingMessage inMessage = (AxisBindingMessage) this
237: .getChild(WSDLConstants.WSDL_MESSAGE_DIRECTION_IN);
238: if (inMessage != null) {
239: bindingOpElement.addChild(inMessage.toWSDL20(wsdl, tns,
240: wsoap, whttp, namespaceMap));
241: }
242:
243: // Add the output element
244: AxisBindingMessage outMessage = (AxisBindingMessage) this
245: .getChild(WSDLConstants.WSDL_MESSAGE_DIRECTION_OUT);
246: if (outMessage != null) {
247: bindingOpElement.addChild(outMessage.toWSDL20(wsdl, tns,
248: wsoap, whttp, namespaceMap));
249: }
250:
251: // Add any fault elements
252: if (faults != null && faults.size() > 0) {
253: Collection faultValues = faults.values();
254: Iterator iterator = faultValues.iterator();
255: while (iterator.hasNext()) {
256: AxisBindingMessage faultMessage = (AxisBindingMessage) iterator
257: .next();
258: bindingOpElement.addChild(faultMessage.toWSDL20(wsdl,
259: tns, wsoap, whttp, namespaceMap));
260: }
261: }
262: WSDLSerializationUtil.addWSDLDocumentationElement(this ,
263: bindingOpElement, omFactory, wsdl);
264: return bindingOpElement;
265: }
266:
267: public Policy getEffectivePolicy() {
268: ArrayList policyList = new ArrayList();
269:
270: PolicyInclude policyInclude;
271:
272: // AxisBindingOperation policies
273: policyInclude = getPolicyInclude();
274: policyList.addAll(policyInclude.getAttachedPolicies());
275:
276: // AxisBinding
277: AxisBinding axisBinding = getAxisBinding();
278: if (axisBinding != null) {
279: policyList.addAll(axisBinding.getPolicyInclude()
280: .getAttachedPolicies());
281: }
282:
283: // AxisEndpoint
284: AxisEndpoint axisEndpoint = null;
285: if (axisBinding != null) {
286: axisEndpoint = axisBinding.getAxisEndpoint();
287: }
288:
289: if (axisEndpoint != null) {
290: policyList.addAll(axisEndpoint.getPolicyInclude()
291: .getAttachedPolicies());
292: }
293:
294: // AxisOperation
295: Policy axisOperationPolicy = axisOperation.getPolicyInclude()
296: .getEffectivePolicy();
297:
298: if (axisOperationPolicy != null) {
299: policyList.add(axisOperationPolicy);
300: }
301:
302: return PolicyUtil.getMergedPolicy(policyList, this );
303: }
304:
305: public AxisBinding getAxisBinding() {
306: return (AxisBinding) parent;
307: }
308: }
|