Return-Path: X-Original-To: apmail-cxf-commits-archive@www.apache.org Delivered-To: apmail-cxf-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 771A868CC for ; Thu, 4 Aug 2011 09:11:00 +0000 (UTC) Received: (qmail 19088 invoked by uid 500); 4 Aug 2011 09:10:49 -0000 Delivered-To: apmail-cxf-commits-archive@cxf.apache.org Received: (qmail 16507 invoked by uid 500); 4 Aug 2011 09:10:14 -0000 Mailing-List: contact commits-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list commits@cxf.apache.org Received: (qmail 15756 invoked by uid 99); 4 Aug 2011 09:09:48 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Aug 2011 09:09:48 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 04 Aug 2011 09:09:46 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 383B72388901 for ; Thu, 4 Aug 2011 09:09:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1153796 - /cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java Date: Thu, 04 Aug 2011 09:09:26 -0000 To: commits@cxf.apache.org From: asoldano@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110804090926.383B72388901@eris.apache.org> Author: asoldano Date: Thu Aug 4 09:09:25 2011 New Revision: 1153796 URL: http://svn.apache.org/viewvc?rev=1153796&view=rev Log: [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/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java Modified: cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java URL: http://svn.apache.org/viewvc/cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java?rev=1153796&r1=1153795&r2=1153796&view=diff ============================================================================== --- cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java (original) +++ cxf/trunk/common/common/src/main/java/org/apache/cxf/helpers/DOMUtils.java Thu Aug 4 09:09:25 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 DOCUMENT_BUILDERS = Collections + .synchronizedMap(new WeakHashMap()); + 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); }