You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by as...@apache.org on 2011/08/04 11:16:43 UTC
svn commit: r1153802 - in /cxf/branches/2.4.x-fixes: ./
common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
Author: asoldano
Date: Thu Aug 4 09:16:42 2011
New Revision: 1153802
URL: http://svn.apache.org/viewvc?rev=1153802&view=rev
Log:
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.4.x-fixes/ (props changed)
cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Aug 4 09:16:42 2011
@@ -1 +1 @@
-/cxf/trunk:1153781
+/cxf/trunk:1153781,1153796
Propchange: cxf/branches/2.4.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Modified: cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java?rev=1153802&r1=1153801&r2=1153802&view=diff
==============================================================================
--- cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java (original)
+++ cxf/branches/2.4.x-fixes/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java Thu Aug 4 09:16:42 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);
}