< prev index next >

src/java.xml/share/classes/com/sun/org/apache/xml/internal/dtm/ref/DTMManagerDefault.java

Print this page
rev 1063 : 8172974: [JAXP] XALAN: Wrong result when transforming namespace unaware StAX Input

@@ -1,56 +1,54 @@
 /*
- * reserved comment block
- * DO NOT REMOVE OR ALTER!
+ * Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
  */
 /*
- * Copyright 1999-2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-/*
- * $Id: DTMManagerDefault.java,v 1.2.4.1 2005/09/15 08:15:02 suresh_emailid Exp $
- */
+
 package com.sun.org.apache.xml.internal.dtm.ref;
 
 import com.sun.org.apache.xalan.internal.utils.FactoryImpl;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.transform.Source;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.sax.SAXSource;
-import javax.xml.transform.stream.StreamSource;
-
 import com.sun.org.apache.xml.internal.dtm.DTM;
 import com.sun.org.apache.xml.internal.dtm.DTMException;
 import com.sun.org.apache.xml.internal.dtm.DTMFilter;
 import com.sun.org.apache.xml.internal.dtm.DTMIterator;
 import com.sun.org.apache.xml.internal.dtm.DTMManager;
 import com.sun.org.apache.xml.internal.dtm.DTMWSFilter;
 import com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTM;
+import com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode;
 import com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2DTM;
 import com.sun.org.apache.xml.internal.dtm.ref.sax2dtm.SAX2RTFDTM;
 import com.sun.org.apache.xml.internal.res.XMLErrorResources;
 import com.sun.org.apache.xml.internal.res.XMLMessages;
 import com.sun.org.apache.xml.internal.utils.PrefixResolver;
 import com.sun.org.apache.xml.internal.utils.SystemIDResolver;
+import com.sun.org.apache.xml.internal.utils.WrappedRuntimeException;
 import com.sun.org.apache.xml.internal.utils.XMLReaderManager;
 import com.sun.org.apache.xml.internal.utils.XMLStringFactory;
-
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.Source;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.transform.sax.SAXSource;
+import javax.xml.transform.stream.StreamSource;
+import jdk.xml.internal.JdkXmlUtils;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
-
 import org.xml.sax.InputSource;
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXNotRecognizedException;
 import org.xml.sax.SAXNotSupportedException;
 import org.xml.sax.XMLReader;

@@ -71,19 +69,11 @@
  * process that queue on an infrequent basis during main-thread
  * activity (eg, when getDTM() is invoked). The downside of that solution
  * would be a greater delay before the DTM's storage is actually released
  * for reuse.
  * */
