cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bimargul...@apache.org
Subject svn commit: r639341 - /incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
Date Thu, 20 Mar 2008 16:15:27 GMT
Author: bimargulies
Date: Thu Mar 20 09:15:26 2008
New Revision: 639341

URL: http://svn.apache.org/viewvc?rev=639341&view=rev
Log:
Stop making DocumentBuilderFactory and DocumentBuilder objects all the  
time.

Modified:
    incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java

Modified: incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java?rev=639341&r1=639340&r2=639341&view=diff
==============================================================================
--- incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
(original)
+++ incubator/cxf/trunk/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
Thu Mar 20 09:15:26 2008
@@ -19,6 +19,7 @@
 
 package org.apache.cxf.bus.spring;
 
+import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParser;
@@ -35,17 +36,26 @@
 
 import com.ctc.wstx.sax.WstxSAXParserFactory;
 
-import org.apache.cxf.helpers.XMLUtils;
 import org.springframework.beans.factory.xml.DefaultDocumentLoader;
 import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
 
-
-
 /**
  * A Spring DocumentLoader that uses WoodStox when we are not validating to speed up the
process. 
  */
 class TunedDocumentLoader extends DefaultDocumentLoader {
     
+    // DocumentBuilderFactories are somewhat expensive but not thread-safe.
+    // We only use this builder with WoodStox, we respect Spring's desire to make new factories

+    // when we aren't doing the optimization.
+    private static DocumentBuilder documentBuilder;
+    static {
+        try {
+            documentBuilder = 
+                DocumentBuilderFactory.newInstance().newDocumentBuilder();
+        } catch (ParserConfigurationException e) {
+            throw new RuntimeException(e);
+        }
+    }
     private TransformerFactory transformerFactory;
     
     TunedDocumentLoader() {
@@ -66,7 +76,11 @@
             reader.setEntityResolver(entityResolver);
             reader.setErrorHandler(errorHandler);
             SAXSource saxSource = new SAXSource(reader, inputSource);
-            Document document = XMLUtils.newDocument();
+            Document document;
+            // collisions are quite unlikely here, but making documentBuilderFactory objects
is expensive.
+            synchronized (documentBuilder) {
+                document = documentBuilder.newDocument();
+            }
             DOMResult domResult = new DOMResult(document, inputSource.getSystemId());
             transformerFactory.newTransformer().transform(saxSource, domResult);
             return document;



Mime
View raw message