From 6cc8b2c01b2a15c11cf65eb7b9be28a7c9aa0dd6 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Wed, 26 Sep 2007 10:41:03 +0000 Subject: [PATCH] SWS-200 --- .../ws/wsdl/wsdl11/Wsdl4jDefinition.java | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/Wsdl4jDefinition.java b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/Wsdl4jDefinition.java index 38b63345..42b49635 100644 --- a/core/src/main/java/org/springframework/ws/wsdl/wsdl11/Wsdl4jDefinition.java +++ b/core/src/main/java/org/springframework/ws/wsdl/wsdl11/Wsdl4jDefinition.java @@ -40,6 +40,12 @@ public class Wsdl4jDefinition implements Wsdl11Definition { private Definition definition; + /** Cached DOM version of the definition */ + private Document document; + + /** WSDL4J is not thread safe, hence the need for a monitor. */ + private final Object monitor = new Object(); + /** * Constructs a new, empty Wsdl4jDefinition. * @@ -54,7 +60,7 @@ public class Wsdl4jDefinition implements Wsdl11Definition { * @param definition the WSDL4J definition */ public Wsdl4jDefinition(Definition definition) { - this.definition = definition; + setDefinition(definition); } /** Returns the WSDL4J Definition. */ @@ -64,19 +70,26 @@ public class Wsdl4jDefinition implements Wsdl11Definition { /** Set the WSDL4J Definition. */ public void setDefinition(Definition definition) { - this.definition = definition; + synchronized (monitor) { + this.definition = definition; + this.document = null; + } } public Source getSource() { Assert.notNull(definition, "definition must not be null"); - try { - WSDLFactory wsdlFactory = WSDLFactory.newInstance(); - WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter(); - Document document = wsdlWriter.getDocument(definition); - return new DOMSource(document); - } - catch (WSDLException ex) { - throw new WsdlDefinitionException(ex.getMessage(), ex); + synchronized (monitor) { + if (document == null) { + try { + WSDLFactory wsdlFactory = WSDLFactory.newInstance(); + WSDLWriter wsdlWriter = wsdlFactory.newWSDLWriter(); + document = wsdlWriter.getDocument(definition); + } + catch (WSDLException ex) { + throw new WsdlDefinitionException(ex.getMessage(), ex); + } + } } + return new DOMSource(document); } }