-public class DTMManagerDefault extends DTMManager
-{
-  //static final boolean JKESS_XNI_EXPERIMENT=true;
-
-  /** Set this to true if you want a dump of the DTM after creation. */
-  private static final boolean DUMPTREE = false;
-
-  /** Set this to true if you want a basic diagnostics. */
-  private static final boolean DEBUG = false;
+public class DTMManagerDefault extends DTMManager {
 
   /**
    * Map from DTM identifier numbers to DTM objects that this manager manages.
    * One DTM may have several prefix numbers, if extended node indexing
    * is in use; in that case, m_dtm_offsets[] will used to control which

@@ -128,12 +118,13 @@
    * be used if you want to add "extended" DTM IDs with nonzero offsets.
    *
    * @param dtm Should be a valid reference to a DTM.
    * @param id Integer DTM ID to be bound to this DTM
    */
-  synchronized public void addDTM(DTM dtm, int id) {    addDTM(dtm,id,0); }
-
+  synchronized public void addDTM(DTM dtm, int id) {
+    addDTM(dtm,id,0);
+  }
 
   /**
    * Add a DTM to the DTM table.
    *
    * @param dtm Should be a valid reference to a DTM.

@@ -141,76 +132,67 @@
    * @param offset Integer addressing offset. The internal DTM Node ID is
    * obtained by adding this offset to the node-number field of the
    * public DTM Handle. For the first DTM ID accessing each DTM, this is 0;
    * for overflow addressing it will be a multiple of 1<<IDENT_DTM_NODE_BITS.
    */
-  synchronized public void addDTM(DTM dtm, int id, int offset)
-  {
-                if(id>=IDENT_MAX_DTMS)
-                {
-                        // TODO: %REVIEW% Not really the right error message.
-            throw new DTMException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_DTMIDS_AVAIL, null)); //"No more DTM IDs are available!");
-                }
-
-                // We used to just allocate the array size to IDENT_MAX_DTMS.
-                // But we expect to increase that to 16 bits, and I'm not willing
-                // to allocate that much space unless needed. We could use one of our
-                // handy-dandy Fast*Vectors, but this will do for now.
-                // %REVIEW%
-                int oldlen=m_dtms.length;
-                if(oldlen<=id)
-                {
-                        // Various growth strategies are possible. I think we don't want
-                        // to over-allocate excessively, and I'm willing to reallocate
-                        // more often to get that. See also Fast*Vector classes.
-                        //
-                        // %REVIEW% Should throw a more diagnostic error if we go over the max...
-                        int newlen=Math.min((id+256),IDENT_MAX_DTMS);
-
-                        DTM new_m_dtms[] = new DTM[newlen];
-                        System.arraycopy(m_dtms,0,new_m_dtms,0,oldlen);
-                        m_dtms=new_m_dtms;
-                        int new_m_dtm_offsets[] = new int[newlen];
-                        System.arraycopy(m_dtm_offsets,0,new_m_dtm_offsets,0,oldlen);
-                        m_dtm_offsets=new_m_dtm_offsets;
-                }
+  synchronized public void addDTM(DTM dtm, int id, int offset) {
+    if (id >= IDENT_MAX_DTMS) {
+      // TODO: %REVIEW% Not really the right error message.
+      throw new DTMException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NO_DTMIDS_AVAIL, null)); //"No more DTM IDs are available!");
+    }
+
+    // We used to just allocate the array size to IDENT_MAX_DTMS.
+    // But we expect to increase that to 16 bits, and I'm not willing
+    // to allocate that much space unless needed. We could use one of our
+    // handy-dandy Fast*Vectors, but this will do for now.
+    // %REVIEW%
+    int oldlen = m_dtms.length;
+    if(oldlen <= id) {
+      // Various growth strategies are possible. I think we don't want
+      // to over-allocate excessively, and I'm willing to reallocate
+      // more often to get that. See also Fast*Vector classes.
+      //
+      // %REVIEW% Should throw a more diagnostic error if we go over the max...
+      int newlen = Math.min((id+256),IDENT_MAX_DTMS);
+      DTM new_m_dtms[] = new DTM[newlen];
+      System.arraycopy(m_dtms,0,new_m_dtms,0,oldlen);
+      m_dtms=new_m_dtms;
+      int new_m_dtm_offsets[] = new int[newlen];
+      System.arraycopy(m_dtm_offsets,0,new_m_dtm_offsets,0,oldlen);
+      m_dtm_offsets=new_m_dtm_offsets;
+    }
 
     m_dtms[id] = dtm;
-                m_dtm_offsets[id]=offset;
+    m_dtm_offsets[id]=offset;
     dtm.documentRegistration();
-                // The DTM should have been told who its manager was when we created it.
-                // Do we need to allow for adopting DTMs _not_ created by this manager?
+    // The DTM should have been told who its manager was when we created it.
+    // Do we need to allow for adopting DTMs _not_ created by this manager?
   }
 
   /**
    * Get the first free DTM ID available. %OPT% Linear search is inefficient!
    */
