001: /*
002: * Copyright 2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.springframework.ws.wsdl.wsdl11.builder;
018:
019: import javax.wsdl.Binding;
020: import javax.wsdl.BindingFault;
021: import javax.wsdl.BindingInput;
022: import javax.wsdl.BindingOperation;
023: import javax.wsdl.BindingOutput;
024: import javax.wsdl.Definition;
025: import javax.wsdl.Fault;
026: import javax.wsdl.Input;
027: import javax.wsdl.Operation;
028: import javax.wsdl.Output;
029: import javax.wsdl.Port;
030: import javax.wsdl.PortType;
031: import javax.wsdl.WSDLException;
032: import javax.wsdl.extensions.ExtensibilityElement;
033: import javax.wsdl.extensions.soap.SOAPAddress;
034: import javax.wsdl.extensions.soap.SOAPBinding;
035: import javax.wsdl.extensions.soap.SOAPBody;
036: import javax.wsdl.extensions.soap.SOAPFault;
037: import javax.wsdl.extensions.soap.SOAPOperation;
038: import javax.xml.namespace.QName;
039:
040: /**
041: * Abstract base class for <code>Wsdl11DefinitionBuilder</code> implementations that use WSDL4J and contain a SOAP 1.1
042: * binding. Requires the <code>locationUri</code> property to be set before use.
043: *
044: * @author Arjen Poutsma
045: * @see #setLocationUri(String)
046: * @since 1.0.0
047: */
048: public abstract class AbstractSoap11Wsdl4jDefinitionBuilder extends
049: AbstractBindingWsdl4jDefinitionBuilder {
050:
051: private static final String WSDL_SOAP_NAMESPACE_URI = "http://schemas.xmlsoap.org/wsdl/soap/";
052:
053: private static final String WSDL_SOAP_PREFIX = "soap";
054:
055: /** The default soap:binding transport attribute value. */
056: public static final String DEFAULT_TRANSPORT_URI = "http://schemas.xmlsoap.org/soap/http";
057:
058: private String transportUri = DEFAULT_TRANSPORT_URI;
059:
060: private String locationUri;
061:
062: /**
063: * Sets the value used for the soap:binding transport attribute value.
064: *
065: * @see javax.wsdl.extensions.soap.SOAPBinding#setTransportURI(String)
066: * @see #DEFAULT_TRANSPORT_URI
067: */
068: public void setTransportUri(String transportUri) {
069: this .transportUri = transportUri;
070: }
071:
072: /** Sets the value used for the soap:address location attribute value. */
073: public void setLocationUri(String locationUri) {
074: this .locationUri = locationUri;
075: }
076:
077: /** Adds the WSDL SOAP namespace to the definition. */
078: protected void populateDefinition(Definition definition)
079: throws WSDLException {
080: definition.addNamespace(WSDL_SOAP_PREFIX,
081: WSDL_SOAP_NAMESPACE_URI);
082: }
083:
084: /**
085: * Calls <code>populateBindingInternal()</code>, creates <code>SOAPBinding</code>, and calls
086: * <code>populateSoapBinding()</code>.
087: *
088: * @param binding the WSDL4J <code>Binding</code>
089: * @param portType the corresponding <code>PortType</code>
090: * @throws WSDLException in case of errors
091: * @see javax.wsdl.extensions.soap.SOAPBinding
092: * @see #populateSoapBinding(javax.wsdl.extensions.soap.SOAPBinding)
093: */
094: protected void populateBinding(Binding binding, PortType portType)
095: throws WSDLException {
096: super .populateBinding(binding, portType);
097: SOAPBinding soapBinding = (SOAPBinding) createSoapExtension(
098: Binding.class, "binding");
099: populateSoapBinding(soapBinding);
100: binding.addExtensibilityElement(soapBinding);
101: }
102:
103: /**
104: * Called after the <code>SOAPBinding</code> has been created. Default implementation sets the binding style to
105: * <code>"document"</code>, and set the transport URI to the value set on this builder. Subclasses can override this
106: * behavior.
107: *
108: * @param soapBinding the WSDL4J <code>SOAPBinding</code>
109: * @throws WSDLException in case of errors
110: * @see javax.wsdl.extensions.soap.SOAPBinding#setStyle(String)
111: * @see javax.wsdl.extensions.soap.SOAPBinding#setTransportURI(String)
112: * @see #setTransportUri(String)
113: * @see #DEFAULT_TRANSPORT_URI
114: */
115: protected void populateSoapBinding(SOAPBinding soapBinding)
116: throws WSDLException {
117: soapBinding.setStyle("document");
118: soapBinding.setTransportURI(transportUri);
119: }
120:
121: /**
122: * Calls <code>getBindingOperationName()</code>, creates a <code>SOAPOperation</code>, and calls
123: * <code>populateSoapOperation()</code>.
124: *
125: * @param bindingOperation the WSDL4J <code>BindingOperation</code>
126: * @throws WSDLException in case of errors
127: * @see javax.wsdl.extensions.soap.SOAPOperation
128: * @see #populateSoapOperation(javax.wsdl.extensions.soap.SOAPOperation)
129: */
130: protected void populateBindingOperation(
131: BindingOperation bindingOperation, Operation operation)
132: throws WSDLException {
133: super .populateBindingOperation(bindingOperation, operation);
134: SOAPOperation soapOperation = (SOAPOperation) createSoapExtension(
135: BindingOperation.class, "operation");
136: populateSoapOperation(soapOperation);
137: bindingOperation.addExtensibilityElement(soapOperation);
138: }
139:
140: /**
141: * Called after the <code>SOAPOperation</code> has been created.
142: * <p/>
143: * Default implementation set the <code>SOAPAction</code> uri to an empty string.
144: *
145: * @param soapOperation the WSDL4J <code>SOAPOperation</code>
146: * @throws WSDLException in case of errors
147: * @see javax.wsdl.extensions.soap.SOAPOperation#setSoapActionURI(String)
148: */
149: protected void populateSoapOperation(SOAPOperation soapOperation)
150: throws WSDLException {
151: soapOperation.setSoapActionURI("");
152: }
153:
154: /**
155: * Creates a <code>SOAPBody</code>, and calls <code>populateSoapBody()</code>.
156: *
157: * @param bindingInput the WSDL4J <code>BindingInput</code>
158: * @throws WSDLException in case of errors
159: * @see javax.wsdl.extensions.soap.SOAPOperation
160: * @see #populateSoapBody(javax.wsdl.extensions.soap.SOAPBody)
161: */
162: protected void populateBindingInput(BindingInput bindingInput,
163: Input input) throws WSDLException {
164: super .populateBindingInput(bindingInput, input);
165: SOAPBody soapBody = (SOAPBody) createSoapExtension(
166: BindingInput.class, "body");
167: populateSoapBody(soapBody);
168: bindingInput.addExtensibilityElement(soapBody);
169: }
170:
171: /**
172: * Creates a <code>SOAPBody</code>, and calls <code>populateSoapBody()</code>.
173: *
174: * @param bindingOutput the WSDL4J <code>BindingOutput</code>
175: * @throws javax.wsdl.WSDLException in case of errors
176: * @see javax.wsdl.extensions.soap.SOAPOperation
177: * @see #populateSoapBody(javax.wsdl.extensions.soap.SOAPBody)
178: */
179: protected void populateBindingOutput(BindingOutput bindingOutput,
180: Output output) throws WSDLException {
181: super .populateBindingOutput(bindingOutput, output);
182: SOAPBody soapBody = (SOAPBody) createSoapExtension(
183: BindingOutput.class, "body");
184: populateSoapBody(soapBody);
185: bindingOutput.addExtensibilityElement(soapBody);
186: }
187:
188: /**
189: * Creates a <code>SOAPBody</code>, and calls <code>populateSoapBody()</code>.
190: *
191: * @param bindingFault the WSDL4J <code>BindingFault</code>
192: * @throws javax.wsdl.WSDLException in case of errors
193: * @see javax.wsdl.extensions.soap.SOAPOperation
194: * @see #populateSoapBody(javax.wsdl.extensions.soap.SOAPBody)
195: */
196: protected void populateBindingFault(BindingFault bindingFault,
197: Fault fault) throws WSDLException {
198: super .populateBindingFault(bindingFault, fault);
199: SOAPFault soapFault = (SOAPFault) createSoapExtension(
200: BindingFault.class, "fault");
201: populateSoapFault(bindingFault, soapFault);
202: bindingFault.addExtensibilityElement(soapFault);
203: }
204:
205: /**
206: * Called after the <code>SOAPBody</code> has been created. Default implementation sets the use style to
207: * <code>"literal"</code>. Subclasses can override this behavior.
208: *
209: * @param soapBody the WSDL4J <code>SOAPBody</code>
210: * @throws WSDLException in case of errors
211: * @see javax.wsdl.extensions.soap.SOAPBody#setUse(String)
212: */
213: protected void populateSoapBody(SOAPBody soapBody)
214: throws WSDLException {
215: soapBody.setUse("literal");
216: }
217:
218: /**
219: * Called after the <code>SOAPFault</code> has been created. Default implementation sets the use style to
220: * <code>"literal"</code>, and sets the name equal to the binding fault. Subclasses can override this behavior.
221: *
222: * @param bindingFault the WSDL4J <code>BindingFault</code>
223: * @param soapFault the WSDL4J <code>SOAPFault</code>
224: * @throws WSDLException in case of errors
225: * @see javax.wsdl.extensions.soap.SOAPBody#setUse(String)
226: */
227: protected void populateSoapFault(BindingFault bindingFault,
228: SOAPFault soapFault) throws WSDLException {
229: soapFault.setName(bindingFault.getName());
230: soapFault.setUse("literal");
231: }
232:
233: /**
234: * Creates a <code>SOAPAddress</code>, and calls <code>populateSoapAddress()</code>.
235: *
236: * @param port the WSDL4J <code>Port</code>
237: * @throws javax.wsdl.WSDLException in case of errors
238: * @see javax.wsdl.extensions.soap.SOAPAddress
239: * @see #populateSoapBody(javax.wsdl.extensions.soap.SOAPBody)
240: */
241: protected void populatePort(Port port, Binding binding)
242: throws WSDLException {
243: super .populatePort(port, binding);
244: SOAPAddress soapAddress = (SOAPAddress) createSoapExtension(
245: Port.class, "address");
246: populateSoapAddress(soapAddress);
247: port.addExtensibilityElement(soapAddress);
248: }
249:
250: /**
251: * Called after the <code>SOAPAddress</code> has been created. Default implementation sets the location URI to the
252: * value set on this builder. Subclasses can override this behavior.
253: *
254: * @param soapAddress the WSDL4J <code>SOAPAddress</code>
255: * @throws WSDLException in case of errors
256: * @see javax.wsdl.extensions.soap.SOAPAddress#setLocationURI(String)
257: * @see #setLocationUri(String)
258: */
259: protected void populateSoapAddress(SOAPAddress soapAddress)
260: throws WSDLException {
261: soapAddress.setLocationURI(locationUri);
262: }
263:
264: /**
265: * Creates a SOAP extensibility element.
266: *
267: * @param parentType a class object indicating where in the WSDL definition this extension will exist
268: * @param localName the local name of the extensibility element
269: * @return the extensibility element
270: * @throws WSDLException in case of errors
271: * @see javax.wsdl.extensions.ExtensionRegistry#createExtension(Class,javax.xml.namespace.QName)
272: */
273: protected ExtensibilityElement createSoapExtension(
274: Class parentType, String localName) throws WSDLException {
275: return createExtension(parentType, new QName(
276: WSDL_SOAP_NAMESPACE_URI, localName));
277: }
278:
279: }
|