01: /*
02: * Copyright 2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: import javax.wsdl.xml.WSDLWriter;
23: import javax.xml.transform.Source;
24: import javax.xml.transform.dom.DOMSource;
25:
26: import org.springframework.util.Assert;
27: import org.springframework.ws.wsdl.WsdlDefinitionException;
28: import org.w3c.dom.Document;
29:
30: /**
31: * Implementation of the <code>Wsdl11Definition</code> based on WSDL4J. A {@link javax.wsdl.Definition} can be given as
32: * as constructor argument, or set using a property.
33: *
34: * @author Arjen Poutsma
35: * @see #Wsdl4jDefinition(javax.wsdl.Definition)
36: * @see #setDefinition(javax.wsdl.Definition)
37: * @since 1.0.0
38: */
39: public class Wsdl4jDefinition implements Wsdl11Definition {
40:
41: private Definition definition;
42:
43: /**
44: * Constructs a new, empty <code>Wsdl4jDefinition</code>.
45: *
46: * @see #setDefinition(javax.wsdl.Definition)
47: */
48: public Wsdl4jDefinition() {
49: }
50:
51: /**
52: * Constructs a new <code>Wsdl4jDefinition</code> based on the given <code>Definition</code>.
53: *
54: * @param definition the WSDL4J definition
55: */
56: public Wsdl4jDefinition(Definition definition) {
57: this .definition = definition;
58: }
59:
60: /** Returns the WSDL4J <code>Definition</code>. */
61: public Definition getDefinition() {
62: return definition;
63: }
64:
65: /** Set the WSDL4J <code>Definition</code>. */
66: public void setDefinition(Definition definition) {
67: this .definition = definition;
68: }
69:
70: public Source getSource() {
71: Assert.notNull(definition, "definition must not be null");
72: try {
73: WSDLFactory wsdlFactory = WSDLFactory.newInstance();
74: WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
75: Document document = wsdlWriter.getDocument(definition);
76: return new DOMSource(document);
77: } catch (WSDLException ex) {
78: throw new WsdlDefinitionException(ex.getMessage(), ex);
79: }
80: }
81: }
|