jkesselm    2002/12/17 14:20:10

  Modified:    java/src/org/apache/xml/dtm Tag: xslt20 DTM.java
               java/src/org/apache/xml/dtm/dom2dtm2 Tag: xslt20
                        DOM2DTM2Base.java
               java/src/org/apache/xml/dtm/ref Tag: xslt20
                        DTMDefaultBase.java DTMDocumentImpl.java
                        DTMManagerDefault.java
               java/src/org/apache/xml/dtm/ref/dom2dtm Tag: xslt20
                        DOM2DTM.java
  Log:
  Changes to improve our ability to retrieve DTM handles corresponding
  to DOM nodes. I've moved the getDTMHandleFromNode() method
  out of DOM2DTM and up to the DTM API, and I've generalized the
  code in DTMManager that invokes this. (The goal was to
  make that DTMManager call work for both DOM2DTM and DOM2DTM2,
  but this is cleaner than the old approach of an instanceof special
  case.)
  
  This has improved our results against Smoketest -- but DOM2DTM
  apparently still has some holes; it's failing some of the cases in
  ProgrammaticDOMTest and TestXPathAPI. However, it's doing
  better on those than the previous version was (partly due to fixing
  some bad DOM construction in the XPath tests, I must admit), so
  it's a net gain and worth checking in.
  
  We should track down the remaining glitches in that code.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.7.4.1.2.2 +13 -0     xml-xalan/java/src/org/apache/xml/dtm/DTM.java
  
  Index: DTM.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/DTM.java,v
  retrieving revision 1.7.4.1.2.1
  retrieving revision 1.7.4.1.2.2
  diff -u -r1.7.4.1.2.1 -r1.7.4.1.2.2
  --- DTM.java  10 Oct 2002 14:58:33 -0000      1.7.4.1.2.1
  +++ DTM.java  17 Dec 2002 22:20:09 -0000      1.7.4.1.2.2
  @@ -911,6 +911,19 @@
      */
     public org.w3c.dom.Node getNode(int nodeHandle);
   
  +  /**
  +   * Given a W3C DOM node, ask whether this DTM knows of a Node Handle
  +   * associated with it. Generally, returns a valid handle only if the
  +   * Node is actually mapped by this DTM (eg, because it's a DOM2DTM
  +   * which contains that Node).
  +   *
  +   * @param node Non-null reference to a DOM node.
  +   *
  +   * @return a DTM node handle, or DTM.NULL if this DTM doesn't
  +   * recognize the provided DOM node.
  +   */
  +  public int getDTMHandleFromNode(org.w3c.dom.Node node);
  +  
     // ==== Construction methods (may not be supported by some implementations!) =====
     // %REVIEW% What response occurs if not supported?
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.5   +63 -0     
xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/DOM2DTM2Base.java
  
  Index: DOM2DTM2Base.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/dom2dtm2/Attic/DOM2DTM2Base.java,v
  retrieving revision 1.1.2.4
  retrieving revision 1.1.2.5
  diff -u -r1.1.2.4 -r1.1.2.5
  --- DOM2DTM2Base.java 20 Nov 2002 16:04:36 -0000      1.1.2.4
  +++ DOM2DTM2Base.java 17 Dec 2002 22:20:09 -0000      1.1.2.5
  @@ -77,6 +77,7 @@
   import org.apache.xml.dtm.DTMWSFilter;
   import org.apache.xml.dtm.ref.DTMManagerDefault;
   import org.apache.xml.dtm.ref.ExpandedNameTable;
  +import org.apache.xml.dtm.ref.DTMNodeProxy;
   import org.apache.xml.utils.BoolStack;
   import org.apache.xml.utils.FastStringBuffer;
   import org.apache.xml.utils.StringBufferPool;
  @@ -2721,6 +2722,68 @@
       int identity = makeNodeIdentity(nodeHandle);
       return m_resolver.findNode(identity);
     }
  +  
  +  /**
  +   * Given a W3C DOM node, ask whether this DTM knows of a Node Handle
  +   * associated with it. Generally, returns a valid handle only if the
  +   * Node is actually mapped by this DTM (eg, because it's a DOM2DTM
  +   * which contains that Node).
  +   *
  +   * @param node Non-null reference to a DOM node.
  +   *
  +   * @return a DTM node handle, or DTM.NULL if this DTM doesn't
  +   * recognize the provided DOM node.
  +   */
  +  public int getDTMHandleFromNode(org.w3c.dom.Node node)
  +  {
  +     // If it's a DTM simulated node, it may know its handle.
  +     // %OPT% Make these share a common interface so we can test-and-call just once!
  +     if(node instanceof DTMNodeProxy)
  +             return ((DTMNodeProxy)node).getDTMNodeNumber();
  +     else if(node instanceof DOM2DTMdefaultNamespaceDeclarationNode)
  +             return 
((DOM2DTMdefaultNamespaceDeclarationNode)node).getHandleOfNode();
  +     
  +     // Otherwise, see if it's one this DTM covers.
  +     // This would be easier if m_root was always the Document node, but
  +     // we decided to allow wrapping a DTM around a subtree.
  +     // %REVIEW% Is this test adequate? What about disjoint subtrees?
  +    if((m_root==node) ||
  +       (m_root.getNodeType()==DOCUMENT_NODE &&
  +        m_root==node.getOwnerDocument()) ||
  +       (m_root.getNodeType()!=DOCUMENT_NODE &&
  +        m_root.getOwnerDocument()==node.getOwnerDocument())
  +       )
  +    {
  +             int identity=m_resolver.findID(node);
  +             return makeNodeHandle(identity);
  +    }
  +    
  +    return DTM.NULL; // Not ours.        
  +  }
  +  
  +  /**
  +   * Return a DTM handle for the given DOM node, if that can be determined
  +   * by this DTM. If we don't know, we will return NULL.
  +   * 
  +   * Note that in some cases this will be a very slow operation. Also note
  +   * that it may require testing Node identity -- which wasn't standardized
  +   * before DOM Level 3 introduced isSameNode().
  +   *
  +   * @param node The Node reference.
  +   *
  +   * @return the DTM node handle covering this DOM node, or DTM.NULL if
  +   * this DTM instance can not determine that value for this node.
  +   */
  +  public int getDTMHandleFromNode_lightweight(org.w3c.dom.Node node)
  +  {
  +     if(node instanceof DTMNodeProxy)
  +             return ((DTMNodeProxy)node).getDTMNodeNumber();
  +     else if(node instanceof DOM2DTMdefaultNamespaceDeclarationNode)
  +             return 
((DOM2DTMdefaultNamespaceDeclarationNode)node).getHandleOfNode();
  +     else
  +       return makeNodeHandle(m_resolver.findID(node));
  +  }
  +  
   
     // ==== Construction methods (may not be supported by some implementations!) =====
   
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.29.2.1.2.1 +17 -0     xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBase.java
  
  Index: DTMDefaultBase.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDefaultBase.java,v
  retrieving revision 1.29.2.1
  retrieving revision 1.29.2.1.2.1
  diff -u -r1.29.2.1 -r1.29.2.1.2.1
  --- DTMDefaultBase.java       14 Aug 2002 19:45:34 -0000      1.29.2.1
  +++ DTMDefaultBase.java       17 Dec 2002 22:20:09 -0000      1.29.2.1.2.1
  @@ -2020,6 +2020,23 @@
     {
       return new DTMNodeProxy(this, nodeHandle);
     }
  +  
  +  /**
  +   * Given a W3C DOM node, ask whether this DTM knows of a Node Handle
  +   * associated with it. Generally, returns a valid handle only if the
  +   * Node is actually mapped by this DTM (eg, because it's a DOM2DTM
  +   * which contains that Node).
  +   *
  +   * @param node Non-null reference to a DOM node.
  +   *
  +   * @return a DTM node handle, or DTM.NULL if this DTM doesn't
  +   * recognize the provided DOM node.
  +   */
  +  public int getDTMHandleFromNode(org.w3c.dom.Node node)
  +  {
  +     return DTM.NULL; // Most DTMs don't map arbitrary DOM nodes.
  +  }
  +  
   
     // ==== Construction methods (may not be supported by some implementations!) =====
   
  
  
  
  1.7.10.1.2.2 +16 -0     
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDocumentImpl.java
  
  Index: DTMDocumentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMDocumentImpl.java,v
  retrieving revision 1.7.10.1.2.1
  retrieving revision 1.7.10.1.2.2
  diff -u -r1.7.10.1.2.1 -r1.7.10.1.2.2
  --- DTMDocumentImpl.java      10 Oct 2002 14:58:34 -0000      1.7.10.1.2.1
  +++ DTMDocumentImpl.java      17 Dec 2002 22:20:10 -0000      1.7.10.1.2.2
  @@ -2090,6 +2090,22 @@
             return null;
           }
   
  +       /**
  +        * Given a W3C DOM node, ask whether this DTM knows of a Node Handle
  +        * associated with it. Generally, returns a valid handle only if the
  +        * Node is actually mapped by this DTM (eg, because it's a DOM2DTM
  +        * which contains that Node).
  +        *
  +        * @param node Non-null reference to a DOM node.
  +        *
  +        * @return a DTM node handle, or DTM.NULL if this DTM doesn't
  +        * recognize the provided DOM node.
  +        */
  +       public int getDTMHandleFromNode(org.w3c.dom.Node node)
  +       {
  +             return DTM.NULL; // this DTM doesn't map DOM nodes.
  +       }
  +
           // ==== Construction methods (may not be supported by some 
