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.axiom.om.OMElement;
026: import org.apache.axiom.om.OMNamespace;
027: import org.apache.axiom.om.OMFactory;
028: import org.apache.axiom.om.OMAbstractFactory;
029: import org.apache.axiom.soap.SOAP11Constants;
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.Iterator;
037:
038: /**
039: * An AxisBinding represents a WSDL binding, and contains AxisBindingOperations.
040: */
041: public class AxisBinding extends AxisDescription {
042:
043: private QName name;
044:
045: private String type;
046:
047: private Map options;
048:
049: private Map faults;
050:
051: public AxisBindingMessage getFault(String name) {
052: return (AxisBindingMessage) faults.get(name);
053: }
054:
055: public void addFault(AxisBindingMessage fault) {
056: this .faults.put(fault.getName(), fault);
057: }
058:
059: public AxisBinding() {
060: options = new HashMap();
061: faults = new HashMap();
062: }
063:
064: public void setProperty(String name, Object value) {
065: options.put(name, value);
066: }
067:
068: /**
069: * @param name name of the property to search for
070: * @return the value of the property, or null if the property is not found
071: */
072: public Object getProperty(String name) {
073: Object obj = options.get(name);
074: if (obj != null) {
075: return obj;
076: }
077:
078: obj = WSDL20DefaultValueHolder.getDefaultValue(name);
079:
080: return obj;
081: }
082:
083: public QName getName() {
084: return name;
085: }
086:
087: public void setName(QName name) {
088: this .name = name;
089: }
090:
091: public String getType() {
092: return type;
093: }
094:
095: public void setType(String type) {
096: this .type = type;
097: }
098:
099: public Object getKey() {
100: return null;
101: }
102:
103: public void engageModule(AxisModule axisModule) throws AxisFault {
104: throw new UnsupportedOperationException(
105: "Sorry we do not support this");
106: }
107:
108: public boolean isEngaged(String moduleName) {
109: throw new UnsupportedOperationException(
110: "axisMessage.isEngaged() is not supported");
111:
112: }
113:
114: /**
115: * Generate the <binding> element
116: *
117: * @param wsdl the WSDL namespace
118: * @param tns the target namespace
119: * @param wsoap the SOAP namespace
120: * @param whttp the HTTP namespace
121: * @param interfaceName the name of the interface
122: * @param nameSpaceMap the namespaceMap (prefix -> namespaceURI) of the service
123: * @param addressingFlag addressing usage flag (see AddressingConstants)
124: * @param serviceName the name of the service
125: * @return the generated binding element
126: */
127: public OMElement toWSDL20(OMNamespace wsdl, OMNamespace tns,
128: OMNamespace wsoap, OMNamespace whttp, String interfaceName,
129: Map nameSpaceMap, String addressingFlag,
130: String serviceName, OMNamespace wsaw) {
131: String property;
132: OMFactory omFactory = OMAbstractFactory.getOMFactory();
133: OMElement bindingElement;
134: bindingElement = omFactory.createOMElement(
135: WSDL2Constants.BINDING_LOCAL_NAME, wsdl);
136: bindingElement.addAttribute(omFactory.createOMAttribute(
137: WSDL2Constants.ATTRIBUTE_NAME, null, this .name
138: .getLocalPart()));
139: bindingElement.addAttribute(omFactory.createOMAttribute(
140: WSDL2Constants.INTERFACE_LOCAL_NAME, null, tns
141: .getPrefix()
142: + ":" + interfaceName));
143:
144: if (WSDL2Constants.URI_WSDL2_SOAP.equals(type)
145: || Constants.URI_SOAP11_HTTP.equals(type)
146: || Constants.URI_SOAP12_HTTP.equals(type)) {
147: // SOAP Binding specific properties
148: bindingElement.addAttribute(omFactory.createOMAttribute(
149: WSDL2Constants.ATTRIBUTE_TYPE, null,
150: WSDL2Constants.URI_WSDL2_SOAP));
151: property = (String) options
152: .get(WSDL2Constants.ATTR_WSOAP_VERSION);
153: if (property != null) {
154: if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
155: .equals(property)) {
156: bindingElement.addAttribute(omFactory
157: .createOMAttribute(
158: WSDL2Constants.ATTRIBUTE_VERSION,
159: wsoap,
160: WSDL2Constants.SOAP_VERSION_1_1));
161: } else {
162: bindingElement.addAttribute(omFactory
163: .createOMAttribute(
164: WSDL2Constants.ATTRIBUTE_VERSION,
165: wsoap,
166: WSDL2Constants.SOAP_VERSION_1_2));
167: }
168: }
169: property = (String) options
170: .get(WSDL2Constants.ATTR_WSOAP_PROTOCOL);
171: if (property != null) {
172: bindingElement.addAttribute(omFactory
173: .createOMAttribute(
174: WSDL2Constants.ATTRIBUTE_PROTOCOL,
175: wsoap, property));
176: }
177: property = (String) options
178: .get(WSDL2Constants.ATTR_WSOAP_MEP);
179: if (property != null) {
180: bindingElement.addAttribute(omFactory
181: .createOMAttribute(
182: WSDL2Constants.ATTRIBUTE_MEP_DEFAULT,
183: wsoap, property));
184: }
185: ArrayList soapModules = (ArrayList) options
186: .get(WSDL2Constants.ATTR_WSOAP_MODULE);
187: if (soapModules != null && soapModules.size() > 0) {
188: WSDLSerializationUtil.addSOAPModuleElements(omFactory,
189: soapModules, wsoap, bindingElement);
190: }
191:
192: WSDLSerializationUtil.addWSAddressingToBinding(
193: addressingFlag, omFactory, bindingElement, wsaw);
194:
195: } else if (WSDL2Constants.URI_WSDL2_HTTP.equals(type)) {
196: // HTTP Binding specific properties
197: property = (String) options
198: .get(WSDL2Constants.ATTR_WHTTP_METHOD);
199: if (property != null) {
200: bindingElement
201: .addAttribute(omFactory
202: .createOMAttribute(
203: WSDL2Constants.ATTRIBUTE_METHOD_DEFAULT,
204: whttp, property));
205: }
206: bindingElement.addAttribute(omFactory.createOMAttribute(
207: WSDL2Constants.ATTRIBUTE_TYPE, null,
208: WSDL2Constants.URI_WSDL2_HTTP));
209: }
210:
211: // Common Properties
212: property = (String) options
213: .get(WSDL2Constants.ATTR_WHTTP_CONTENT_ENCODING);
214: if (property != null) {
215: bindingElement.addAttribute(omFactory.createOMAttribute(
216: WSDL2Constants.ATTRIBUTE_CONTENT_ENCODING_DEFAULT,
217: whttp, property));
218: }
219: property = (String) options
220: .get(WSDL2Constants.ATTR_WHTTP_QUERY_PARAMETER_SEPARATOR);
221: if (property != null) {
222: bindingElement
223: .addAttribute(omFactory
224: .createOMAttribute(
225: WSDL2Constants.ATTRIBUTE_QUERY_PARAMETER_SEPERATOR_DEFAULT,
226: whttp, property));
227: }
228:
229: // Populate Binding faults
230: if (faults != null) {
231: Iterator iterator = faults.values().iterator();
232: while (iterator.hasNext()) {
233: AxisBindingMessage axisBindingFault = (AxisBindingMessage) iterator
234: .next();
235: bindingElement.addChild(axisBindingFault.toWSDL20(wsdl,
236: tns, wsoap, whttp, nameSpaceMap));
237: }
238: }
239:
240: // Populate Binding Operations
241: Iterator iterator = this .getChildren();
242: while (iterator.hasNext()) {
243: AxisBindingOperation axisBindingOperation = (AxisBindingOperation) iterator
244: .next();
245: bindingElement
246: .addChild(axisBindingOperation.toWSDL20(wsdl, tns,
247: wsoap, whttp, type, nameSpaceMap,
248: serviceName));
249: }
250: WSDLSerializationUtil.addWSDLDocumentationElement(this ,
251: bindingElement, omFactory, wsdl);
252: return bindingElement;
253: }
254:
255: public Policy getEffectivePolicy() {
256: ArrayList policyList = new ArrayList();
257: policyList.addAll(getPolicyInclude().getAttachedPolicies());
258:
259: // AxisEndpoint
260: AxisEndpoint axisEndpoint = getAxisEndpoint();
261:
262: if (axisEndpoint != null) {
263: policyList.addAll(axisEndpoint.getPolicyInclude()
264: .getAttachedPolicies());
265: }
266:
267: AxisService service = null;
268:
269: if (axisEndpoint != null) {
270: service = axisEndpoint.getAxisService();
271: }
272:
273: if (service != null) {
274: Policy effectivePolicy = service.getPolicyInclude()
275: .getEffectivePolicy();
276: if (effectivePolicy != null) {
277: policyList.add(effectivePolicy);
278: }
279: }
280:
281: return PolicyUtil.getMergedPolicy(policyList, this );
282: }
283:
284: public AxisEndpoint getAxisEndpoint() {
285: return (AxisEndpoint) parent;
286: }
287: }
|