You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by el...@apache.org on 2002/06/18 00:38:39 UTC

cvs commit: xml-xerces/java/src/org/apache/xerces/dom AttrImpl.java AttributeMap.java DOMNormalizer.java DeferredDocumentImpl.java ElementImpl.java NamedNodeMapImpl.java

elena       2002/06/17 15:38:39

  Modified:    java/src/org/apache/xerces/dom AttrImpl.java
                        AttributeMap.java DOMNormalizer.java
                        DeferredDocumentImpl.java ElementImpl.java
                        NamedNodeMapImpl.java
  Log:
  Add removeItem (Node item, boolean addDefault)  method to AttributeMap to allow
  removing *this* node. Make sure that id tables are updated during removal or
  addition of default attributes of type ID.
  
  Revision  Changes    Path
  1.44      +10 -1     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.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- AttrImpl.java	11 Jun 2002 17:41:24 -0000	1.43
  +++ AttrImpl.java	17 Jun 2002 22:38:38 -0000	1.44
  @@ -222,6 +222,15 @@
           }
       }
   
  +    /**
  +     * NON-DOM: set the type of this attribute to be ID type.
  +     * 
  +     * @param id
  +     */
  +    public void setIdAttribute(boolean id){
  +        this.isIdAttribute(id);
  +    }
  +
       //
       // Node methods
       //
  
  
  
  1.19      +69 -29    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.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- AttributeMap.java	18 Apr 2002 02:07:23 -0000	1.18
  +++ AttributeMap.java	17 Jun 2002 22:38:38 -0000	1.19
  @@ -268,6 +268,37 @@
           return internalRemoveNamedItem(name, false);
       }
   
  +
  +    /**
  +     * NON-DOM: Remove the node object
  +     * 
  +     * NOTE: Specifically removes THIS NODE -- not the node with this
  +     * name, nor the node with these contents. If node does not belong to
  +     * this named node map, we throw a DOMException.
  +     * 
  +     * @param item       The node to remove
  +     * @param addDefault true -- magically add default attribute
  +     * @return Removed node
  +     * @exception DOMException
  +     */
  +    protected Node removeItem (Node item, boolean addDefault) throws DOMException{
  +        int index = -1;
  +        if (nodes != null) {
  +            for (int i= 0;i<nodes.size();i++) {
  +                if (nodes.elementAt(i) == item) {
  +                    index = i;
  +                    break;
  +                }
  +            }
  +        }
  +        if (index < 0) {
  +            throw new DOMException(DOMException.NOT_FOUND_ERR,
  +                                       "DOM008 Not found");
  +        }
  +        
  +        return remove((AttrImpl)item, index, addDefault);
  +    }
  +
       /**
        * Internal removeNamedItem method allowing to specify whether an exception
        * must be thrown if the specified name is not found.
  @@ -288,48 +319,55 @@
               }
           }
   
  -        AttrImpl n = (AttrImpl)nodes.elementAt(i);
  +        return remove ((AttrImpl)nodes.elementAt(i), i, true);
  +
  +    } // internalRemoveNamedItem(String,boolean):Node
  +
  +    private final Node remove (AttrImpl attr, int index, boolean addDefault){
  +
           CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
  +        String name = attr.getNodeName();
  +        if (attr.isIdAttribute()) {
  +                ownerDocument.removeIdentifier(attr.getValue());
  +        }
   
  -        // If there's a default, add it instead
  -        if (hasDefaults()) {
  -            NamedNodeMapImpl defaults =
  -                ((ElementImpl) ownerNode).getDefaultAttributes();
  +        if (hasDefaults() && addDefault) {
  +            // If there's a default, add it instead
  +
  +            NamedNodeMapImpl defaults = ((ElementImpl) ownerNode).getDefaultAttributes();
               Node d;
               if (defaults != null && (d = defaults.getNamedItem(name)) != null
  -                && findNamePoint(name, i+1) < 0) {
  -
  +                && findNamePoint(name, index+1) < 0) {
                   NodeImpl clone = (NodeImpl)d.cloneNode(true);
                   clone.ownerNode = ownerNode;
  +
                   clone.isOwned(true);
                   clone.isSpecified(false);
  -                nodes.setElementAt(clone, i);
  +                nodes.setElementAt(clone, index);
  +                if (attr.isIdAttribute()) {
  +                        ownerDocument.putIdentifier(clone.getNodeValue(), (ElementImpl)ownerNode);
  +                }
               } else {
  -                nodes.removeElementAt(i);
  +                nodes.removeElementAt(index);
               }
           } else {
  -            nodes.removeElementAt(i);
  +            nodes.removeElementAt(index);
           }
   
           //        changed(true);
   
           // remove reference to owner
  -        n.ownerNode = ownerDocument;
  -        n.isOwned(false);
  +        attr.ownerNode = ownerDocument;
  +        attr.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);
  -        }
  +        attr.isSpecified(true);
  +        attr.isIdAttribute(false);
   
           // notify document
  -        ownerDocument.removedAttrNode(n, ownerNode, name);
  +        ownerDocument.removedAttrNode(attr, ownerNode, name);
   
  -        return n;
  -
  -    } // internalRemoveNamedItem(String,boolean):Node
  +        return attr;
  +    }
       
       /**
        * Introduced in DOM Level 2. <p>
  @@ -386,11 +424,13 @@
           AttrImpl n = (AttrImpl)nodes.elementAt(i);
           CoreDocumentImpl ownerDocument = ownerNode.ownerDocument();
   
  +        if (n.isIdAttribute()) {
  +                ownerDocument.removeIdentifier(n.getValue());
  +        }
           // If there's a default, add it instead
           String nodeName = n.getNodeName();
           if (hasDefaults()) {
  -            NamedNodeMapImpl defaults =
  -                ((ElementImpl) ownerNode).getDefaultAttributes();
  +            NamedNodeMapImpl defaults = ((ElementImpl) ownerNode).getDefaultAttributes();
               Node d;
               if (defaults != null
                   && (d = defaults.getNamedItem(nodeName)) != null)
  @@ -411,6 +451,10 @@
                           clone.isOwned(true);
                           clone.isSpecified(false);
                           nodes.setElementAt(clone, i);
  +                        if (clone.isIdAttribute()) {
  +                                ownerDocument.putIdentifier(clone.getNodeValue(), 
  +                                                            (ElementImpl)ownerNode);
  +                        }
                       } else {
                           nodes.removeElementAt(i);
                       }
  @@ -429,10 +473,7 @@
           // 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);
  -        }
  +        n.isIdAttribute(false);
   
           // notify document
           ownerDocument.removedAttrNode(n, ownerNode, name);
  @@ -486,7 +527,6 @@
        * @param defaults The default attributes map to sync with.
        */
       protected void reconcileDefaults(NamedNodeMapImpl defaults) {
  -        
           // remove any existing default
           int nsize = (nodes != null) ? nodes.size() : 0;
           for (int i = nsize - 1; i >= 0; i--) {
  
  
  
  1.6       +2 -2      xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java
  
  Index: DOMNormalizer.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/DOMNormalizer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DOMNormalizer.java	14 Jun 2002 17:54:55 -0000	1.5
  +++ DOMNormalizer.java	17 Jun 2002 22:38:38 -0000	1.6
  @@ -858,7 +858,7 @@
                   if (DEBUG_ND) {
                       System.out.println("==>remove default attr: "+attribute.getNodeName());
                   }
  -                attrMap.removeItem(attribute);
  +                attrMap.removeItem(attribute, false);
               }
           }
       }
  
  
  
  1.46      +12 -1     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.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- DeferredDocumentImpl.java	7 May 2002 19:29:03 -0000	1.45
  +++ DeferredDocumentImpl.java	17 Jun 2002 22:38:38 -0000	1.46
  @@ -687,6 +687,17 @@
           putIdentifier(value, elemIndex);
       }
   
  +
  +    /** Sets type of attribute */
  +    public void setIdAttribute(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);
  +    }
  +
       /** Inserts a child before the specified node in the table. */
       public int insertBefore(int parentIndex, int newChildIndex, int refChildIndex) {
   
  
  
  
  1.48      +2 -2      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.47
  retrieving revision 1.48
  diff -u -r1.47 -r1.48
  --- ElementImpl.java	11 Jun 2002 17:41:24 -0000	1.47
  +++ ElementImpl.java	17 Jun 2002 22:38:38 -0000	1.48
  @@ -430,7 +430,7 @@
               throw new DOMException(DOMException.NOT_FOUND_ERR, 
                                          "DOM008 Not found");
           }
  -        return (Attr) attributes.removeItem(oldAttr);
  +        return (Attr) attributes.removeItem(oldAttr, true);
   
       } // removeAttributeNode(Attr):Attr
   
  
  
  
  1.29      +1 -29     xml-xerces/java/src/org/apache/xerces/dom/NamedNodeMapImpl.java
  
  Index: NamedNodeMapImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/NamedNodeMapImpl.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -r1.28 -r1.29
  --- NamedNodeMapImpl.java	24 May 2002 00:00:53 -0000	1.28
  +++ NamedNodeMapImpl.java	17 Jun 2002 22:38:38 -0000	1.29
  @@ -535,34 +535,6 @@
          }
       }
   
  -    /**
  -     * NON-DOM: Remove the node object
  -     * 
  -     * NOTE: Specifically removes THIS NODE -- not the node with this
  -     * name, nor the node with these contents. If node does not belong to
  -     * this named node map, we throw a DOMException.
  -     * 
  -     * @param item   The node to remove
  -     * @return Removed node
  -     * @exception DOMException
  -     */
  -    protected Node removeItem (Node item) throws DOMException{
  -        int index = -1;
  -        if (nodes != null) {
  -            for (int i= 0;i<nodes.size();i++) {
  -                if (nodes.elementAt(i) == item) {
  -                    index = i;
  -                    nodes.removeElementAt(index);
  -                    break;
  -                }
  -            }
  -        }
  -        if (index < 0) {
  -            throw new DOMException(DOMException.NOT_FOUND_ERR,
  -                                       "DOM008 Not found");
  -        }
  -        return item;
  -    }
   
       protected Object getItem (int index){
           if (nodes !=null) {
  
  
  

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