-  synchronized public int getFirstFreeDTMID()
-  {
+  synchronized public int getFirstFreeDTMID() {
     int n = m_dtms.length;
-    for (int i = 1; i < n; i++)
-    {
-      if(null == m_dtms[i])
-      {
+    for (int i = 1; i < n; i++) {
+      if(null == m_dtms[i]) {
         return i;
       }
     }
-                return n; // count on addDTM() to throw exception if out of range
+    return n; // count on addDTM() to throw exception if out of range
   }
 
   /**
    * The default table for exandedNameID lookups.
    */
-  private ExpandedNameTable m_expandedNameTable =
-    new ExpandedNameTable();
+  private ExpandedNameTable m_expandedNameTable = new ExpandedNameTable();
 
   /**
    * Constructor DTMManagerDefault
    *
    */
-  public DTMManagerDefault(){}
-
+  public DTMManagerDefault() {}
 
   /**
    * Get an instance of a DTM, loaded with the content from the
    * specified source.  If the unique flag is true, a new instance will
    * always be returned.  Otherwise it is up to the DTMManager to return a

@@ -238,41 +220,36 @@
    */
   synchronized public DTM getDTM(Source source, boolean unique,
                                  DTMWSFilter whiteSpaceFilter,
                                  boolean incremental, boolean doIndexing)
   {
-
-    if(DEBUG && null != source)
-      System.out.println("Starting "+
-                         (unique ? "UNIQUE" : "shared")+
-                         " source: "+source.getSystemId()
-                         );
+    /* Uncomment for debugging
+    if (null != source) {
+      System.out.println("Starting " +
+                         (unique ? "UNIQUE" : "shared") +
+                         " source: " + source.getSystemId());
+    }
+    */
 
     XMLStringFactory xstringFactory = m_xsf;
     int dtmPos = getFirstFreeDTMID();
     int documentID = dtmPos << IDENT_DTM_NODE_BITS;
 
-    if ((null != source) && source instanceof DOMSource)
-    {
+    if ((null != source) && source instanceof DOMSource) {
       DOM2DTM dtm = new DOM2DTM(this, (DOMSource) source, documentID,
                                 whiteSpaceFilter, xstringFactory, doIndexing);
 
       addDTM(dtm, dtmPos, 0);
 
-      //      if (DUMPTREE)
-      //      {
-      //        dtm.dumpDTM();
-      //      }
+      /* Uncomment for debugging
+      dtm.dumpDTM();
+      */
 
       return dtm;
-    }
-    else
-    {
-      boolean isSAXSource = (null != source)
-        ? (source instanceof SAXSource) : true;
-      boolean isStreamSource = (null != source)
-        ? (source instanceof StreamSource) : false;
+    } else {
+      boolean isSAXSource = (null != source) ? (source instanceof SAXSource) : true;
+      boolean isStreamSource = (null != source) ? (source instanceof StreamSource) : false;
 
       if (isSAXSource || isStreamSource) {
         XMLReader reader = null;
         SAX2DTM dtm;
 

@@ -307,50 +284,40 @@
             //
             // %REVIEW% This is a sloppy way to request this mode;
             // we need to consider architectural improvements.
             dtm = new SAX2RTFDTM(this, source, documentID, whiteSpaceFilter,
                                  xstringFactory, doIndexing);
-          }
-          /**************************************************************
-          // EXPERIMENTAL 3/22/02
-          else if(JKESS_XNI_EXPERIMENT && m_incremental) {
-            dtm = new XNI2DTM(this, source, documentID, whiteSpaceFilter,
-                              xstringFactory, doIndexing);
-          }
-          **************************************************************/
-          // Create the basic SAX2DTM.
-          else {
+          } else {
+            // Create the basic SAX2DTM.
             dtm = new SAX2DTM(this, source, documentID, whiteSpaceFilter,
                               xstringFactory, doIndexing);
           }
 
           // Go ahead and add the DTM to the lookup table.  This needs to be
           // done before any parsing occurs. Note offset 0, since we've just
           // created a new DTM.
           addDTM(dtm, dtmPos, 0);
 
-
           boolean haveXercesParser =
                      (null != reader)
                      && (reader.getClass()
                                .getName()
-                               .equals("com.sun.org.apache.xerces.internal.parsers.SAXParser") );
+                               .equals("com.sun.org.apache.xerces.internal.parsers.SAXParser"));
 
           if (haveXercesParser) {
             incremental = true;  // No matter what.  %REVIEW%
           }
 
           // If the reader is null, but they still requested an incremental
           // build, then we still want to set up the IncrementalSAXSource stuff.
-          if (m_incremental && incremental
-               /* || ((null == reader) && incremental) */) {
+          if (m_incremental && incremental) {
             IncrementalSAXSource coParser=null;
 
             if (haveXercesParser) {
               // IncrementalSAXSource_Xerces to avoid threading.
               try {
-                coParser = new com.sun.org.apache.xml.internal.dtm.ref.IncrementalSAXSource_Xerces();
+                coParser = new IncrementalSAXSource_Xerces();
               }  catch( Exception ex ) {
                 ex.printStackTrace();
                 coParser=null;
               }
             }

@@ -365,34 +332,14 @@
                 filter.setXMLReader(reader);
                 coParser=filter;
               }
             }
 
-
-            /**************************************************************
-            // EXPERIMENTAL 3/22/02
-            if (JKESS_XNI_EXPERIMENT && m_incremental &&
-                  dtm instanceof XNI2DTM &&
-                  coParser instanceof IncrementalSAXSource_Xerces) {
-                com.sun.org.apache.xerces.internal.xni.parser.XMLPullParserConfiguration xpc=
-                      ((IncrementalSAXSource_Xerces)coParser)
-                                           .getXNIParserConfiguration();
-              if (xpc!=null) {
-                // Bypass SAX; listen to the XNI stream
-                ((XNI2DTM)dtm).setIncrementalXNISource(xpc);
-              } else {
-                  // Listen to the SAX stream (will fail, diagnostically...)
-                dtm.setIncrementalSAXSource(coParser);
-              }
-            } else
-            ***************************************************************/
-
             // Have the DTM set itself up as IncrementalSAXSource's listener.
             dtm.setIncrementalSAXSource(coParser);
 
             if (null == xmlSource) {
-
               // Then the user will construct it themselves.
               return dtm;
             }
 
             if (null == reader.getErrorHandler()) {

@@ -404,23 +351,18 @@
               // Launch parsing coroutine.  Launches a second thread,
               // if we're using IncrementalSAXSource.filter().
 
               coParser.startParse(xmlSource);
             } catch (RuntimeException re) {
-
               dtm.clearCoRoutine();
-
               throw re;
             } catch (Exception e) {
-
               dtm.clearCoRoutine();
-
-              throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
+              throw new WrappedRuntimeException(e);
             }
           } else {
             if (null == reader) {
-
               // Then the user will construct it themselves.
               return dtm;
             }
 
             // not incremental

@@ -428,34 +370,28 @@
             reader.setDTDHandler(dtm);
             if (null == reader.getErrorHandler()) {
               reader.setErrorHandler(dtm);
             }
 
-            try {
-              reader.setProperty(
-                               "http://xml.org/sax/properties/lexical-handler",
-                               dtm);
-            } catch (SAXNotRecognizedException e){}
-              catch (SAXNotSupportedException e){}
+            JdkXmlUtils.setXMLReaderPropertyIfSupport(reader,
+                "http://xml.org/sax/properties/lexical-handler", dtm, false);
 
             try {
               reader.parse(xmlSource);
             } catch (RuntimeException re) {
               dtm.clearCoRoutine();
-
               throw re;
             } catch (Exception e) {
               dtm.clearCoRoutine();
-
-              throw new com.sun.org.apache.xml.internal.utils.WrappedRuntimeException(e);
+              throw new WrappedRuntimeException(e);
             }
           }
 
-          if (DUMPTREE) {
-            System.out.println("Dumping SAX2DOM");
-            dtm.dumpDTM(System.err);
-          }
+          /* Uncomment for debugging
+          System.out.println("Dumping SAX2DOM");
+          dtm.dumpDTM(System.err);
+          */
 
           return dtm;
         } finally {
           // Reset the ContentHandler, DTDHandler, ErrorHandler to the DefaultHandler
           // after creating the DTM.

@@ -471,11 +407,10 @@
             catch (Exception e) {}
           }
           releaseXMLReader(reader);
         }
       } else {
-
         // It should have been handled by a derived class or the caller
         // made a mistake.
         throw new DTMException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NOT_SUPPORTED, new Object[]{source})); //"Not supported: " + source);
       }
     }

