cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r639705 - in /incubator/cxf/branches/2.0.x-fixes: ./ rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
Date Fri, 21 Mar 2008 16:37:26 GMT
Author: dkulp
Date: Fri Mar 21 09:37:15 2008
New Revision: 639705

URL: http://svn.apache.org/viewvc?rev=639705&view=rev
Log:
Merged revisions 639341 via svnmerge from 
https://svn.apache.org/repos/asf/incubator/cxf/trunk

........
  r639341 | bimargulies | 2008-03-20 12:15:26 -0400 (Thu, 20 Mar 2008) | 3 lines
  
  Stop making DocumentBuilderFactory and DocumentBuilder objects all the  
  time.
........

Modified:
    incubator/cxf/branches/2.0.x-fixes/   (props changed)
    incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java

Propchange: incubator/cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
URL: http://svn.apache.org/viewvc/incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java?rev=639705&r1=639704&r2=639705&view=diff
==============================================================================
--- incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
(original)
+++ incubator/cxf/branches/2.0.x-fixes/rt/core/src/main/java/org/apache/cxf/bus/spring/TunedDocumentLoader.java
Fri Mar 21 09:37:15 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