changeset 612:8bbd7289b29d icedtea-2.3.13

8027201: Enhance JAX-P set up Reviewed-by: alanb, dfuchs, lancea, hawtin
author joehw
date Thu, 14 Nov 2013 09:47:24 -0800
parents 29ea19c7c204
children 691a5e0c657f
files src/com/sun/org/apache/xalan/internal/lib/ExsltStrings.java src/com/sun/org/apache/xalan/internal/lib/Extensions.java
diffstat 2 files changed, 37 insertions(+), 82 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/sun/org/apache/xalan/internal/lib/ExsltStrings.java	Tue Oct 22 12:59:33 2013 -0700
+++ b/src/com/sun/org/apache/xalan/internal/lib/ExsltStrings.java	Thu Nov 14 09:47:24 2013 -0800
@@ -227,7 +227,7 @@
         token = str.substring(fromIndex);
       }
 
-      Document doc = DocumentHolder.m_doc;
+      Document doc = getDocument();
       synchronized (doc)
       {
         Element element = doc.createElement("token");
@@ -291,7 +291,7 @@
     {
       StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
 
-      Document doc = DocumentHolder.m_doc;
+      Document doc = getDocument();
       synchronized (doc)
       {
         while (lTokenizer.hasMoreTokens())
@@ -307,7 +307,7 @@
     else
     {
 
-      Document doc = DocumentHolder.m_doc;
+      Document doc = getDocument();
       synchronized (doc)
       {
         for (int i = 0; i < toTokenize.length(); i++)
@@ -329,35 +329,23 @@
   {
     return tokenize(toTokenize, " \t\n\r");
   }
+
     /**
-     * This class is not loaded until first referenced (see Java Language
-     * Specification by Gosling/Joy/Steele, section 12.4.1)
-     *
-     * The static members are created when this class is first referenced, as a
-     * lazy initialization not needing checking against null or any
-     * synchronization.
-     *
+   * @return an instance of DOM Document
      */
-    private static class DocumentHolder
-    {
-        // Reuse the Document object to reduce memory usage.
-        private static final Document m_doc;
-        static {
-            try
-            {
-                if (System.getSecurityManager() == null) {
-                    m_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-                } else {
-                    m_doc = DocumentBuilderFactory.newInstance(JDK_DEFAULT_DOM, null).newDocumentBuilder().newDocument();
-                }
+   private static Document getDocument()
+   {
+        try
+        {
+            if (System.getSecurityManager() == null) {
+                return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+            } else {
+                return DocumentBuilderFactory.newInstance(JDK_DEFAULT_DOM, null).newDocumentBuilder().newDocument();
             }
-
-            catch(ParserConfigurationException pce)
-            {
-                  throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(pce);
-            }
-
+        }
+        catch(ParserConfigurationException pce)
+        {
+            throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(pce);
         }
     }
-
 }
--- a/src/com/sun/org/apache/xalan/internal/lib/Extensions.java	Tue Oct 22 12:59:33 2013 -0700
+++ b/src/com/sun/org/apache/xalan/internal/lib/Extensions.java	Thu Nov 14 09:47:24 2013 -0800
@@ -115,23 +115,14 @@
 
       // This no longer will work right since the DTM.
       // Document myDoc = myProcessor.getContextNode().getOwnerDocument();
-      try
-      {
-        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-        DocumentBuilder db = dbf.newDocumentBuilder();
-        Document myDoc = db.newDocument();
-
-        Text textNode = myDoc.createTextNode(textNodeValue);
-        DocumentFragment docFrag = myDoc.createDocumentFragment();
+      Document myDoc = getDocument();
 
-        docFrag.appendChild(textNode);
+      Text textNode = myDoc.createTextNode(textNodeValue);
+      DocumentFragment docFrag = myDoc.createDocumentFragment();
 
-        return new NodeSet(docFrag);
-      }
-      catch(ParserConfigurationException pce)
-      {
-        throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(pce);
-      }
+      docFrag.appendChild(textNode);
+
+      return new NodeSet(docFrag);
     }
   }
 
@@ -250,8 +241,7 @@
   public static NodeList tokenize(String toTokenize, String delims)
   {
 
-    Document doc = DocumentHolder.m_doc;
-
+    Document doc = getDocument();
 
     StringTokenizer lTokenizer = new StringTokenizer(toTokenize, delims);
     NodeSet resultSet = new NodeSet();
@@ -309,17 +299,7 @@
   public static Node checkEnvironment(ExpressionContext myContext)
   {
 
-    Document factoryDocument;
-    try
-    {
-      DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
-      DocumentBuilder db = dbf.newDocumentBuilder();
-      factoryDocument = db.newDocument();
-    }
-    catch(ParserConfigurationException pce)
-    {
-      throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(pce);
-    }
+    Document factoryDocument = getDocument();
 
     Node resultNode = null;
     try
@@ -392,34 +372,21 @@
   }
 
     /**
-     * This class is not loaded until first referenced (see Java Language
-     * Specification by Gosling/Joy/Steele, section 12.4.1)
-     *
-     * The static members are created when this class is first referenced, as a
-     * lazy initialization not needing checking against null or any
-     * synchronization.
-     *
+   * @return an instance of DOM Document
      */
-    private static class DocumentHolder
-    {
-        // Reuse the Document object to reduce memory usage.
-        private static final Document m_doc;
-        static
+   private static Document getDocument()
+   {
+        try
         {
-            try
-            {
-                if (System.getSecurityManager() == null) {
-                    m_doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
-                } else {
-                    m_doc = DocumentBuilderFactory.newInstance(JDK_DEFAULT_DOM, null).newDocumentBuilder().newDocument();
-                }
+            if (System.getSecurityManager() == null) {
+                return DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
+            } else {
+                return DocumentBuilderFactory.newInstance(JDK_DEFAULT_DOM, null).newDocumentBuilder().newDocument();
             }
-
-            catch(ParserConfigurationException pce)
-            {
-                  throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(pce);
-            }
-
+        }
+        catch(ParserConfigurationException pce)
+        {
+            throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(pce);
         }
     }
 }