You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by le...@apache.org on 2002/04/12 03:13:52 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/dom AttrImpl.java AttributeMap.java DeferredAttrImpl.java DeferredAttrNSImpl.java DeferredDocumentImpl.java ElementImpl.java NodeImpl.java

lehors      02/04/11 18:13:52

  Modified:    java/src/org/apache/xerces/parsers AbstractDOMParser.java
               java/src/org/apache/xerces/dom AttrImpl.java
                        AttributeMap.java DeferredAttrImpl.java
                        DeferredAttrNSImpl.java DeferredDocumentImpl.java
                        ElementImpl.java NodeImpl.java
  Log:
  improved management of ID attributes in the DOM:
  we now keep track of which attributes are said to be IDs by the parser
  and update our id table when their value changes so that
  Document.getElementById() is more reliable
  
  Revision  Changes    Path
  1.47      +6 -4      xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java
  
  Index: AbstractDOMParser.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/parsers/AbstractDOMParser.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- AbstractDOMParser.java	3 Apr 2002 23:48:27 -0000	1.46
  +++ AbstractDOMParser.java	12 Apr 2002 01:13:52 -0000	1.47
  @@ -63,6 +63,7 @@
   import org.apache.xerces.dom.DocumentImpl;
   import org.apache.xerces.dom.DocumentTypeImpl;
   import org.apache.xerces.dom.ElementDefinitionImpl;
  +import org.apache.xerces.dom.ElementImpl;
   import org.apache.xerces.dom.EntityImpl;
   import org.apache.xerces.dom.EntityReferenceImpl;
   import org.apache.xerces.dom.NodeImpl;
  @@ -107,7 +108,7 @@
    * @author Andy Clark, IBM
    * @author Elena Litani, IBM
    *
  - * @version $Id: AbstractDOMParser.java,v 1.46 2002/04/03 23:48:27 elena Exp $
  + * @version $Id: AbstractDOMParser.java,v 1.47 2002/04/12 01:13:52 lehors Exp $
    */
   public abstract class AbstractDOMParser
       extends AbstractXMLDocumentParser {
  @@ -774,7 +775,7 @@
                       attrImpl.setSpecified(specified);
                       // identifier registration
                       if (attributes.getType(i).equals("ID")) {
  -                        fDocumentImpl.putIdentifier(attrValue, el);
  +                        ((ElementImpl) el).setIdAttributeNode(attr);
                       }
                   }
                   // REVISIT: Handle entities in attribute value.
  @@ -802,14 +803,14 @@
                       }
   
                   }
  -                fDeferredDocumentImpl.setDeferredAttribute(el,
  +                int attr = fDeferredDocumentImpl.setDeferredAttribute(el,
                                                       attributes.getQName(i),
                                                       attributes.getURI(i),
                                                       attrValue,
                                                       attributes.isSpecified(i));
                   // identifier registration
                   if (attributes.getType(i).equals("ID")) {
  -                    fDeferredDocumentImpl.putIdentifier(attrValue, el);
  +                    fDeferredDocumentImpl.setIdAttributeNode(el, attr);
                   }
               }
               fDeferredDocumentImpl.appendChild(fCurrentNodeIndex, el);
  @@ -1640,6 +1641,7 @@
                   // add default attribute
                   int attrIndex = fDeferredDocumentImpl.createDeferredAttribute(
                                       attributeName, defaultValue.toString(), false);
  +                // REVISIT: set ID type correctly
                   fDeferredDocumentImpl.appendChild(elementDefIndex, attrIndex);
               }
   
  
  
  
  1.42      +38 -22    xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java
  
  Index: AttrImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttrImpl.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- AttrImpl.java	29 Jan 2002 01:15:06 -0000	1.41
  +++ AttrImpl.java	12 Apr 2002 01:13:52 -0000	1.42
  @@ -143,7 +143,7 @@
    * @author Arnaud  Le Hors, IBM
    * @author Joe Kesselman, IBM
    * @author Andy Clark, IBM
  - * @version $Id: AttrImpl.java,v 1.41 2002/01/29 01:15:06 lehors Exp $
  + * @version $Id: AttrImpl.java,v 1.42 2002/04/12 01:13:52 lehors Exp $
    * @since PR-DOM-Level-1-19980818.
    *
    */
  @@ -318,14 +318,18 @@
                                      "DOM001 Modification not allowed");
           }
           CoreDocumentImpl ownerDocument = ownerDocument();
  +        Element ownerElement = getOwnerElement();
           String oldvalue = "";
  -        if (ownerDocument.getMutationEvents()) {
  -            // Can no longer just discard the kids; they may have
  -            // event listeners waiting for them to disconnect.
  -            if (needsSyncChildren()) {
  -                synchronizeChildren();
  -            }
  -            if (value != null) {
  +        if (needsSyncData()) {
  +            synchronizeData();
  +        }
  +        if (needsSyncChildren()) {
  +            synchronizeChildren();
  +        }
  +        if (value != null) {
  +            if (ownerDocument.getMutationEvents()) {
  +                // Can no longer just discard the kids; they may have
  +                // event listeners waiting for them to disconnect.
                   if (hasStringValue()) {
                       oldvalue = (String) value;
                       // create an actual text node as our child so
  @@ -352,20 +356,26 @@
                       }
                   }
               }
  -        }
  -        else
  -        {
  -            // simply discard children if any
  -            if (!hasStringValue() && value != null) {
  -                // remove ref from first child to last child
  -                ChildNode firstChild = (ChildNode) value;
  -                firstChild.previousSibling = null;
  -                firstChild.isFirstChild(false);
  -                firstChild.ownerNode = ownerDocument;
  -            }
  -            // then remove ref to current value
  -            value = null;
  -            needsSyncChildren(false);
  +            else {
  +                if (hasStringValue()) {
  +                    oldvalue = (String) value;
  +                }
  +                else {
  +                    // simply discard children if any
  +                    oldvalue = getValue();
  +                    // remove ref from first child to last child
  +                    ChildNode firstChild = (ChildNode) value;
  +                    firstChild.previousSibling = null;
  +                    firstChild.isFirstChild(false);
  +                    firstChild.ownerNode = ownerDocument;
  +                }
  +                // then remove ref to current value
  +                value = null;
  +                needsSyncChildren(false);
  +            }
  +            if (isIdAttribute() && ownerElement != null) {
  +                ownerDocument.removeIdentifier(oldvalue);
  +            }
           }
   
           // Create and add the new one, generating only non-aggregate events
  @@ -387,6 +397,9 @@
               hasStringValue(true);
               changed();
           }
  +        if (isIdAttribute() && ownerElement != null) {
  +            ownerDocument.putIdentifier(newvalue, ownerElement);
  +        }
   
       } // setValue(String)
   
  @@ -396,6 +409,9 @@
        */
       public String getValue() {
   
  +        if (needsSyncData()) {
  +            synchronizeData();
  +        }
           if (needsSyncChildren()) {
               synchronizeChildren();
           }
  
  
  
  1.17      +10 -0     xml-xerces/java/src/org/apache/xerces/dom/AttributeMap.java
  
  Index: AttributeMap.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/AttributeMap.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- AttributeMap.java	29 Jan 2002 01:15:07 -0000	1.16
  +++ AttributeMap.java	12 Apr 2002 01:13:52 -0000	1.17
  @@ -309,6 +309,11 @@
           n.isOwned(false);
           // make sure it won't be mistaken with defaults in case it's reused
           n.isSpecified(true);
  +        // update id table if needed
  +        if (n.isIdAttribute()) {
  +            ownerDocument.removeIdentifier(n.getValue());
  +            n.isIdAttribute(false);
  +        }
   
           // notify document
           ownerDocument.removedAttrNode(n, ownerNode, name);
  @@ -414,6 +419,11 @@
           n.isOwned(false);
           // make sure it won't be mistaken with defaults in case it's reused
           n.isSpecified(true);
  +        // update id table if needed
  +        if (n.isIdAttribute()) {
  +            ownerDocument.removeIdentifier(n.getValue());
  +            n.isIdAttribute(false);
  +        }
   
           // notify document
           ownerDocument.removedAttrNode(n, ownerNode, name);
  
  
  
  1.17      +4 -2      xml-xerces/java/src/org/apache/xerces/dom/DeferredAttrImpl.java
  
  Index: DeferredAttrImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DeferredAttrImpl.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- DeferredAttrImpl.java	29 Jan 2002 01:15:07 -0000	1.16
  +++ DeferredAttrImpl.java	12 Apr 2002 01:13:52 -0000	1.17
  @@ -98,7 +98,7 @@
    *
    * @author Andy Clark, IBM
    * @author Arnaud  Le Hors, IBM
  - * @version $Id: DeferredAttrImpl.java,v 1.16 2002/01/29 01:15:07 lehors Exp $
  + * @version $Id: DeferredAttrImpl.java,v 1.17 2002/04/12 01:13:52 lehors Exp $
    * @since  PR-DOM-Level-1-19980818.
    */
   public final class DeferredAttrImpl
  @@ -159,7 +159,9 @@
           DeferredDocumentImpl ownerDocument =
               (DeferredDocumentImpl) ownerDocument();
           name = ownerDocument.getNodeName(fNodeIndex);
  -        isSpecified(ownerDocument.getNodeExtra(fNodeIndex) == 1);
  +        int extra = ownerDocument.getNodeExtra(fNodeIndex);
  +        isSpecified((extra & SPECIFIED) == 1);
  +        isIdAttribute((extra & IDATTRIBUTE) == 1);
   
       } // synchronizeData()
   
  
  
  
  1.21      +5 -2      xml-xerces/java/src/org/apache/xerces/dom/DeferredAttrNSImpl.java
  
  Index: DeferredAttrNSImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DeferredAttrNSImpl.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- DeferredAttrNSImpl.java	29 Jan 2002 01:15:07 -0000	1.20
  +++ DeferredAttrNSImpl.java	12 Apr 2002 01:13:52 -0000	1.21
  @@ -61,7 +61,7 @@
    * DeferredAttrImpl.java at the same time.
    */
   
  -/* $Id: DeferredAttrNSImpl.java,v 1.20 2002/01/29 01:15:07 lehors Exp $ */
  +/* $Id: DeferredAttrNSImpl.java,v 1.21 2002/04/12 01:13:52 lehors Exp $ */
   
   
   package org.apache.xerces.dom;
  @@ -144,7 +144,10 @@
               localName = name.substring(index + 1);
           }
   
  -        isSpecified(ownerDocument.getNodeExtra(fNodeIndex) == 1);
  +        int extra = ownerDocument.getNodeExtra(fNodeIndex);
  +        isSpecified((extra & SPECIFIED) != 0);
  +        isIdAttribute((extra & IDATTRIBUTE) != 0);
  +
           namespaceURI = ownerDocument.getNodeURI(fNodeIndex);
           // hide the fact that our parser uses an empty string for null
           if (namespaceURI != null && namespaceURI.length() == 0) {
  
  
  
  1.43      +21 -6     xml-xerces/java/src/org/apache/xerces/dom/DeferredDocumentImpl.java
  
  Index: DeferredDocumentImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DeferredDocumentImpl.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- DeferredDocumentImpl.java	18 Feb 2002 19:34:39 -0000	1.42
  +++ DeferredDocumentImpl.java	12 Apr 2002 01:13:52 -0000	1.43
  @@ -74,7 +74,7 @@
    * which associates them with the Document within whose context they
    * were created.
    *
  - * @version $Id: DeferredDocumentImpl.java,v 1.42 2002/02/18 19:34:39 elena Exp $
  + * @version $Id: DeferredDocumentImpl.java,v 1.43 2002/04/12 01:13:52 lehors Exp $
    * @since  PR-DOM-Level-1-19980818.
    */
   public class DeferredDocumentImpl
  @@ -358,8 +358,8 @@
   				    String attrName, String attrURI,
   				    String attrValue, boolean specified) {
           // create attribute
  -	int attrNodeIndex =
  -	    createDeferredAttribute(attrName, attrURI, attrValue, specified);
  +	int attrNodeIndex = createDeferredAttribute(attrName, attrURI,
  +                                                    attrValue, specified);
   	int attrChunk = attrNodeIndex >> CHUNK_SHIFT;
   	int attrIndex  = attrNodeIndex & CHUNK_MASK;
   	// set attribute's parent to element
  @@ -388,8 +388,8 @@
       } // setDeferredAttribute(int,String,String,String,boolean):int
   
       /** Creates an attribute in the table. */
  -    public int createDeferredAttribute(String attrName,
  -                                       String attrValue, boolean specified) {
  +    public int createDeferredAttribute(String attrName, String attrValue,
  +                                       boolean specified) {
           return createDeferredAttribute(attrName, null, attrValue, specified);
       }
   
  @@ -404,7 +404,8 @@
           setChunkValue(fNodeName, attrName, chunk, index);
           setChunkValue(fNodeURI, attrURI, chunk, index);
           setChunkValue(fNodeValue, attrValue, chunk, index);
  -        setChunkIndex(fNodeExtra, specified ? 1 : 0, chunk, index);
  +        int extra = specified ? SPECIFIED : 0;
  +        setChunkIndex(fNodeExtra, extra, chunk, index);
   
           // return node index
           return nodeIndex;
  @@ -610,6 +611,20 @@
           return oldAttrIndex;
   
       } // setAttributeNode(int,int):int
  +
  +
  +    /** Adds an attribute node to the specified element. */
  +    public void setIdAttributeNode(int elemIndex, int attrIndex) {
  +
  +        int chunk = attrIndex >> CHUNK_SHIFT;
  +        int index = attrIndex & CHUNK_MASK;
  +        int extra = getChunkIndex(fNodeExtra, chunk, index);
  +        extra = extra | IDATTRIBUTE;
  +        setChunkIndex(fNodeExtra, extra, chunk, index);
  +
  +        String value = getChunkValue(fNodeValue, chunk, index);
  +        putIdentifier(value, elemIndex);
  +    }
   
       /** Inserts a child before the specified node in the table. */
       public int insertBefore(int parentIndex, int newChildIndex, int refChildIndex) {
  
  
  
  1.43      +24 -1     xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java
  
  Index: ElementImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ElementImpl.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- ElementImpl.java	29 Jan 2002 01:15:07 -0000	1.42
  +++ ElementImpl.java	12 Apr 2002 01:13:52 -0000	1.43
  @@ -88,7 +88,7 @@
    * @author Joe Kesselman, IBM
    * @author Andy Clark, IBM
    * @author Ralf Pfeiffer, IBM
  - * @version $Id: ElementImpl.java,v 1.42 2002/01/29 01:15:07 lehors Exp $
  + * @version $Id: ElementImpl.java,v 1.43 2002/04/12 01:13:52 lehors Exp $
    * @since  PR-DOM-Level-1-19980818.
    */
   public class ElementImpl
  @@ -821,6 +821,29 @@
           if (attributes != null) {
               attributes.setReadOnly(readOnly,true);
           }
  +    }
  +
  +    /**
  +     * NON-DOM: register the given attribute node as an ID attribute
  +     */
  +    public void setIdAttributeNode(Attr at) {
  +        if (needsSyncData()) {
  +            synchronizeData();
  +        }
  +    	if (ownerDocument.errorChecking) {
  +            if (isReadOnly()) {
  +                throw new DOMException(
  +                                     DOMException.NO_MODIFICATION_ALLOWED_ERR, 
  +                                     "DOM001 Modification not allowed");
  +            }
  +    	
  +            if (at.getOwnerElement() != this) {
  +                throw new DOMException(DOMException.NOT_FOUND_ERR, 
  +                                       "DOM008 Not found");
  +            }
  +        }
  +        ((AttrImpl) at).isIdAttribute(true);
  +        ownerDocument.putIdentifier(at.getValue(), this);
       }
   
       //
  
  
  
  1.50      +10 -1     xml-xerces/java/src/org/apache/xerces/dom/NodeImpl.java
  
  Index: NodeImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/NodeImpl.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- NodeImpl.java	14 Feb 2002 11:49:28 -0000	1.49
  +++ NodeImpl.java	12 Apr 2002 01:13:52 -0000	1.50
  @@ -115,7 +115,7 @@
    *
    * @author Arnaud  Le Hors, IBM
    * @author Joe Kesselman, IBM
  - * @version $Id: NodeImpl.java,v 1.49 2002/02/14 11:49:28 rahuls Exp $
  + * @version $Id: NodeImpl.java,v 1.50 2002/04/12 01:13:52 lehors Exp $
    * @since  PR-DOM-Level-1-19980818.
    */
   public abstract class NodeImpl
  @@ -154,6 +154,7 @@
       protected final static short IGNORABLEWS  = 0x1<<6;
       protected final static short HASSTRING    = 0x1<<7;
       protected final static short UNNORMALIZED = 0x1<<8;
  +    protected final static short IDATTRIBUTE  = 0x1<<9;
   
       //
       // Constructors
  @@ -1255,6 +1256,14 @@
               ownerNode.isNormalized(false);
           }
           flags = (short) (value ? flags & ~UNNORMALIZED : flags | UNNORMALIZED);
  +    }
  +
  +    final boolean isIdAttribute() {
  +        return (flags & IDATTRIBUTE) != 0;
  +    }
  +
  +    final void isIdAttribute(boolean value) {
  +        flags = (short) (value ? flags | IDATTRIBUTE : flags & ~IDATTRIBUTE);
       }
   
       //
  
  
  

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