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.axiom.om.OMAbstractFactory;
022: import org.apache.axiom.om.OMElement;
023: import org.apache.axiom.om.OMFactory;
024: import org.apache.axiom.om.OMNamespace;
025: import org.apache.axis2.AxisFault;
026: import org.apache.axis2.util.PolicyUtil;
027: import org.apache.axis2.util.WSDL20Util;
028: import org.apache.axis2.util.WSDLSerializationUtil;
029: import org.apache.axis2.wsdl.WSDLConstants;
030: import org.apache.neethi.Policy;
031:
032: import java.util.ArrayList;
033: import java.util.HashMap;
034: import java.util.Map;
035:
036: public class AxisBindingMessage extends AxisDescription {
037:
038: private String name;
039:
040: private String direction;
041:
042: private Map options;
043:
044: private AxisMessage axisMessage;
045:
046: // Used to indicate whether this message is a fault or not. Needed for the WSDL 2.0 serializer
047: private boolean fault = false;
048:
049: public boolean isFault() {
050: return fault;
051: }
052:
053: public void setFault(boolean fault) {
054: this .fault = fault;
055: }
056:
057: public String getName() {
058: return name;
059: }
060:
061: public void setName(String name) {
062: this .name = name;
063: }
064:
065: public AxisMessage getAxisMessage() {
066: return axisMessage;
067: }
068:
069: public void setAxisMessage(AxisMessage axisMessage) {
070: this .axisMessage = axisMessage;
071: }
072:
073: public String getDirection() {
074: return direction;
075: }
076:
077: public void setDirection(String direction) {
078: this .direction = direction;
079: }
080:
081: public AxisBindingMessage() {
082: options = new HashMap();
083: }
084:
085: public void setProperty(String name, Object value) {
086: options.put(name, value);
087: }
088:
089: /**
090: * @param name name of the property to search for
091: * @return the value of the property, or null if the property is not found
092: */
093: public Object getProperty(String name) {
094: Object obj = options.get(name);
095: if (obj != null) {
096: return obj;
097: }
098:
099: return null;
100: }
101:
102: public Object getKey() {
103: return null; //To change body of implemented methods use File | Settings | File Templates.
104: }
105:
106: public void engageModule(AxisModule axisModule) throws AxisFault {
107: throw new UnsupportedOperationException(
108: "Sorry we do not support this");
109: }
110:
111: public boolean isEngaged(String moduleName) {
112: throw new UnsupportedOperationException(
113: "axisMessage.isEngaged() is not supported");
114:
115: }
116:
117: /**
118: * Generates the bindingMessage element (can be input, output, infault or outfault)
119: * @param tns - The targetnamespace
120: * @param wsoap - The SOAP namespace (WSDL 2.0)
121: * @param whttp - The HTTP namespace (WSDL 2.0)
122: * @param nameSpaceMap - The namespacemap of the service
123: * @return The generated bindingMessage element
124: */
125: public OMElement toWSDL20(OMNamespace wsdl, OMNamespace tns,
126: OMNamespace wsoap, OMNamespace whttp, Map nameSpaceMap) {
127: String property;
128: ArrayList list;
129: OMFactory omFactory = OMAbstractFactory.getOMFactory();
130: OMElement bindingMessageElement;
131:
132: // If this is a fault, create a fault element and add fault specific properties
133: if (this .isFault()) {
134: if (this .getParent() instanceof AxisBinding) {
135: bindingMessageElement = omFactory.createOMElement(
136: WSDL2Constants.FAULT_LOCAL_NAME, wsdl);
137: } else if (WSDLConstants.WSDL_MESSAGE_DIRECTION_IN
138: .equals(this .getDirection())) {
139: bindingMessageElement = omFactory.createOMElement(
140: WSDL2Constants.IN_FAULT_LOCAL_NAME, wsdl);
141: } else {
142: bindingMessageElement = omFactory.createOMElement(
143: WSDL2Constants.OUT_FAULT_LOCAL_NAME, wsdl);
144: }
145: bindingMessageElement.addAttribute(omFactory
146: .createOMAttribute(WSDL2Constants.ATTRIBUTE_REF,
147: null, tns.getPrefix() + ":" + this .name));
148:
149: WSDL20Util.extractWSDL20SoapFaultInfo(options,
150: bindingMessageElement, omFactory, wsoap);
151:
152: Integer code = (Integer) this .options
153: .get(WSDL2Constants.ATTR_WHTTP_CODE);
154: if (code != null) {
155: bindingMessageElement.addAttribute(omFactory
156: .createOMAttribute(
157: WSDL2Constants.ATTRIBUTE_CODE, whttp,
158: code.toString()));
159: }
160:
161: //Checks whether the message is an input message
162: } else if (WSDLConstants.WSDL_MESSAGE_DIRECTION_IN.equals(this
163: .getDirection())) {
164: bindingMessageElement = omFactory.createOMElement(
165: WSDL2Constants.IN_PUT_LOCAL_NAME, wsdl);
166:
167: //Message should be an output message
168: } else {
169: bindingMessageElement = omFactory.createOMElement(
170: WSDL2Constants.OUT_PUT_LOCAL_NAME, wsdl);
171: }
172:
173: // Populate common properties
174: property = (String) this .options
175: .get(WSDL2Constants.ATTR_WHTTP_CONTENT_ENCODING);
176: if (property != null) {
177: bindingMessageElement.addAttribute(omFactory
178: .createOMAttribute(
179: WSDL2Constants.ATTRIBUTE_CONTENT_ENCODING,
180: whttp, property));
181: }
182: list = (ArrayList) this .options
183: .get(WSDL2Constants.ATTR_WHTTP_HEADER);
184: if (list != null && list.size() > 0) {
185: WSDLSerializationUtil.addHTTPHeaderElements(omFactory,
186: list, whttp, bindingMessageElement, nameSpaceMap);
187: }
188: list = (ArrayList) this .options
189: .get(WSDL2Constants.ATTR_WSOAP_HEADER);
190: if (list != null && list.size() > 0) {
191: WSDLSerializationUtil.addSOAPHeaderElements(omFactory,
192: list, wsoap, bindingMessageElement, nameSpaceMap);
193: }
194: list = (ArrayList) this .options
195: .get(WSDL2Constants.ATTR_WSOAP_MODULE);
196: if (list != null && list.size() > 0) {
197: WSDLSerializationUtil.addSOAPModuleElements(omFactory,
198: list, wsoap, bindingMessageElement);
199: }
200: WSDLSerializationUtil.addWSDLDocumentationElement(this ,
201: bindingMessageElement, omFactory, wsdl);
202: return bindingMessageElement;
203: }
204:
205: public Policy getEffectivePolicy() {
206: ArrayList policyList = new ArrayList();
207:
208: PolicyInclude policyInclude;
209:
210: // AxisBindingMessage policies
211: policyInclude = getPolicyInclude();
212: policyList.addAll(policyInclude.getAttachedPolicies());
213:
214: // AxisBindingOperation policies
215: AxisBindingOperation axisBindingOperation = getAxisBindingOperation();
216: if (axisBindingOperation != null) {
217: policyList.addAll(axisBindingOperation.getPolicyInclude()
218: .getAttachedPolicies());
219: }
220:
221: // AxisBinding policies
222: AxisBinding axisBinding = null;
223: if (axisBindingOperation != null) {
224: axisBinding = axisBindingOperation.getAxisBinding();
225: }
226:
227: if (axisBinding != null) {
228: policyList.addAll(axisBinding.getPolicyInclude()
229: .getAttachedPolicies());
230: }
231:
232: // AxisEndpoint
233: AxisEndpoint axisEndpoint = null;
234: if (axisBinding != null) {
235: axisEndpoint = axisBinding.getAxisEndpoint();
236: }
237:
238: if (axisEndpoint != null) {
239: policyList.addAll(axisEndpoint.getPolicyInclude()
240: .getAttachedPolicies());
241: }
242:
243: // AxisMessage
244: Policy axisOperationPolicy = axisMessage.getPolicyInclude()
245: .getEffectivePolicy();
246:
247: if (axisOperationPolicy != null) {
248: policyList.add(axisOperationPolicy);
249: }
250:
251: return PolicyUtil.getMergedPolicy(policyList, this );
252: }
253:
254: public AxisBindingOperation getAxisBindingOperation() {
255: return (AxisBindingOperation) parent;
256: }
257:
258: }
|