@@ -488,20 +423,19 @@
    *
    * @param node Non-null reference to a DOM node.
    *
    * @return a valid DTM handle.
    */
-  synchronized public int getDTMHandleFromNode(org.w3c.dom.Node node)
+  synchronized public int getDTMHandleFromNode(Node node)
   {
-    if(null == node)
+    if (node == null) {
       throw new IllegalArgumentException(XMLMessages.createXMLMessage(XMLErrorResources.ER_NODE_NON_NULL, null)); //"node must be non-null for getDTMHandleFromNode!");
+    }
 
-    if (node instanceof com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy)
-      return ((com.sun.org.apache.xml.internal.dtm.ref.DTMNodeProxy) node).getDTMNodeNumber();
-
-    else
-    {
+    if (node instanceof DTMNodeProxy) {
+      return ((DTMNodeProxy)node).getDTMNodeNumber();
+    } else {
       // Find the DOM2DTMs wrapped around this Document (if any)
       // and check whether they contain the Node in question.
       //
       // NOTE that since a DOM2DTM may represent a subtree rather
       // than a full document, we have to be prepared to check more

@@ -512,72 +446,70 @@
       // %REVIEW% We could search for the one which contains this
       // node at the deepest level, and thus covers the widest
       // subtree, but that's going to entail additional work
       // checking more DTMs... and getHandleOfNode is not a
       // cheap operation in most implementations.
-                        //
-                        // TODO: %REVIEW% If overflow addressing, we may recheck a DTM
-                        // already examined. Ouch. But with the increased number of DTMs,
-                        // scanning back to check this is painful.
-                        // POSSIBLE SOLUTIONS:
-                        //   Generate a list of _unique_ DTM objects?
-                        //   Have each DTM cache last DOM node search?
-                        int max = m_dtms.length;
-      for(int i = 0; i < max; i++)
-        {
-          DTM thisDTM=m_dtms[i];
-          if((null != thisDTM) && thisDTM instanceof DOM2DTM)
-          {
-            int handle=((DOM2DTM)thisDTM).getHandleOfNode(node);
-            if(handle!=DTM.NULL) return handle;
+      //
+      // TODO: %REVIEW% If overflow addressing, we may recheck a DTM
+      // already examined. Ouch. But with the increased number of DTMs,
+      // scanning back to check this is painful.
+      // POSSIBLE SOLUTIONS:
+      //   Generate a list of _unique_ DTM objects?
+      //   Have each DTM cache last DOM node search?
+      int max = m_dtms.length;
+      for (int i = 0; i < max; i++) {
+        DTM thisDTM = m_dtms[i];
+        if ((null != thisDTM) && thisDTM instanceof DOM2DTM) {
+          int handle=((DOM2DTM)thisDTM).getHandleOfNode(node);
+          if (handle!=DTM.NULL) {
+            return handle;
           }
-         }
+        }
+      }
 
-                        // Not found; generate a new DTM.
-                        //
-                        // %REVIEW% Is this really desirable, or should we return null
-                        // and make folks explicitly instantiate from a DOMSource? The
-                        // latter is more work but gives the caller the opportunity to
-                        // explicitly add the DTM to a DTMManager... and thus to know when
-                        // it can be discarded again, which is something we need to pay much
-                        // more attention to. (Especially since only DTMs which are assigned
-                        // to a manager can use the overflow addressing scheme.)
-                        //
-                        // %BUG% If the source node was a DOM2DTM$defaultNamespaceDeclarationNode
-                        // and the DTM wasn't registered with this DTMManager, we will create
-                        // a new DTM and _still_ not be able to find the node (since it will
-                        // be resynthesized). Another reason to push hard on making all DTMs
-                        // be managed DTMs.
+      // Not found; generate a new DTM.
+      //
+      // %REVIEW% Is this really desirable, or should we return null
+      // and make folks explicitly instantiate from a DOMSource? The
+      // latter is more work but gives the caller the opportunity to
+      // explicitly add the DTM to a DTMManager... and thus to know when
+      // it can be discarded again, which is something we need to pay much
+      // more attention to. (Especially since only DTMs which are assigned
+      // to a manager can use the overflow addressing scheme.)
+      //
+      // %BUG% If the source node was a DOM2DTM$defaultNamespaceDeclarationNode
+      // and the DTM wasn't registered with this DTMManager, we will create
+      // a new DTM and _still_ not be able to find the node (since it will
+      // be resynthesized). Another reason to push hard on making all DTMs
+      // be managed DTMs.
 
-                        // Since the real root of our tree may be a DocumentFragment, we need to
+      // Since the real root of our tree may be a DocumentFragment, we need to
       // use getParent to find the root, instead of getOwnerDocument.  Otherwise
       // DOM2DTM#getHandleOfNode will be very unhappy.
       Node root = node;
       Node p = (root.getNodeType() == Node.ATTRIBUTE_NODE) ? ((org.w3c.dom.Attr)root).getOwnerElement() : root.getParentNode();
-      for (; p != null; p = p.getParentNode())
-      {
+      for (; p != null; p = p.getParentNode()) {
         root = p;
       }
 
-      DOM2DTM dtm = (DOM2DTM) getDTM(new javax.xml.transform.dom.DOMSource(root),
-                                                                                                                                                 false, null, true, true);
+      DOM2DTM dtm = (DOM2DTM) getDTM(new javax.xml.transform.dom.DOMSource(root), false, null, true, true);
 
       int handle;
 
-      if(node instanceof com.sun.org.apache.xml.internal.dtm.ref.dom2dtm.DOM2DTMdefaultNamespaceDeclarationNode)
-      {
-                                // Can't return the same node since it's unique to a specific DTM,
-                                // but can return the equivalent node -- find the corresponding
-                                // Document Element, then ask it for the xml: namespace decl.
-                                handle=dtm.getHandleOfNode(((org.w3c.dom.Attr)node).getOwnerElement());
-                                handle=dtm.getAttributeNode(handle,node.getNamespaceURI(),node.getLocalName());
+      if (node instanceof DOM2DTMdefaultNamespaceDeclarationNode) {
+        // Can't return the same node since it's unique to a specific DTM,
+        // but can return the equivalent node -- find the corresponding
+        // Document Element, then ask it for the xml: namespace decl.
+        handle = dtm.getHandleOfNode(((org.w3c.dom.Attr)node).getOwnerElement());
+        handle = dtm.getAttributeNode(handle, node.getNamespaceURI(), node.getLocalName());
+      } else {
+        handle = ((DOM2DTM)dtm).getHandleOfNode(node);
       }
-      else
-                                handle = ((DOM2DTM)dtm).getHandleOfNode(node);
 
-      if(DTM.NULL == handle)
+      if (DTM.NULL == handle) {
         throw new RuntimeException(XMLMessages.createXMLMessage(XMLErrorResources.ER_COULD_NOT_RESOLVE_NODE, null)); //"Could not resolve the node to a handle!");
+      }
 
       return handle;
     }
   }
 

@@ -593,15 +525,12 @@
    * @param inputSource The value returned from the URIResolver.
    * @return  a SAX2 XMLReader to use to resolve the inputSource argument.
    *
    * @return non-null XMLReader reference ready to parse.
    */
-  synchronized public XMLReader getXMLReader(Source inputSource)
-  {
-
-    try
-    {
+  synchronized public XMLReader getXMLReader(Source inputSource) {
+    try {
       XMLReader reader = (inputSource instanceof SAXSource)
                          ? ((SAXSource) inputSource).getXMLReader() : null;
 
       // If user did not supply a reader, ask for one from the reader manager
       if (null == reader) {

@@ -611,11 +540,10 @@
 
         reader = m_readerManager.getXMLReader();
       }
 
       return reader;
-
     } catch (SAXException se) {
       throw new DTMException(se.getMessage(), se);
     }
   }
 

@@ -640,23 +568,19 @@
    *
    * @param nodeHandle DTM Handle indicating which node to retrieve
    *
    * @return a reference to the DTM object containing this node.
    */
-  synchronized public DTM getDTM(int nodeHandle)
-  {
-    try
-    {
+  synchronized public DTM getDTM(int nodeHandle) {
+    try {
       // Performance critical function.
       return m_dtms[nodeHandle >>> IDENT_DTM_NODE_BITS];
-    }
-    catch(java.lang.ArrayIndexOutOfBoundsException e)
-    {
-      if(nodeHandle==DTM.NULL)
-                                return null;            // Accept as a special case.
+    } catch(java.lang.ArrayIndexOutOfBoundsException e) {
+      if (nodeHandle==DTM.NULL)
+        return null;            // Accept as a special case.
       else
-                                throw e;                // Programming error; want to know about it.
+        throw e;                // Programming error; want to know about it.
     }
   }
 
   /**
    * Given a DTM, find the ID number in the DTM tables which addresses

@@ -666,27 +590,24 @@
    * @param dtm The DTM which (hopefully) contains this node.
    *
    * @return The DTM ID (as the high bits of a NodeHandle, not as our
    * internal index), or -1 if the DTM doesn't belong to this manager.
    */
-  synchronized public int getDTMIdentity(DTM dtm)
-  {
-        // Shortcut using DTMDefaultBase's extension hooks
-        // %REVIEW% Should the lookup be part of the basic DTM API?
-        if(dtm instanceof DTMDefaultBase)
-        {
-                DTMDefaultBase dtmdb=(DTMDefaultBase)dtm;
-                if(dtmdb.getManager()==this)
-                        return dtmdb.getDTMIDs().elementAt(0);
-                else
-                        return -1;
-        }
+  synchronized public int getDTMIdentity(DTM dtm) {
+    // Shortcut using DTMDefaultBase's extension hooks
+    // %REVIEW% Should the lookup be part of the basic DTM API?
+    if (dtm instanceof DTMDefaultBase) {
+      DTMDefaultBase dtmdb = (DTMDefaultBase)dtm;
+      if (dtmdb.getManager() == this)
+        return dtmdb.getDTMIDs().elementAt(0);
+      else
+        return -1;
+    }
 
     int n = m_dtms.length;
 
-    for (int i = 0; i < n; i++)
-    {
+    for (int i = 0; i < n; i++) {
       DTM tdtm = m_dtms[i];
 
       if (tdtm == dtm && m_dtm_offsets[i]==0)
         return i << IDENT_DTM_NODE_BITS;
     }

@@ -707,50 +628,43 @@
    * in this version of the DTM manager.
    *
    * @return true if the DTM was released, false if shouldHardDelete was set
    * and we decided not to.
    */
-  synchronized public boolean release(DTM dtm, boolean shouldHardDelete)
-  {
-    if(DEBUG)
-    {
-      System.out.println("Releasing "+
-                         (shouldHardDelete ? "HARD" : "soft")+
-                         " dtm="+
-                         // Following shouldn't need a nodeHandle, but does...
-                         // and doesn't seem to report the intended value
-                         dtm.getDocumentBaseURI()
-                         );
-    }
-
-    if (dtm instanceof SAX2DTM)
-    {
-      ((SAX2DTM) dtm).clearCoRoutine();
-    }
-
-                // Multiple DTM IDs may be assigned to a single DTM.
-                // The Right Answer is to ask which (if it supports
-                // extension, the DTM will need a list anyway). The
-                // Wrong Answer, applied if the DTM can't help us,
-                // is to linearly search them all; this may be very
-                // painful.
-                //
-                // %REVIEW% Should the lookup move up into the basic DTM API?
-                if(dtm instanceof DTMDefaultBase)
-                {
-                        com.sun.org.apache.xml.internal.utils.SuballocatedIntVector ids=((DTMDefaultBase)dtm).getDTMIDs();
-                        for(int i=ids.size()-1;i>=0;--i)
-                                m_dtms[ids.elementAt(i)>>>DTMManager.IDENT_DTM_NODE_BITS]=null;
-                }
-                else
-                {
-                        int i = getDTMIdentity(dtm);
-                    if (i >= 0)
-                        {
-                                m_dtms[i >>> DTMManager.IDENT_DTM_NODE_BITS] = null;
-                        }
-                }
+  synchronized public boolean release(DTM dtm, boolean shouldHardDelete) {
+    /* Uncomment for debugging
+    System.out.println("Releasing "+
+                       (shouldHardDelete ? "HARD" : "soft") +
+                       " dtm=" +
+                       // Following shouldn't need a nodeHandle, but does...
+                       // and doesn't seem to report the intended value
+                       dtm.getDocumentBaseURI());
+    */
+
+    if (dtm instanceof SAX2DTM) {
+      ((SAX2DTM)dtm).clearCoRoutine();
+    }
+
+    // Multiple DTM IDs may be assigned to a single DTM.
+    // The Right Answer is to ask which (if it supports
+    // extension, the DTM will need a list anyway). The
+    // Wrong Answer, applied if the DTM can't help us,
+    // is to linearly search them all; this may be very
+    // painful.
+    //
+    // %REVIEW% Should the lookup move up into the basic DTM API?
+    if (dtm instanceof DTMDefaultBase) {
+      com.sun.org.apache.xml.internal.utils.SuballocatedIntVector ids=((DTMDefaultBase)dtm).getDTMIDs();
+      for (int i=ids.size() - 1; i >= 0; --i) {
+        m_dtms[ids.elementAt(i)>>>DTMManager.IDENT_DTM_NODE_BITS] = null;
+      }
+    } else {
+      int i = getDTMIdentity(dtm);
+      if (i >= 0) {
+        m_dtms[i >>> DTMManager.IDENT_DTM_NODE_BITS] = null;
+      }
+    }
 
     dtm.documentRelease();
     return true;
   }
 

@@ -758,26 +672,21 @@
    * Method createDocumentFragment
    *
    *
    * NEEDSDOC (createDocumentFragment) @return
    */
-  synchronized public DTM createDocumentFragment()
-  {
-
-    try
-    {
+  synchronized public DTM createDocumentFragment() {
+    try {
       DocumentBuilderFactory dbf = FactoryImpl.getDOMFactory(super.useServicesMechnism());
       dbf.setNamespaceAware(true);
 
       DocumentBuilder db = dbf.newDocumentBuilder();
       Document doc = db.newDocument();
       Node df = doc.createDocumentFragment();
 
       return getDTM(new DOMSource(df), true, null, false, false);
-    }
-    catch (Exception e)
-    {
+    } catch (Exception e) {
       throw new DTMException(e);
     }
   }
 
   /**

@@ -789,13 +698,11 @@
    * NEEDSDOC @param entityReferenceExpansion
    *
    * NEEDSDOC (createDTMIterator) @return
    */
   synchronized public DTMIterator createDTMIterator(int whatToShow, DTMFilter filter,
-                                       boolean entityReferenceExpansion)
-  {
-
+                                       boolean entityReferenceExpansion) {
     /** @todo: implement this com.sun.org.apache.xml.internal.dtm.DTMManager abstract method */
     return null;
   }
 
   /**

@@ -806,13 +713,11 @@
    * NEEDSDOC @param presolver
    *
    * NEEDSDOC (createDTMIterator) @return
    */
   synchronized public DTMIterator createDTMIterator(String xpathString,
-                                       PrefixResolver presolver)
-  {
-
+                                       PrefixResolver presolver) {
     /** @todo: implement this com.sun.org.apache.xml.internal.dtm.DTMManager abstract method */
     return null;
   }
 
   /**

@@ -821,13 +726,11 @@
    *
    * NEEDSDOC @param node
    *
    * NEEDSDOC (createDTMIterator) @return
    */
-  synchronized public DTMIterator createDTMIterator(int node)
-  {
-
+  synchronized public DTMIterator createDTMIterator(int node) {
     /** @todo: implement this com.sun.org.apache.xml.internal.dtm.DTMManager abstract method */
     return null;
   }
 
   /**

@@ -837,13 +740,11 @@
    * NEEDSDOC @param xpathCompiler
    * NEEDSDOC @param pos
    *
    * NEEDSDOC (createDTMIterator) @return
    */
-  synchronized public DTMIterator createDTMIterator(Object xpathCompiler, int pos)
-  {
-
+  synchronized public DTMIterator createDTMIterator(Object xpathCompiler, int pos) {
     /** @todo: implement this com.sun.org.apache.xml.internal.dtm.DTMManager abstract method */
     return null;
   }
 
   /**

@@ -851,10 +752,9 @@
    *
    * NEEDSDOC @param dtm
    *
    * NEEDSDOC ($objectName$) @return
    */
-  public ExpandedNameTable getExpandedNameTable(DTM dtm)
-  {
+  public ExpandedNameTable getExpandedNameTable(DTM dtm) {
     return m_expandedNameTable;
   }
 }
< prev index next >