cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asold...@apache.org
Subject svn commit: r1153811 - in /cxf/branches/2.3.x-fixes: ./ common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
Date Thu, 04 Aug 2011 09:39:52 GMT
Author: asoldano
Date: Thu Aug  4 09:39:51 2011
New Revision: 1153811

URL: http://svn.apache.org/viewvc?rev=1153811&view=rev
Log:
Merged revisions 1153802 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/branches/2.4.x-fixes

................
  r1153802 | asoldano | 2011-08-04 11:16:42 +0200 (Thu, 04 Aug 2011) | 9 lines
  
  Merged revisions 1153796 via svnmerge from 
  https://svn.apache.org/repos/asf/cxf/trunk
  
  ........
    r1153796 | asoldano | 2011-08-04 11:09:25 +0200 (Thu, 04 Aug 2011) | 2 lines
    
    [CXF-3675] Add a classloader based map of DocumentBuilder instances in DOMUtils to improve
performances when building documents. This also restores the former behaviour, with the DocumentBuilder
being cached in DOMUtils.
  ........
................

Modified:
    cxf/branches/2.3.x-fixes/   (props changed)
    cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java

Propchange: cxf/branches/2.3.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug  4 09:39:51 2011
@@ -1,2 +1,2 @@
-/cxf/branches/2.4.x-fixes:1153362,1153783
-/cxf/trunk:1153258,1153781
+/cxf/branches/2.4.x-fixes:1153362,1153783,1153802
+/cxf/trunk:1153258,1153781,1153796

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

Modified: cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java?rev=1153811&r1=1153810&r2=1153811&view=diff
==============================================================================
--- cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
(original)
+++ cxf/branches/2.3.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
Thu Aug  4 09:39:51 2011
@@ -25,8 +25,11 @@ import java.io.OutputStream;
 import java.io.Reader;
 import java.io.StringReader;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
+import java.util.WeakHashMap;
 
 import javax.xml.XMLConstants;
 import javax.xml.namespace.QName;
@@ -62,9 +65,28 @@ import org.apache.cxf.common.util.String
 public final class DOMUtils {
     private static final String XMLNAMESPACE = "xmlns";
 
+    private static final Map<ClassLoader, DocumentBuilder> DOCUMENT_BUILDERS = Collections
+        .synchronizedMap(new WeakHashMap<ClassLoader, DocumentBuilder>());
+
     private DOMUtils() {
     }
 
+    private static DocumentBuilder getBuilder() throws ParserConfigurationException {
+        ClassLoader loader = Thread.currentThread().getContextClassLoader();
+        if (loader == null) {
+            loader = DOMUtils.class.getClassLoader();
+        }
+        if (loader == null) {
+            return XMLUtils.getParser();
+        }
+        DocumentBuilder builder = DOCUMENT_BUILDERS.get(loader);
+        if (builder == null) {
+            builder = XMLUtils.getParser();
+            DOCUMENT_BUILDERS.put(loader, builder);
+        }
+        return builder;
+    }
+
     /**
      * This function is much like getAttribute, but returns null, not "", for a nonexistent
attribute.
      * 
@@ -484,7 +506,7 @@ public final class DOMUtils {
 
     public static DocumentBuilder createDocumentBuilder() {
         try {
-            return XMLUtils.getParser();
+            return getBuilder();
         } catch (ParserConfigurationException e) {
             throw new RuntimeException("Couldn't find a DOM parser.", e);
         }
@@ -492,7 +514,7 @@ public final class DOMUtils {
 
     public static Document createDocument() {
         try {
-            return XMLUtils.getParser().newDocument();
+            return getBuilder().newDocument();
         } catch (ParserConfigurationException e) {
             throw new RuntimeException("Couldn't find a DOM parser.", e);
         }



Mime
View raw message