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.Definition;
020: import javax.wsdl.WSDLException;
021: import javax.wsdl.extensions.ExtensibilityElement;
022: import javax.wsdl.extensions.ExtensionRegistry;
023: import javax.wsdl.factory.WSDLFactory;
024: import javax.xml.namespace.QName;
025:
026: import org.apache.commons.logging.Log;
027: import org.apache.commons.logging.LogFactory;
028: import org.springframework.ws.wsdl.WsdlDefinitionException;
029: import org.springframework.ws.wsdl.wsdl11.Wsdl11Definition;
030: import org.springframework.ws.wsdl.wsdl11.Wsdl11DefinitionBuilder;
031: import org.springframework.ws.wsdl.wsdl11.Wsdl4jDefinition;
032: import org.springframework.ws.wsdl.wsdl11.Wsdl4jDefinitionException;
033:
034: /**
035: * Abstract base class for <code>Wsdl11DefinitionBuilder</code> implementations that use WSDL4J. Creates a base {@link
036: * Definition}, and passes that to subclass template methods.
037: *
038: * @author Arjen Poutsma
039: * @since 1.0.0
040: */
041: public abstract class AbstractWsdl4jDefinitionBuilder implements
042: Wsdl11DefinitionBuilder {
043:
044: /** Logger available to subclasses. */
045: protected final Log logger = LogFactory.getLog(getClass());
046:
047: /** WSDL4J extension registry. Lazily created in <code>createExtension()</code>. */
048: private ExtensionRegistry extensionRegistry;
049:
050: /** The WSDL4J <code>Definition</code> created by <code>buildDefinition()</code>. */
051: private Definition definition;
052:
053: public final void buildDefinition() throws WsdlDefinitionException {
054: try {
055: WSDLFactory wsdlFactory = WSDLFactory.newInstance();
056: definition = wsdlFactory.newDefinition();
057: populateDefinition(definition);
058: } catch (WSDLException ex) {
059: throw new Wsdl4jDefinitionException(ex);
060: }
061: }
062:
063: /**
064: * Called after the <code>Definition</code> has been created, but before any sub-elements are added. Default
065: * implementation is empty.
066: *
067: * @param definition the WSDL4J <code>Definition</code>
068: * @throws WSDLException in case of errors
069: * @see #buildDefinition()
070: */
071: protected void populateDefinition(Definition definition)
072: throws WSDLException {
073: }
074:
075: public final void buildImports() throws WsdlDefinitionException {
076: try {
077: buildImports(definition);
078: } catch (WSDLException ex) {
079: throw new Wsdl4jDefinitionException(ex);
080: }
081: }
082:
083: /**
084: * Adds imports to the definition.
085: *
086: * @param definition the WSDL4J <code>Definition</code>
087: * @throws WSDLException in case of errors
088: */
089: protected abstract void buildImports(Definition definition)
090: throws WSDLException;
091:
092: public final void buildTypes() throws WsdlDefinitionException {
093: try {
094: buildTypes(definition);
095: } catch (WSDLException ex) {
096: throw new Wsdl4jDefinitionException(ex);
097: }
098: }
099:
100: /**
101: * Adds types to the definition.
102: *
103: * @param definition the WSDL4J <code>Definition</code>
104: * @throws WSDLException in case of errors
105: */
106: protected abstract void buildTypes(Definition definition)
107: throws WSDLException;
108:
109: public final void buildMessages() throws WsdlDefinitionException {
110: try {
111: buildMessages(definition);
112: } catch (WSDLException ex) {
113: throw new Wsdl4jDefinitionException(ex);
114: }
115: }
116:
117: /**
118: * Adds messages to the definition.
119: *
120: * @param definition the WSDL4J <code>Definition</code>
121: * @throws WSDLException in case of errors
122: */
123: protected abstract void buildMessages(Definition definition)
124: throws WSDLException;
125:
126: public final void buildPortTypes() throws WsdlDefinitionException {
127: try {
128: buildPortTypes(definition);
129: } catch (WSDLException ex) {
130: throw new Wsdl4jDefinitionException(ex);
131: }
132: }
133:
134: /**
135: * Adds port types to the definition.
136: *
137: * @param definition the WSDL4J <code>Definition</code>
138: * @throws WSDLException in case of errors
139: */
140: protected abstract void buildPortTypes(Definition definition)
141: throws WSDLException;
142:
143: public final void buildBindings() throws WsdlDefinitionException {
144: try {
145: buildBindings(definition);
146: } catch (WSDLException ex) {
147: throw new Wsdl4jDefinitionException(ex);
148: }
149: }
150:
151: /**
152: * Adds bindings to the definition.
153: *
154: * @param definition the WSDL4J <code>Definition</code>
155: * @throws WSDLException in case of errors
156: */
157: protected abstract void buildBindings(Definition definition)
158: throws WSDLException;
159:
160: public final void buildServices() throws WsdlDefinitionException {
161: try {
162: buildServices(definition);
163: } catch (WSDLException ex) {
164: throw new Wsdl4jDefinitionException(ex);
165: }
166: }
167:
168: /**
169: * Adds services to the definition.
170: *
171: * @param definition the WSDL4J <code>Definition</code>
172: * @throws WSDLException in case of errors
173: */
174: protected abstract void buildServices(Definition definition)
175: throws WSDLException;
176:
177: public final Wsdl11Definition getDefinition()
178: throws WsdlDefinitionException {
179: return new Wsdl4jDefinition(definition);
180: }
181:
182: /**
183: * Creates a WSDL4J extensibility element.
184: *
185: * @param parentType a class object indicating where in the WSDL definition this extension will exist
186: * @param elementType the qname of the extensibility element
187: * @return the extensibility element
188: * @throws WSDLException in case of errors
189: * @see javax.wsdl.extensions.ExtensionRegistry#createExtension(Class,javax.xml.namespace.QName)
190: */
191: protected ExtensibilityElement createExtension(Class parentType,
192: QName elementType) throws WSDLException {
193: if (extensionRegistry == null) {
194: WSDLFactory wsdlFactory = WSDLFactory.newInstance();
195: extensionRegistry = wsdlFactory
196: .newPopulatedExtensionRegistry();
197: }
198: return extensionRegistry.createExtension(parentType,
199: elementType);
200: }
201:
202: }
|