You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by lm...@apache.org on 2003/03/25 21:49:39 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/dom CoreDocumentImpl.java

lmartin     2003/03/25 12:49:39

  Modified:    java/src/org/apache/xerces/dom CoreDocumentImpl.java
  Log:
  added support for ordering disconnected nodes - needed for compareDocumentPosition
  
  Revision  Changes    Path
  1.40      +53 -1     xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java
  
  Index: CoreDocumentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/CoreDocumentImpl.java,v
  retrieving revision 1.39
  retrieving revision 1.40
  diff -u -r1.39 -r1.40
  --- CoreDocumentImpl.java	21 Jan 2003 17:54:57 -0000	1.39
  +++ CoreDocumentImpl.java	25 Mar 2003 20:49:38 -0000	1.40
  @@ -210,6 +210,17 @@
       /** Bypass error checking. */
       protected boolean errorChecking = true;
   
  +    /** The following are required for compareDocumentPosition 
  +    */
  +    // Document number.   Documents are ordered across the implementation using
  +    // positive integer values.  Documents are assigned numbers on demand. 
  +    private int documentNumber=0;
  +    // Node counter and table.  Used to assign numbers to nodes for this 
  +    // document.  Node number values are negative integers.  Nodes are 
  +    // assigned numbers on demand. 
  +    private int nodeCounter = 0;
  +    private Hashtable nodeTable;
  +
       //
       // Static initialization
       //
  @@ -1229,6 +1240,47 @@
       } // createElementDefinition(String):ElementDefinitionImpl
   
       // other non-DOM methods
  +
  +    /** NON-DOM:  Get the number associated with this document.   Used to 
  +        order documents in the implementation.    
  +    */
  +    protected int getNodeNumber() {
  +         if (documentNumber==0) {
  +          
  +            CoreDOMImplementationImpl cd = (CoreDOMImplementationImpl)CoreDOMImplementationImpl.getDOMImplementation();
  +            documentNumber = cd.assignDocumentNumber();   
  +         }
  +         return documentNumber;
  +    }
  +           
  +        
  +    /** NON-DOM:  Get a number associated with a node created with respect 
  +        to this document.   Needed for compareDocumentPosition when nodes 
  +        are disconnected.  This is only used on demand. 
  +    */ 
  +    protected int getNodeNumber(Node node) {
  +
  +         // Check if the node is already in the hash 
  +         // If so, retrieve the node number  
  +         // If not, assign a number to the node 
  +         // Node numbers are negative, from -1 to -n
  +         int num;
  +         if (nodeTable == null) {
  +             nodeTable = new Hashtable();
  +             num = --nodeCounter;
  +             nodeTable.put(node, new Integer(num));   
  +         }
  +         else {
  +             Integer n = (Integer)nodeTable.get(node);
  +             if (n== null) {
  +                 num = --nodeCounter;
  +                 nodeTable.put(node, new Integer(num));
  +             }
  +             else
  +                 num = n.intValue();
  +         }
  +         return num;
  +    }
   
       /**
        * Copies a node from another document to this document. The new nodes are
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org