1
2
3
4
5
6
7
8
9
10
11
12
13
14
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.util.StringUtils;
28 import org.springframework.ws.wsdl.WsdlDefinitionException;
29
30 import org.w3c.dom.Document;
31
32
33
34
35
36
37
38
39
40
41 public class Wsdl4jDefinition implements Wsdl11Definition {
42
43 private Definition definition;
44
45
46 private Document document;
47
48
49 private final Object monitor = new Object();
50
51
52
53
54
55
56 public Wsdl4jDefinition() {
57 }
58
59
60
61
62
63
64 public Wsdl4jDefinition(Definition definition) {
65 setDefinition(definition);
66 }
67
68
69 public Definition getDefinition() {
70 synchronized (monitor) {
71 return definition;
72 }
73 }
74
75
76 public void setDefinition(Definition definition) {
77 synchronized (monitor) {
78 this.definition = definition;
79 this.document = null;
80 }
81 }
82
83 public Source getSource() {
84 synchronized (monitor) {
85 Assert.notNull(definition, "definition must not be null");
86 if (document == null) {
87 try {
88 WSDLFactory wsdlFactory = WSDLFactory.newInstance();
89 WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter();
90 document = wsdlWriter.getDocument(definition);
91 }
92 catch (WSDLException ex) {
93 throw new WsdlDefinitionException(ex.getMessage(), ex);
94 }
95 }
96 }
97 return new DOMSource(document);
98 }
99
100 public String toString() {
101 StringBuilder builder = new StringBuilder("Wsdl4jDefinition");
102 if (definition != null && StringUtils.hasLength(definition.getTargetNamespace())) {
103 builder.append('{');
104 builder.append(definition.getTargetNamespace());
105 builder.append('}');
106 }
107 return builder.toString();
108 }
109 }