View Javadoc

1   /*
2    * Copyright 2008 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.wsdl.wsdl11;
18  
19  import javax.wsdl.Definition;
20  import javax.wsdl.WSDLException;
21  import javax.wsdl.factory.WSDLFactory;
22  
23  import org.springframework.beans.factory.InitializingBean;
24  import org.springframework.util.Assert;
25  import org.springframework.ws.wsdl.wsdl11.provider.BindingsProvider;
26  import org.springframework.ws.wsdl.wsdl11.provider.ImportsProvider;
27  import org.springframework.ws.wsdl.wsdl11.provider.MessagesProvider;
28  import org.springframework.ws.wsdl.wsdl11.provider.PortTypesProvider;
29  import org.springframework.ws.wsdl.wsdl11.provider.ServicesProvider;
30  import org.springframework.ws.wsdl.wsdl11.provider.TypesProvider;
31  
32  /**
33   * Implementation of the [email protected] Wsdl11Definition} that uses a provider-based mechanism to populate a WSDL4J [email protected]
34   * Definition}.
35   * <p/>
36   * All providers are optional, indicating that a particular part of the WSDL will not be created. Providers can be set
37   * via various properties. The providers are [email protected] #afterPropertiesSet() invoked} in the following order: <ol>
38   * <li>[email protected] ImportsProvider}</li> <li>[email protected] TypesProvider}</li> <li>[email protected] MessagesProvider}</li> <li>[email protected]
39   * PortTypesProvider}</li> <li>[email protected] BindingsProvider}</li> <li>[email protected] ServicesProvider}</li> </ol>
40   * <p/>
41   * This definition requires the target namespace to be set via [email protected] #setTargetNamespace(String)}
42   *
43   * @author Arjen Poutsma
44   * @see #setImportsProvider(ImportsProvider)
45   * @see #setTypesProvider(TypesProvider)
46   * @see #setMessagesProvider(MessagesProvider)
47   * @see #setPortTypesProvider(PortTypesProvider)
48   * @see #setBindingsProvider(BindingsProvider)
49   * @see #setServicesProvider(ServicesProvider)
50   * @since 1.5.0
51   */
52  public class ProviderBasedWsdl4jDefinition extends Wsdl4jDefinition implements InitializingBean {
53  
54      /** The prefix used to register the target namespace in the WSDL. */
55      public static final String TARGET_NAMESPACE_PREFIX = "tns";
56  
57      private ImportsProvider importsProvider;
58  
59      private TypesProvider typesProvider;
60  
61      private MessagesProvider messagesProvider;
62  
63      private PortTypesProvider portTypesProvider;
64  
65      private BindingsProvider bindingsProvider;
66  
67      private ServicesProvider servicesProvider;
68  
69      private String targetNamespace;
70  
71      /**
72       * Returns the [email protected] ImportsProvider} for this definition.
73       * <p/>
74       * Default is <code>null</code>, indicating that no <code>&lt;import&gt;</code> will be created
75       *
76       * @return the import provider; or <code>null</code>
77       */
78      public ImportsProvider getImportsProvider() {
79          return importsProvider;
80      }
81  
82      /**
83       * Sets the [email protected] ImportsProvider} for this definition.
84       * <p/>
85       * Default is <code>null</code>, indicating that no <code>&lt;import&gt;</code> will be created
86       *
87       * @param importsProvider the import provider
88       */
89      public void setImportsProvider(ImportsProvider importsProvider) {
90          this.importsProvider = importsProvider;
91      }
92  
93      /**
94       * Returns the [email protected] TypesProvider} for this definition.
95       * <p/>
96       * Defaults to <code>null</code>, indicating that no <code>&lt;types&gt;</code> will be created
97       *
98       * @return the types provider; or <code>null</code>
99       */
100     public TypesProvider getTypesProvider() {
101         return typesProvider;
102     }
103 
104     /**
105      * Sets the [email protected] TypesProvider} for this definition.
106      * <p/>
107      * Defaults to <code>null</code>, indicating that no <code>&lt;types&gt;</code> will be created
108      *
109      * @param typesProvider the types provider; or <code>null</code>
110      */
111     public void setTypesProvider(TypesProvider typesProvider) {
112         this.typesProvider = typesProvider;
113     }
114 
115     /**
116      * Returns the [email protected] MessagesProvider} for this definition.
117      * <p/>
118      * Defaults to <code>null</code>, indicating that no <code>&lt;message&gt;</code> will be created
119      *
120      * @return the messages provider; or <code>null</code>
121      */
122     public MessagesProvider getMessagesProvider() {
123         return messagesProvider;
124     }
125 
126     /**
127      * Sets the [email protected] MessagesProvider} for this definition.
128      * <p/>
129      * Defaults to <code>null</code>, indicating that no <code>&lt;message&gt;</code> will be created
130      *
131      * @param messagesProvider the messages provider; or <code>null</code>
132      */
133     public void setMessagesProvider(MessagesProvider messagesProvider) {
134         this.messagesProvider = messagesProvider;
135     }
136 
137     /**
138      * Returns the [email protected] PortTypesProvider} for this definition.
139      * <p/>
140      * Defaults to <code>null</code>, indicating that no <code>&lt;portType&gt;</code> will be created
141      *
142      * @return the port types provider; or <code>null</code>
143      */
144     public PortTypesProvider getPortTypesProvider() {
145         return portTypesProvider;
146     }
147 
148     /**
149      * Sets the [email protected] PortTypesProvider} for this definition.
150      * <p/>
151      * Defaults to <code>null</code>, indicating that no <code>&lt;portType&gt;</code> will be created
152      *
153      * @param portTypesProvider the port types provider; or <code>null</code>
154      */
155     public void setPortTypesProvider(PortTypesProvider portTypesProvider) {
156         this.portTypesProvider = portTypesProvider;
157     }
158 
159     /**
160      * Returns the [email protected] BindingsProvider} for this definition.
161      * <p/>
162      * Defaults to <code>null</code>, indicating that no <code>&lt;binding&gt;</code> will be created
163      *
164      * @return the binding provider; or <code>null</code>
165      */
166     public BindingsProvider getBindingsProvider() {
167         return bindingsProvider;
168     }
169 
170     /**
171      * Sets the [email protected] BindingsProvider} for this definition.
172      * <p/>
173      * Defaults to <code>null</code>, indicating that no <code>&lt;binding&gt;</code> will be created
174      *
175      * @param bindingsProvider the bindings provider; or <code>null</code>
176      */
177     public void setBindingsProvider(BindingsProvider bindingsProvider) {
178         this.bindingsProvider = bindingsProvider;
179     }
180 
181     /**
182      * Returns the [email protected] ServicesProvider} for this definition.
183      * <p/>
184      * Defaults to <code>null</code>, indicating that no <code>&lt;service&gt;</code> will be created
185      *
186      * @return the services provider; or <code>null</code>
187      */
188     public ServicesProvider getServicesProvider() {
189         return servicesProvider;
190     }
191 
192     /**
193      * Sets the [email protected] ServicesProvider} for this definition.
194      * <p/>
195      * Defaults to <code>null</code>, indicating that no <code>&lt;service&gt;</code> will be created
196      *
197      * @param servicesProvider the services provider; or <code>null</code>
198      */
199     public void setServicesProvider(ServicesProvider servicesProvider) {
200         this.servicesProvider = servicesProvider;
201     }
202 
203     /**
204      * Returns the target namespace for the WSDL definition.
205      *
206      * @return the target namespace
207      * @see javax.wsdl.Definition#getTargetNamespace()
208      */
209     public String getTargetNamespace() {
210         return targetNamespace;
211     }
212 
213     /**
214      * Sets the target namespace used for this definition. Required.
215      *
216      * @param targetNamespace the target namespace
217      * @see javax.wsdl.Definition#setTargetNamespace(String)
218      */
219     public void setTargetNamespace(String targetNamespace) {
220         this.targetNamespace = targetNamespace;
221     }
222 
223     public void afterPropertiesSet() throws WSDLException {
224         Assert.notNull(getTargetNamespace(), "'targetNamespace' is required");
225         WSDLFactory wsdlFactory = WSDLFactory.newInstance();
226         Definition definition = wsdlFactory.newDefinition();
227         definition.setTargetNamespace(getTargetNamespace());
228         definition.addNamespace(TARGET_NAMESPACE_PREFIX, getTargetNamespace());
229         if (importsProvider != null) {
230             importsProvider.addImports(definition);
231         }
232         if (typesProvider != null) {
233             typesProvider.addTypes(definition);
234         }
235         if (messagesProvider != null) {
236             messagesProvider.addMessages(definition);
237         }
238         if (portTypesProvider != null) {
239             portTypesProvider.addPortTypes(definition);
240         }
241         if (bindingsProvider != null) {
242             bindingsProvider.addBindings(definition);
243         }
244         if (servicesProvider != null) {
245             servicesProvider.addServices(definition);
246         }
247         setDefinition(definition);
248     }
249 }