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...@locus.apache.org on 2000/09/15 00:08:05 UTC

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

lehors      00/09/14 15:08:04

  Modified:    java/src/org/apache/xerces/dom AttributeMap.java
                        ElementImpl.java NodeImpl.java
  Log:
  patch from Lars Heete:
  Correct the generation of DOMAttrModified and DOMCharacterDataModified
  mutation events.
     - DOMAttrModified and DOMCharacterDataModified events get dispatched to
       the parent chain.
     - removing an attribute now generates a DOMAttrModified event with
        newval=null
     - adding an attribute now generates only one DOMAttrModified event
        with oldval=null
  
  Revision  Changes    Path
  1.6       +40 -1     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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AttributeMap.java	2000/08/18 01:58:34	1.5
  +++ AttributeMap.java	2000/09/14 22:08:02	1.6
  @@ -274,6 +274,21 @@
               }
           }
   
  +        LCount lc=null;
  +        String oldvalue="";
  +        AttrImpl enclosingAttribute=null;
  +        if (NodeImpl.MUTATIONEVENTS
  +            && ownerNode.ownerDocument().mutationEvents)
  +        {
  +            // MUTATION PREPROCESSING AND PRE-EVENTS:
  +            lc=LCount.lookup(MutationEventImpl.DOM_ATTR_MODIFIED);
  +            if(lc.captures+lc.bubbles+lc.defaults>0)
  +            {
  +               enclosingAttribute=(AttrImpl)(nodes.elementAt(i));
  +               oldvalue=enclosingAttribute.getNodeValue();
  +            }
  +        } // End mutation preprocessing
  +
           NodeImpl n = (NodeImpl)nodes.elementAt(i);
           // If there's a default, add it instead
           if (hasDefaults()) {
  @@ -302,6 +317,30 @@
           n.isOwned(false);
           // make sure it won't be mistaken with defaults in case it's reused
           n.isSpecified(true);
  +
  +        // We can't use the standard dispatchAggregate, since it assumes
  +        // that the Attr is still attached to an owner. This code is
  +        // similar but dispatches to the previous owner, "element".
  +        if(NodeImpl.MUTATIONEVENTS && ownerNode.ownerDocument().mutationEvents)
  +        {
  +    	    // If we have to send DOMAttrModified (determined earlier),
  +            // do so.
  +            if(lc.captures+lc.bubbles+lc.defaults>0) {
  +                MutationEvent me= new MutationEventImpl();
  +                //?????ownerDocument.createEvent("MutationEvents");
  +                me.initMutationEvent(MutationEventImpl.DOM_ATTR_MODIFIED,
  +                                     true, false,
  +                                     null, n.getNodeValue(),
  +				     null, name);
  +                ownerNode.dispatchEvent(me);
  +            }
  +
  +            // We can hand off to process DOMSubtreeModified, though.
  +            // Note that only the Element needs to be informed; the
  +            // Attr's subtree has not been changed by this operation.
  +            ownerNode.dispatchAggregateEvents(null,null);
  +        }
  +
           return n;
   
       } // removeNamedItem(String):Node
  @@ -422,7 +461,7 @@
                   me.initMutationEvent(MutationEventImpl.DOM_ATTR_MODIFIED,
                                        true, false,
                                        null, n.getNodeValue(),
  -                             ((ElementImpl)ownerNode).getAttribute(name),name);
  +				     null, name);
                   ownerNode.dispatchEvent(me);
               }
   
  
  
  
  1.26      +9 -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.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ElementImpl.java	2000/07/20 01:40:35	1.25
  +++ ElementImpl.java	2000/09/14 22:08:03	1.26
  @@ -427,9 +427,13 @@
               if (attributes == null) {
                   attributes = new AttributeMap(this, null);
               }
  +
  +	    newAttr.setNodeValue(value);
               attributes.setNamedItem(newAttr);
           }
  -    	newAttr.setNodeValue(value);
  +	else {
  +	    newAttr.setNodeValue(value);
  +	}
   
       } // setAttribute(String,String)
    
  @@ -567,9 +571,12 @@
               if (attributes == null) {
                   attributes = new AttributeMap(this, null);
               }
  +	    newAttr.setNodeValue(value);
               attributes.setNamedItemNS(newAttr);
       	}
  -    	newAttr.setNodeValue(value);
  +	else {
  +	    newAttr.setNodeValue(value);
  +	}
   
       } // setAttributeNS(String,String,String)
       
  
  
  
  1.33      +1 -6      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.32
  retrieving revision 1.33
  diff -u -r1.32 -r1.33
  --- NodeImpl.java	2000/08/30 00:22:28	1.32
  +++ NodeImpl.java	2000/09/14 22:08:03	1.33
  @@ -1141,12 +1141,7 @@
   	{
         if(MUTATIONEVENTS && ownerDocument().mutationEvents)
         {
  -          Vector nodeListeners = ownerDocument().getEventListeners(this);
  -	    if(nodeListeners==null)
  -            return;
  -
  -	    // If we have to send DOMAttrModified (determined earlier),
  -	    // do so.
  +	    // We have to send DOMAttrModified.
   	    NodeImpl owner=null;
   	    if(enclosingAttr!=null)
   	    {