servicemix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gno...@apache.org
Subject svn commit: r513670 - in /incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi: servicedesc/EndpointReferenceBuilder.java util/DOMUtil.java
Date Fri, 02 Mar 2007 09:12:09 GMT
Author: gnodet
Date: Fri Mar  2 01:12:08 2007
New Revision: 513670

URL: http://svn.apache.org/viewvc?view=rev&rev=513670
Log:
SM-860: EndpointReferenceBuilder.getReference() should cache its DocumentBuilderFactory instance

Modified:
    incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointReferenceBuilder.java
    incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/DOMUtil.java

Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointReferenceBuilder.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointReferenceBuilder.java?view=diff&rev=513670&r1=513669&r2=513670
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointReferenceBuilder.java
(original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/servicedesc/EndpointReferenceBuilder.java
Fri Mar  2 01:12:08 2007
@@ -17,24 +17,23 @@
 package org.apache.servicemix.jbi.servicedesc;
 
 import javax.jbi.servicedesc.ServiceEndpoint;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.servicemix.jbi.util.DOMUtil;
 import org.w3c.dom.Document;
 import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Element;
 
 public class EndpointReferenceBuilder {
+    private static final Log log = LogFactory.getLog(EndpointReferenceBuilder.class);
 
     public static final String JBI_NAMESPACE = "http://java.sun.com/jbi/end-point-reference";
     public static final String XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
     
     public static DocumentFragment getReference(ServiceEndpoint endpoint) {
         try {
-            DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-            dbf.setNamespaceAware(true);
-            DocumentBuilder db = dbf.newDocumentBuilder();
-            Document doc = db.newDocument();
+            Document doc = DOMUtil.newDocument();
             DocumentFragment fragment = doc.createDocumentFragment();
             Element epr = doc.createElementNS(JBI_NAMESPACE, "jbi:end-point-reference");
             epr.setAttributeNS(XMLNS_NAMESPACE,"xmlns:sns", endpoint.getServiceName().getNamespaceURI());
@@ -43,6 +42,7 @@
             fragment.appendChild(epr);
             return fragment;
         } catch (Exception e) {
+            log.warn("Unable to create reference for ServiceEndpoint " + endpoint, e);
             return null;
         }
     }

Modified: incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/DOMUtil.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/DOMUtil.java?view=diff&rev=513670&r1=513669&r2=513670
==============================================================================
--- incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/DOMUtil.java
(original)
+++ incubator/servicemix/trunk/core/servicemix-core/src/main/java/org/apache/servicemix/jbi/util/DOMUtil.java
Fri Mar  2 01:12:08 2007
@@ -25,7 +25,13 @@
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
+import edu.emory.mathcs.backport.java.util.Queue;
+import edu.emory.mathcs.backport.java.util.concurrent.ConcurrentLinkedQueue;
+
 import javax.xml.namespace.QName;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
 import javax.xml.transform.TransformerException;
@@ -207,5 +213,36 @@
             return new QName(el.getNamespaceURI(), el.getLocalName());
         }
     }
-    
+
+    private static DocumentBuilderFactory dbf = null;
+    private static Queue builders = new ConcurrentLinkedQueue();
+
+    public static DocumentBuilder getBuilder() throws ParserConfigurationException {
+        DocumentBuilder builder = (DocumentBuilder) builders.poll();
+        if (builder == null) {
+            if (dbf == null) {
+                dbf = DocumentBuilderFactory.newInstance();
+                dbf.setNamespaceAware(true);
+            }
+            builder = dbf.newDocumentBuilder();
+        }
+        return builder;
+    }
+
+    public static void releaseBuilder(DocumentBuilder builder) {
+        builders.add(builder);
+    }
+
+    /**
+     * Return a new document, ready to populate.
+     * @return
+     * @throws ParserConfigurationException
+     */
+    public static Document newDocument() throws ParserConfigurationException {
+        DocumentBuilder builder = getBuilder();
+        Document doc = builder.newDocument();
+        releaseBuilder(builder);
+        return doc;
+    }
+
 }



Mime
View raw message