You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by bi...@apache.org on 2009/03/30 01:57:54 UTC

svn commit: r759801 - /cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java

Author: bimargulies
Date: Sun Mar 29 23:57:54 2009
New Revision: 759801

URL: http://svn.apache.org/viewvc?rev=759801&view=rev
Log:
Add a soft reference to the DOM, since the WSDL will hang onto it once created.

Modified:
    cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java

Modified: cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java
URL: http://svn.apache.org/viewvc/cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java?rev=759801&r1=759800&r2=759801&view=diff
==============================================================================
--- cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java (original)
+++ cxf/trunk/api/src/main/java/org/apache/cxf/service/model/SchemaInfo.java Sun Mar 29 23:57:54 2009
@@ -19,6 +19,8 @@
 
 package org.apache.cxf.service.model;
 
+import java.lang.ref.SoftReference;
+
 import javax.xml.namespace.QName;
 
 import org.w3c.dom.Attr;
@@ -40,6 +42,9 @@
     private boolean isAttributeQualified;
     private XmlSchema schema;
     private String systemId;
+    // Avoid re-serializing all the time. Particularly as a cached WSDL will
+    // hold a reference to the element.
+    private SoftReference<Element> cachedElement = new SoftReference<Element>(null);
     
     public SchemaInfo(String namespaceUri) {
         this(namespaceUri, false, false);
@@ -70,8 +75,16 @@
         this.namespaceUri = nsUri;
     }
 
+    /**
+     * Build and return a DOM tree for this schema.
+     * @return
+     */
     public synchronized Element getElement() {
-        Element element = null;
+        // if someone recently used this DOM tree, take advantage.
+        Element element = cachedElement.get();
+        if (element != null) {
+            return element;
+        }
         if (getSchema() == null) {
             throw new RuntimeException("No XmlSchma in SchemaInfo");
         }
@@ -94,6 +107,7 @@
                 throw new RuntimeException("Error serializing Xml Schema", e);
             }
             element = serializedSchema.getDocumentElement();
+            cachedElement = new SoftReference<Element>(element);
         }
         // XXX A problem can occur with the ibm jdk when the XmlSchema
         // object is serialized. The xmlns declaration gets incorrectly