View Javadoc

1   /*
2    * Copyright 2006 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.builder;
18  
19  import javax.wsdl.Definition;
20  import javax.wsdl.WSDLException;
21  import javax.wsdl.extensions.ExtensibilityElement;
22  import javax.wsdl.extensions.ExtensionRegistry;
23  import javax.wsdl.factory.WSDLFactory;
24  import javax.xml.namespace.QName;
25  
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  
29  import org.springframework.ws.wsdl.WsdlDefinitionException;
30  import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
31  import org.springframework.ws.wsdl.wsdl11.Wsdl11DefinitionBuilder;
32  import org.springframework.ws.wsdl.wsdl11.Wsdl4jDefinition;
33  import org.springframework.ws.wsdl.wsdl11.Wsdl4jDefinitionException;
34  
35  /**
36   * Abstract base class for <code>Wsdl11DefinitionBuilder</code> implementations that use WSDL4J. Creates a base {@link
37   * Definition}, and passes that to subclass template methods.
38   *
39   * @author Arjen Poutsma
40   * @since 1.0.0
41   * @deprecated as of Spring Web Services 1.5: superseded by {@link org.springframework.ws.wsdl.wsdl11.DefaultWsdl11Definition}
42   *             and the {@link org.springframework.ws.wsdl.wsdl11.provider} package
43   */
44  public abstract class AbstractWsdl4jDefinitionBuilder implements Wsdl11DefinitionBuilder {
45  
46      /** Logger available to subclasses. */
47      protected final Log logger = LogFactory.getLog(getClass());
48  
49      /** The WSDL4J <code>Definition</code> created by <code>buildDefinition()</code>. */
50      private Definition definition;
51  
52      public final void buildDefinition() throws WsdlDefinitionException {
53          try {
54              WSDLFactory wsdlFactory = WSDLFactory.newInstance();
55              definition = wsdlFactory.newDefinition();
56              if (definition.getExtensionRegistry() == null) {
57                  ExtensionRegistry extensionRegistry = wsdlFactory.newPopulatedExtensionRegistry();
58                  definition.setExtensionRegistry(extensionRegistry);
59              }
60              populateExtensionRegistry(definition.getExtensionRegistry());
61              populateDefinition(definition);
62          }
63          catch (WSDLException ex) {
64              throw new Wsdl4jDefinitionException(ex);
65          }
66      }
67  
68      /**
69       * Called after the <code>Definition</code> has been created, but before any sub-elements are added. Default
70       * implementation is empty.
71       *
72       * @param definition the WSDL4J <code>Definition</code>
73       * @throws WSDLException in case of errors
74       * @see #buildDefinition()
75       */
76      protected void populateDefinition(Definition definition) throws WSDLException {
77      }
78  
79      public final void buildImports() throws WsdlDefinitionException {
80          try {
81              buildImports(definition);
82          }
83          catch (WSDLException ex) {
84              throw new Wsdl4jDefinitionException(ex);
85          }
86      }
87  
88      /**
89       * Adds imports to the definition.
90       *
91       * @param definition the WSDL4J <code>Definition</code>
92       * @throws WSDLException in case of errors
93       */
94      protected abstract void buildImports(Definition definition) throws WSDLException;
95  
96      public final void buildTypes() throws WsdlDefinitionException {
97          try {
98              buildTypes(definition);
99          }
100         catch (WSDLException ex) {
101             throw new Wsdl4jDefinitionException(ex);
102         }
103     }
104 
105     /**
106      * Adds types to the definition.
107      *
108      * @param definition the WSDL4J <code>Definition</code>
109      * @throws WSDLException in case of errors
110      */
111     protected abstract void buildTypes(Definition definition) throws WSDLException;
112 
113     public final void buildMessages() throws WsdlDefinitionException {
114         try {
115             buildMessages(definition);
116         }
117         catch (WSDLException ex) {
118             throw new Wsdl4jDefinitionException(ex);
119         }
120     }
121 
122     /**
123      * Adds messages to the definition.
124      *
125      * @param definition the WSDL4J <code>Definition</code>
126      * @throws WSDLException in case of errors
127      */
128     protected abstract void buildMessages(Definition definition) throws WSDLException;
129 
130     public final void buildPortTypes() throws WsdlDefinitionException {
131         try {
132             buildPortTypes(definition);
133         }
134         catch (WSDLException ex) {
135             throw new Wsdl4jDefinitionException(ex);
136         }
137     }
138 
139     /**
140      * Adds port types to the definition.
141      *
142      * @param definition the WSDL4J <code>Definition</code>
143      * @throws WSDLException in case of errors
144      */
145     protected abstract void buildPortTypes(Definition definition) throws WSDLException;
146 
147     public final void buildBindings() throws WsdlDefinitionException {
148         try {
149             buildBindings(definition);
150         }
151         catch (WSDLException ex) {
152             throw new Wsdl4jDefinitionException(ex);
153         }
154     }
155 
156     /**
157      * Adds bindings to the definition.
158      *
159      * @param definition the WSDL4J <code>Definition</code>
160      * @throws WSDLException in case of errors
161      */
162     protected abstract void buildBindings(Definition definition) throws WSDLException;
163 
164     public final void buildServices() throws WsdlDefinitionException {
165         try {
166             buildServices(definition);
167         }
168         catch (WSDLException ex) {
169             throw new Wsdl4jDefinitionException(ex);
170         }
171     }
172 
173     /**
174      * Adds services to the definition.
175      *
176      * @param definition the WSDL4J <code>Definition</code>
177      * @throws WSDLException in case of errors
178      */
179     protected abstract void buildServices(Definition definition) throws WSDLException;
180 
181     public final Wsdl11Definition getDefinition() throws WsdlDefinitionException {
182         return new Wsdl4jDefinition(definition);
183     }
184 
185     /**
186      * Creates a WSDL4J extensibility element.
187      *
188      * @param parentType  a class object indicating where in the WSDL definition this extension will exist
189      * @param elementType the qname of the extensibility element
190      * @return the extensibility element
191      * @throws WSDLException in case of errors
192      * @see javax.wsdl.extensions.ExtensionRegistry#createExtension(Class,javax.xml.namespace.QName)
193      */
194     protected ExtensibilityElement createExtension(Class parentType, QName elementType) throws WSDLException {
195         return definition.getExtensionRegistry().createExtension(parentType, elementType);
196     }
197 
198     /** Allows customization of the given {@link ExtensionRegistry}. Default implementation is empty. */
199     protected void populateExtensionRegistry(ExtensionRegistry extensionRegistry) {
200     }
201 
202 }