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 2001/01/20 01:51:40 UTC

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

lehors      01/01/19 16:51:40

  Modified:    java/src/org/apache/html/dom HTMLFormElementImpl.java
                        HTMLSelectElementImpl.java
               java/src/org/apache/xerces/dom ParentNode.java
  Log:
  Applied patch from Mark Diekhans:
  
  This patch provides for hiding the NodeList DOM methods when necessary.
  The approach adds a method getChildNodesUnoptimized() to ParentNode
  that return an anonymous class implementing NodeList.  If a subclass
  has a conflicting method getLength() or item(int); it must implement
  getChildNodes() and then call this method to get a NodeList.
  This was done for a couple of reasons:
     (1) Avoided duplicate code (in different files).
     (2) Avoided needing to make various private fields in ParentNode
         protected.
  
  Revision  Changes    Path
  1.4       +8 -1      xml-xerces/java/src/org/apache/html/dom/HTMLFormElementImpl.java
  
  Index: HTMLFormElementImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/html/dom/HTMLFormElementImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HTMLFormElementImpl.java	2000/12/21 00:33:40	1.3
  +++ HTMLFormElementImpl.java	2001/01/20 00:51:39	1.4
  @@ -62,7 +62,7 @@
   
   
   /**
  - * @version $Revision: 1.3 $ $Date: 2000/12/21 00:33:40 $
  + * @version $Revision: 1.4 $ $Date: 2001/01/20 00:51:39 $
    * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
    * @see org.w3c.dom.html.HTMLFormElement
    * @see ElementImpl
  @@ -170,6 +170,13 @@
           // No scripting in server-side DOM. This method is moot.
       }
   
  +    /*
  +     * Explicit implementation of getChildNodes() to avoid problems with
  +     * overriding the getLength() method hidden in the super class.
  +     */
  +    public NodeList getChildNodes() {
  +        return getChildNodesUnoptimized();
  +    }
       
       /**
        * Constructor requires owner document.
  
  
  
  1.4       +8 -1      xml-xerces/java/src/org/apache/html/dom/HTMLSelectElementImpl.java
  
  Index: HTMLSelectElementImpl.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/html/dom/HTMLSelectElementImpl.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- HTMLSelectElementImpl.java	2000/12/21 00:33:44	1.3
  +++ HTMLSelectElementImpl.java	2001/01/20 00:51:39	1.4
  @@ -62,7 +62,7 @@
   
   
   /**
  - * @version $Revision: 1.3 $ $Date: 2000/12/21 00:33:44 $
  + * @version $Revision: 1.4 $ $Date: 2001/01/20 00:51:39 $
    * @author <a href="mailto:arkin@exoffice.com">Assaf Arkin</a>
    * @see org.w3c.dom.html.HTMLSelectElement
    * @see ElementImpl
  @@ -233,6 +233,13 @@
           // No scripting in server-side DOM. This method is moot.
       }
   
  +    /*
  +     * Explicit implementation of getChildNodes() to avoid problems with
  +     * overriding the getLength() method hidden in the super class.
  +     */
  +    public NodeList getChildNodes() {
  +        return getChildNodesUnoptimized();
  +    }
     
       /**
        * Constructor requires owner document.
  
  
  
  1.19      +63 -11    xml-xerces/java/src/org/apache/xerces/dom/ParentNode.java
  
  Index: ParentNode.java
  ===================================================================
  RCS file: /home/cvs/xml-xerces/java/src/org/apache/xerces/dom/ParentNode.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ParentNode.java	2001/01/18 22:26:26	1.18
  +++ ParentNode.java	2001/01/20 00:51:40	1.19
  @@ -1,4 +1,4 @@
  -/* $Id: ParentNode.java,v 1.18 2001/01/18 22:26:26 lehors Exp $ */
  +/* $Id: ParentNode.java,v 1.19 2001/01/20 00:51:40 lehors Exp $ */
   /*
    * The Apache Software License, Version 1.1
    *
  @@ -74,7 +74,9 @@
    * return itself in response to the getChildNodes() query. This eliminiates
    * the need for a separate ChildNodeList object. Note that this is an
    * IMPLEMENTATION DETAIL; applications should _never_ assume that
  - * this identity exists.
  + * this identity exists. On the other hand, subclasses may need to override
  + * this, in case of conflicting names. This is the case for the classes
  + * HTMLSelectElementImpl and HTMLFormElementImpl of the HTML DOM.
    * <P>
    * While we have a direct reference to the first child, the last child is
    * stored as the previous sibling of the first child. First child nodes are
  @@ -246,7 +248,6 @@
        * differently.
        */
       public NodeList getChildNodes() {
  -        // JKESS: KNOWN ISSUE HERE 
   
           if (needsSyncChildren()) {
               synchronizeChildren();
  @@ -781,10 +782,11 @@
       //
   
       /**
  -     * NodeList method: Count the immediate children of this node
  +     * Count the immediate children of this node.  Use to implement
  +     * NodeList.getLength().
        * @return int
        */
  -    public int getLength() {
  +    private int nodeListGetLength() {
   
           if (nodeListLength == -1) { // is the cached length invalid ?
               ChildNode node;
  @@ -803,15 +805,22 @@
   
           return nodeListLength;
   
  -    } // getLength():int
  +    } // nodeListGetLength():int
   
       /**
  -     * NodeList method: Return the Nth immediate child of this node, or
  -     * null if the index is out of bounds.
  -     * @return org.w3c.dom.Node
  -     * @param Index int
  +     * NodeList method: Count the immediate children of this node
  +     * @return int
        */
  -    public Node item(int index) {
  +    public int getLength() {
  +        return nodeListGetLength();
  +    }
  +
  +    /**
  +     * Return the Nth immediate child of this node, or null if the index is
  +     * out of bounds.  Use to implement NodeList.item().
  +     * @param index int
  +     */
  +    private Node nodeListItem(int index) {
           // short way
           if (nodeListIndex != -1 && nodeListNode != null) {
               if (nodeListIndex < index) {
  @@ -838,7 +847,50 @@
           }
           return nodeListNode;
   
  +    } // nodeListItem(int):Node
  +
  +    /**
  +     * NodeList method: Return the Nth immediate child of this node, or
  +     * null if the index is out of bounds.
  +     * @return org.w3c.dom.Node
  +     * @param index int
  +     */
  +    public Node item(int index) {
  +        return nodeListItem(index);
       } // item(int):Node
  +
  +    /**
  +     * Create a NodeList to access children that is use by subclass elements
  +     * that have methods named getLength() or item(int).  ChildAndParentNode
  +     * optimizes getChildNodes() by implementing NodeList itself.  However if
  +     * a subclass Element implements methods with the same name as the NodeList
  +     * methods, they will override the actually methods in this class.
  +     * <p>
  +     * To use this method, the subclass should implement getChildNodes() and
  +     * have it call this method.  The resulting NodeList instance maybe
  +     * shared and cached in a transient field, but the cached value must be
  +     * cleared if the node is cloned.
  +     */
  +    protected final NodeList getChildNodesUnoptimized() {
  +        if (needsSyncChildren()) {
  +            synchronizeChildren();
  +        }
  +        return new NodeList() {
  +                /**
  +                 * @see NodeList.getLength()
  +                 */
  +                public int getLength() {
  +                    return nodeListGetLength();
  +                } // getLength():int
  +                
  +                /**
  +                 * @see NodeList.item(int)
  +                 */
  +                public Node item(int index) {
  +                    return nodeListItem(index);
  +                } // item(int):Node
  +            };
  +    } // getChildNodesUnoptimized():NodeList
   
       //
       // DOM2: methods, getters, setters