implementations!) =====
           // %REVIEW% jjk: These probably aren't the right API. At the very least
           // they need to deal with current-insertion-location and end-element
  
  
  
  1.41.6.1.2.8 +43 -32    
xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java
  
  Index: DTMManagerDefault.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/DTMManagerDefault.java,v
  retrieving revision 1.41.6.1.2.7
  retrieving revision 1.41.6.1.2.8
  diff -u -r1.41.6.1.2.7 -r1.41.6.1.2.8
  --- DTMManagerDefault.java    20 Nov 2002 16:04:36 -0000      1.41.6.1.2.7
  +++ DTMManagerDefault.java    17 Dec 2002 22:20:10 -0000      1.41.6.1.2.8
  @@ -682,55 +682,66 @@
       {
         // Find the DOM2DTMs wrapped around this Document (if any)
         // and check whether they contain the Node in question.
  +      // This has been generalized slightly, since it's possible that
  +      // there may be multiple DOM-aware DTMs (DOM2DTM and DOM2DTM2,
  +      // currently); I've added getDTMHandleFromNode() to the DTM API
  +      // and most DTMs will immediately return DTM.NULL don't know).
         //
         // NOTE that since a DOM2DTM may represent a subtree rather
         // than a full document, we have to be prepared to check more
         // than one -- and there is no guarantee that we will find
         // one that contains ancestors or siblings of the node we're
  -      // seeking.
  +      // seeking. (That checking should probably be done in the
  +      // individual DTMs.)
         //
         // %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;
  +       //
  +       // %OPT% %REVIEW% Due to overflow addressing, we may recheck a large DTM
  +       // which was previously examined. Ouch. But with the increased number of
  +       // DTMs (another outcome of overflow addressing), scanning back to check
  +       // this is painful. 
  +       // POSSIBLE SOLUTIONS: 
  +       //   Generate a list of _unique_ DTM objects?
  +       //   Have each DTM cache last DOM node search?
  +       //   Or just make the lookup much faster, as in DOM2DTM2.
  +       int max = m_dtms.length;
         for(int i = 0; i < max; i++)
           {
             DTM thisDTM=m_dtms[i];
  -          if((null != thisDTM) && thisDTM instanceof DOM2DTM)
  +
  +          if(null != thisDTM)
             {
  -            int handle=((DOM2DTM)thisDTM).getHandleOfNode(node);
  +            int handle=thisDTM.getDTMHandleFromNode(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.
  +      
  +      // %OPT% %REVIEW% Shouldn't this also switch to DOM2DTM2 when we're
  +      // testing that code?
         Node root = node;
         Node p = (root.getNodeType() == Node.ATTRIBUTE_NODE) ? 
((org.w3c.dom.Attr)root).getOwnerElement() : root.getParentNode();
         for (; p != null; p = p.getParentNode())
  @@ -738,8 +749,8 @@
           root = p;
         }
   
  -      DOM2DTM dtm = (DOM2DTM) getDTM(new javax.xml.transform.dom.DOMSource(root),
  -                                                                                    
                                                          false, null, true, true);
  +      DTM dtm = getDTM(new javax.xml.transform.dom.DOMSource(root),
  +                                    false, null, true, true);
   
         int handle;
         
  @@ -748,11 +759,11 @@
                                // 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.getDTMHandleFromNode(((org.w3c.dom.Attr)node).getOwnerElement());
                                
handle=dtm.getAttributeNode(handle,node.getNamespaceURI(),node.getLocalName());
         }
         else
  -                             handle = ((DOM2DTM)dtm).getHandleOfNode(node);
  +                             handle = dtm.getDTMHandleFromNode(node);
   
         if(DTM.NULL == handle)
           throw new 
RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_COULD_NOT_RESOLVE_NODE,
 null)); //"Could not resolve the node to a handle!");
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.28.4.1.2.3 +10 -1     
xml-xalan/java/src/org/apache/xml/dtm/ref/dom2dtm/DOM2DTM.java
  
  Index: DOM2DTM.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/dom2dtm/DOM2DTM.java,v
  retrieving revision 1.28.4.1.2.2
  retrieving revision 1.28.4.1.2.3
  diff -u -r1.28.4.1.2.2 -r1.28.4.1.2.3
  --- DOM2DTM.java      10 Dec 2002 18:27:48 -0000      1.28.4.1.2.2
  +++ DOM2DTM.java      17 Dec 2002 22:20:10 -0000      1.28.4.1.2.3
  @@ -734,13 +734,22 @@
      * @param node A node, which may be null.
      *
      * @return The node handle or <code>DTM.NULL</code>.  */
  -  public int getHandleOfNode(Node node)
  +  public int getDTMHandleFromNode(Node node)
     {
  +     // If it's a DTM simulated node, it may know its handle.
  +     // %OPT% Make these share a common interface so we can test-and-call just once!
  +     if(node instanceof DTMNodeProxy)
  +             return ((DTMNodeProxy)node).getDTMNodeNumber();
  +     else if(node instanceof DOM2DTMdefaultNamespaceDeclarationNode)
  +             return 
((DOM2DTMdefaultNamespaceDeclarationNode)node).getHandleOfNode();
  +     
  +     // Otherwise, see if it's one this DTM covers.
       if (null != node)
       {
         // Is Node actually within the same document? If not, don't search!
         // This would be easier if m_root was always the Document node, but
         // we decided to allow wrapping a DTM around a subtree.
  +       // %REVIEW% Is this test adequate? What about disjoint subtrees?
         if((m_root==node) ||
            (m_root.getNodeType()==DOCUMENT_NODE &&
             m_root==node.getOwnerDocument()) ||
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to