@@ -40,6 +40,12 @@ public class Wsdl4jDefinition implements Wsdl11Definition {
4040
4141 private Definition definition ;
4242
43+ /** Cached DOM version of the definition */
44+ private Document document ;
45+
46+ /** WSDL4J is not thread safe, hence the need for a monitor. */
47+ private final Object monitor = new Object ();
48+
4349 /**
4450 * Constructs a new, empty <code>Wsdl4jDefinition</code>.
4551 *
@@ -54,7 +60,7 @@ public Wsdl4jDefinition() {
5460 * @param definition the WSDL4J definition
5561 */
5662 public Wsdl4jDefinition (Definition definition ) {
57- this . definition = definition ;
63+ setDefinition ( definition ) ;
5864 }
5965
6066 /** Returns the WSDL4J <code>Definition</code>. */
@@ -64,19 +70,26 @@ public Definition getDefinition() {
6470
6571 /** Set the WSDL4J <code>Definition</code>. */
6672 public void setDefinition (Definition definition ) {
67- this .definition = definition ;
73+ synchronized (monitor ) {
74+ this .definition = definition ;
75+ this .document = null ;
76+ }
6877 }
6978
7079 public Source getSource () {
7180 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- }
78- catch (WSDLException ex ) {
79- throw new WsdlDefinitionException (ex .getMessage (), ex );
81+ synchronized (monitor ) {
82+ if (document == null ) {
83+ try {
84+ WSDLFactory wsdlFactory = WSDLFactory .newInstance ();
85+ WSDLWriter wsdlWriter = wsdlFactory .newWSDLWriter ();
86+ document = wsdlWriter .getDocument (definition );
87+ }
88+ catch (WSDLException ex ) {
89+ throw new WsdlDefinitionException (ex .getMessage (), ex );
90+ }
91+ }
8092 }
93+ return new DOMSource (document );
8194 }
8295}
0 commit comments