# HG changeset patch # User joehw # Date 1384451244 28800 # Node ID 8bbd7289b29dd7222e6b273272f275316369c7b8 # Parent 29ea19c7c2041fe803e70d8175e2854fa781cbd6 8027201: Enhance JAX-P set up Reviewed-by: alanb, dfuchs, lancea, hawtin diff -r 29ea19c7c204 -r 8bbd7289b29d src/com/sun/org/apache/xalan/internal/lib/ExsltStrings.java --- 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); } } - } diff -r 29ea19c7c204 -r 8bbd7289b29d src/com/sun/org/apache/xalan/internal/lib/Extensions.java --- 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); } } }