axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ruchi...@apache.org
Subject svn commit: r367519 [4/5] - in /webservices/axis2/trunk/java/modules: doom/src/org/apache/axis2/om/impl/dom/ doom/src/org/apache/axis2/om/impl/dom/factory/ doom/src/org/apache/axis2/om/impl/dom/jaxp/ integration/test/org/apache/axis2/security/
Date Tue, 10 Jan 2006 07:54:32 GMT
Modified: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamedNodeMapImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamedNodeMapImpl.java?rev=367519&r1=367518&r2=367519&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamedNodeMapImpl.java (original)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamedNodeMapImpl.java Mon Jan  9 23:53:43 2006
@@ -23,138 +23,149 @@
 
 /**
  * 
- * Most of the implementation is taken from 
+ * Most of the implementation is taken from
  * org.apache.xerces.dom.NamedNodeMapImpl
  */
 public class NamedNodeMapImpl implements NamedNodeMap {
 
-	Vector nodes;
-	ParentNode ownerNode;
+    Vector nodes;
+
+    ParentNode ownerNode;
+
     //
     // Data
     //
 
     protected short flags;
 
-    protected final static short READONLY     = 0x1<<0;
-    protected final static short CHANGED      = 0x1<<1;
-    protected final static short HASDEFAULTS  = 0x1<<2;
-    
-    
-	protected NamedNodeMapImpl(ParentNode ownerNode) {
-		this.ownerNode = ownerNode;
-	}
-
-	/**
-	 * 
-	 */
+    protected final static short READONLY = 0x1 << 0;
+
+    protected final static short CHANGED = 0x1 << 1;
+
+    protected final static short HASDEFAULTS = 0x1 << 2;
+
+    protected NamedNodeMapImpl(ParentNode ownerNode) {
+        this.ownerNode = ownerNode;
+    }
+
+    /**
+     * 
+     */
     public Node getNamedItem(String name) {
-    	int i = findNamePoint(name,0);
-        return (i < 0) ? null : (Node)(nodes.elementAt(i));
+        int i = findNamePoint(name, 0);
+        return (i < 0) ? null : (Node) (nodes.elementAt(i));
 
     }
 
-	/** 
-	 *From org.apache.xerces.dom.NamedNodeMapImpl
-	 */
+    /**
+     * From org.apache.xerces.dom.NamedNodeMapImpl
+     */
     public Node item(int index) {
-    	return (nodes != null && index < nodes.size()) ?
-                    (Node)(nodes.elementAt(index)) : null;
+        return (nodes != null && index < nodes.size()) ? (Node) (nodes
+                .elementAt(index)) : null;
     }
 
-	/**
-	 * From org.apache.xerces.dom.NamedNodeMapImpl
-	 */
+    /**
+     * From org.apache.xerces.dom.NamedNodeMapImpl
+     */
     public int getLength() {
-    	return (nodes != null) ? nodes.size() : 0;
+        return (nodes != null) ? nodes.size() : 0;
     }
-    
+
     /**
      * Removes a node specified by name.
-     * @param name The name of a node to remove.
-     * @return Returns the node removed from the map if a node with such a name exists.
+     * 
+     * @param name
+     *            The name of a node to remove.
+     * @return Returns the node removed from the map if a node with such a name
+     *         exists.
      */
     /***/
-    public Node removeNamedItem(String name)
-        throws DOMException {
+    public Node removeNamedItem(String name) throws DOMException {
 
-    	if (isReadOnly()) {
-            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
-            throw
-                new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
-                msg);
-        }
-    	int i = findNamePoint(name,0);
-    	if (i < 0) {
-            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
+        if (isReadOnly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+        int i = findNamePoint(name, 0);
+        if (i < 0) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
             throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
         }
 
-        NodeImpl n = (NodeImpl)nodes.elementAt(i);
+        NodeImpl n = (NodeImpl) nodes.elementAt(i);
         nodes.removeElementAt(i);
 
         return n;
 
     } // removeNamedItem(String):Node
-    
-    
+
     /**
-     * Introduced in DOM Level 2. 
-     * Retrieves a node specified by local name and namespace URI.
-     *
-     * @param namespaceURI  The namespace URI of the node to retrieve.
-     *                      When it is null or an empty string, this
-     *                      method behaves like getNamedItem.
-     * @param localName     The local name of the node to retrieve.
-     * @return          Returns s Node (of any type) with the specified name, or null if the specified
-     *                      name did not identify any node in the map.
+     * Introduced in DOM Level 2. Retrieves a node specified by local name and
+     * namespace URI.
+     * 
+     * @param namespaceURI
+     *            The namespace URI of the node to retrieve. When it is null or
+     *            an empty string, this method behaves like getNamedItem.
+     * @param localName
+     *            The local name of the node to retrieve.
+     * @return Returns s Node (of any type) with the specified name, or null if
+     *         the specified name did not identify any node in the map.
      */
     public Node getNamedItemNS(String namespaceURI, String localName) {
 
-    	int i = findNamePoint(namespaceURI, localName);
-        return (i < 0) ? null : (Node)(nodes.elementAt(i));
+        int i = findNamePoint(namespaceURI, localName);
+        return (i < 0) ? null : (Node) (nodes.elementAt(i));
 
     } // getNamedItemNS(String,String):Node
 
     /**
      * Adds a node using its namespaceURI and localName.
+     * 
      * @see org.w3c.dom.NamedNodeMap#setNamedItem
-     * @return Returns the replaced Node if the new Node replaces an existing node else returns null.
-     * @param arg A node to store in a named node map. The node will later be
-     *      accessible using the value of the namespaceURI and localName
-     *      attribute of the node. If a node with those namespace URI and
-     *      local name is already present in the map, it is replaced by the new
-     *      one.
+     * @return Returns the replaced Node if the new Node replaces an existing
+     *         node else returns null.
+     * @param arg
+     *            A node to store in a named node map. The node will later be
+     *            accessible using the value of the namespaceURI and localName
+     *            attribute of the node. If a node with those namespace URI and
+     *            local name is already present in the map, it is replaced by
+     *            the new one.
      */
     public Node setNamedItemNS(Node arg) throws DOMException {
-        
-        DocumentImpl ownerDocument = (DocumentImpl)ownerNode.getOwnerDocument();
+
+        DocumentImpl ownerDocument = (DocumentImpl) ownerNode
+                .getOwnerDocument();
         if (isReadOnly()) {
-			String msg = DOMMessageFormatter.formatMessage(
-					DOMMessageFormatter.DOM_DOMAIN,
-					"NO_MODIFICATION_ALLOWED_ERR", null);
-			throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
-					msg);
-		}
-
-		if (arg.getOwnerDocument() != ownerDocument) {
-			String msg = DOMMessageFormatter.formatMessage(
-					DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
-			throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
-		}
-        
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+
+        if (arg.getOwnerDocument() != ownerDocument) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
+            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
+        }
+
         int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
         NodeImpl previous = null;
         if (i >= 0) {
             previous = (NodeImpl) nodes.elementAt(i);
-            nodes.setElementAt(arg,i);
+            nodes.setElementAt(arg, i);
         } else {
             // If we can't find by namespaceURI, localName, then we find by
             // nodeName so we know where to insert.
-            i = findNamePoint(arg.getNodeName(),0);
+            i = findNamePoint(arg.getNodeName(), 0);
             if (i >= 0) {
                 previous = (NodeImpl) nodes.elementAt(i);
-                nodes.insertElementAt(arg,i);
+                nodes.insertElementAt(arg, i);
             } else {
                 i = -1 - i; // Insert point (may be end of list)
                 if (null == nodes) {
@@ -164,97 +175,100 @@
             }
         }
         return previous;
-        
+
     } // setNamedItemNS(Node):Node
 
     /**
-     * Introduced in DOM Level 2. 
-     * Removes a node specified by local name and namespace URI.
+     * Introduced in DOM Level 2. Removes a node specified by local name and
+     * namespace URI.
+     * 
      * @param namespaceURI
-     *                      The namespace URI of the node to remove.
-     *                      When it is null or an empty string, this
-     *                      method behaves like removeNamedItem.
-     * @param     name          The local name of the node to remove.
-     * @return          Returns the node removed from the map if a node with such
-     *                      a local name and namespace URI exists.
-     * @throws              NOT_FOUND_ERR: Raised if there is no node named
-     *                      name in the map.
-
-     */
-     public Node removeNamedItemNS(String namespaceURI, String name)
-        throws DOMException {
-
-    	if (isReadOnly()) {
-            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NO_MODIFICATION_ALLOWED_ERR", null);
-            throw
-                new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
-                msg);
-        }
-    	int i = findNamePoint(namespaceURI, name);
-    	if (i < 0) {
-            String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
+     *            The namespace URI of the node to remove. When it is null or an
+     *            empty string, this method behaves like removeNamedItem.
+     * @param name
+     *            The local name of the node to remove.
+     * @return Returns the node removed from the map if a node with such a local
+     *         name and namespace URI exists.
+     * @throws NOT_FOUND_ERR:
+     *             Raised if there is no node named name in the map.
+     * 
+     */
+    public Node removeNamedItemNS(String namespaceURI, String name)
+            throws DOMException {
+
+        if (isReadOnly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+        int i = findNamePoint(namespaceURI, name);
+        if (i < 0) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR", null);
             throw new DOMException(DOMException.NOT_FOUND_ERR, msg);
         }
 
-        NodeImpl n = (NodeImpl)nodes.elementAt(i);
+        NodeImpl n = (NodeImpl) nodes.elementAt(i);
         nodes.removeElementAt(i);
 
         return n;
 
     } // removeNamedItem(String):Node
-     
-     
-     /**
-      * Adds a node using its nodeName attribute.
-      * As the nodeName attribute is used to derive the name which the node must be
-      * stored under, multiple nodes of certain types (those that have a "special" string
-      * value) cannot be stored as the names would clash. This is seen as preferable to
-      * allowing nodes to be aliased.
-      * @see org.w3c.dom.NamedNodeMap#setNamedItem
-      * @return Returns the replaced Node if the new Node replaces an existing node, 
-      *         otherwise returns null.
-      * @param arg 
-      *      A node to store in a named node map. The node will later be
-      *      accessible using the value of the namespaceURI and localName
-      *      attribute of the node. If a node with those namespace URI and
-      *      local name is already present in the map, it is replaced by the new
-      *      one.
-      * @exception org.w3c.dom.DOMException The exception description.
-      */
-     public Node setNamedItem(Node arg)
-     throws DOMException {
-         
-         DocumentImpl ownerDocument = (DocumentImpl)ownerNode.getOwnerDocument();
-         
-         if (isReadOnly()) {
-			String msg = DOMMessageFormatter.formatMessage(
-					DOMMessageFormatter.DOM_DOMAIN,
-					"NO_MODIFICATION_ALLOWED_ERR", null);
-			throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
-					msg);
-         }
-         if (arg.getOwnerDocument() != ownerDocument) {
-         	String msg = DOMMessageFormatter.formatMessage(
-					DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
-			throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
-         }
-         
-         int i = findNamePoint(arg.getNodeName(),0);
-         NodeImpl previous = null;
-         if (i >= 0) {
-             previous = (NodeImpl) nodes.elementAt(i);
-             nodes.setElementAt(arg,i);
-         } else {
-             i = -1 - i; // Insert point (may be end of list)
-             if (null == nodes) {
-                 nodes = new Vector(5, 10);
-             }
-             nodes.insertElementAt(arg, i);
-         }
-         return previous;
-         
-     } // setNamedItem(Node):Node
-	
+
+    /**
+     * Adds a node using its nodeName attribute. As the nodeName attribute is
+     * used to derive the name which the node must be stored under, multiple
+     * nodes of certain types (those that have a "special" string value) cannot
+     * be stored as the names would clash. This is seen as preferable to
+     * allowing nodes to be aliased.
+     * 
+     * @see org.w3c.dom.NamedNodeMap#setNamedItem
+     * @return Returns the replaced Node if the new Node replaces an existing
+     *         node, otherwise returns null.
+     * @param arg
+     *            A node to store in a named node map. The node will later be
+     *            accessible using the value of the namespaceURI and localName
+     *            attribute of the node. If a node with those namespace URI and
+     *            local name is already present in the map, it is replaced by
+     *            the new one.
+     * @exception org.w3c.dom.DOMException
+     *                The exception description.
+     */
+    public Node setNamedItem(Node arg) throws DOMException {
+
+        DocumentImpl ownerDocument = (DocumentImpl) ownerNode
+                .getOwnerDocument();
+
+        if (isReadOnly()) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN,
+                    "NO_MODIFICATION_ALLOWED_ERR", null);
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    msg);
+        }
+        if (arg.getOwnerDocument() != ownerDocument) {
+            String msg = DOMMessageFormatter.formatMessage(
+                    DOMMessageFormatter.DOM_DOMAIN, "WRONG_DOCUMENT_ERR", null);
+            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR, msg);
+        }
+
+        int i = findNamePoint(arg.getNodeName(), 0);
+        NodeImpl previous = null;
+        if (i >= 0) {
+            previous = (NodeImpl) nodes.elementAt(i);
+            nodes.setElementAt(arg, i);
+        } else {
+            i = -1 - i; // Insert point (may be end of list)
+            if (null == nodes) {
+                nodes = new Vector(5, 10);
+            }
+            nodes.insertElementAt(arg, i);
+        }
+        return previous;
+
+    } // setNamedItem(Node):Node
 
     final boolean isReadOnly() {
         return (flags & READONLY) != 0;
@@ -279,40 +293,41 @@
     final void hasDefaults(boolean value) {
         flags = (short) (value ? flags | HASDEFAULTS : flags & ~HASDEFAULTS);
     }
-	
+
     /**
      * 
      * From org.apache.xerces.dom.NamedNodeMapImpl
      * 
      * Subroutine: Locates the named item, or the point at which said item
-     * should be added. 
-     *
-     * @param name Name of a node to look up.
-     *
-     * @return If positive or zero, the index of the found item.
-     * If negative, index of the appropriate point at which to insert
-     * the item, encoded as -1-index and hence reconvertable by subtracting
-     * it from -1. (Encoding because I don't want to recompare the strings
-     * but don't want to burn bytes on a datatype to hold a flagged value.)
+     * should be added.
+     * 
+     * @param name
+     *            Name of a node to look up.
+     * 
+     * @return If positive or zero, the index of the found item. If negative,
+     *         index of the appropriate point at which to insert the item,
+     *         encoded as -1-index and hence reconvertable by subtracting it
+     *         from -1. (Encoding because I don't want to recompare the strings
+     *         but don't want to burn bytes on a datatype to hold a flagged
+     *         value.)
      */
     protected int findNamePoint(String name, int start) {
 
-    	// Binary search
-    	int i = 0;
-    	if (nodes != null) {
+        // Binary search
+        int i = 0;
+        if (nodes != null) {
             int first = start;
-            int last  = nodes.size() - 1;
+            int last = nodes.size() - 1;
 
             while (first <= last) {
                 i = (first + last) / 2;
-                int test = name.compareTo(((Node)(nodes.elementAt(i))).getNodeName());
+                int test = name.compareTo(((Node) (nodes.elementAt(i)))
+                        .getNodeName());
                 if (test == 0) {
                     return i; // Name found
-                }
-                else if (test < 0) {
+                } else if (test < 0) {
                     last = i - 1;
-                }
-                else {
+                } else {
                     first = i + 1;
                 }
             }
@@ -320,93 +335,90 @@
             if (first > i) {
                 i = first;
             }
-    	}
+        }
 
-    	return -1 - i; // not-found has to be encoded.
+        return -1 - i; // not-found has to be encoded.
 
     } // findNamePoint(String):int
-    
-    /** This findNamePoint is for DOM Level 2 Namespaces.
+
+    /**
+     * This findNamePoint is for DOM Level 2 Namespaces.
      */
     protected int findNamePoint(String namespaceURI, String name) {
-        
-        if (nodes == null) return -1;
-        if (name == null) return -1;
-        
+
+        if (nodes == null)
+            return -1;
+        if (name == null)
+            return -1;
+
         // This is a linear search through the same nodes Vector.
         // The Vector is sorted on the DOM Level 1 nodename.
-        // The DOM Level 2 NS keys are namespaceURI and Localname, 
+        // The DOM Level 2 NS keys are namespaceURI and Localname,
         // so we must linear search thru it.
         // In addition, to get this to work with nodes without any namespace
         // (namespaceURI and localNames are both null) we then use the nodeName
         // as a seconday key.
         for (int i = 0; i < nodes.size(); i++) {
-            NodeImpl a = (NodeImpl)nodes.elementAt(i);
+            NodeImpl a = (NodeImpl) nodes.elementAt(i);
             String aNamespaceURI = a.getNamespaceURI();
             String aLocalName = a.getLocalName();
             if (namespaceURI == null) {
-              if (aNamespaceURI == null
-                  &&
-                  (name.equals(aLocalName)
-                   ||
-                   (aLocalName == null && name.equals(a.getNodeName()))))
-                return i;
+                if (aNamespaceURI == null && (name.equals(aLocalName) || 
+                        (aLocalName == null && name.equals(a.getNodeName()))))
+                    return i;
             } else {
-              if (namespaceURI.equals(aNamespaceURI)
-                  &&
-                  name.equals(aLocalName))
-                return i;
+                if (namespaceURI.equals(aNamespaceURI)
+                        && name.equals(aLocalName))
+                    return i;
             }
         }
         return -1;
     }
-    
-    // Compare 2 nodes in the map.  If a precedes b, return true, otherwise 
+
+    // Compare 2 nodes in the map. If a precedes b, return true, otherwise
     // return false
     protected boolean precedes(Node a, Node b) {
 
-       if (nodes != null) {
-          for (int i = 0; i < nodes.size(); i++) {
-              Node n = (Node)nodes.elementAt(i);
-              if (n==a) return true;
-              if (n==b) return false;
-          }
-       }
+        if (nodes != null) {
+            for (int i = 0; i < nodes.size(); i++) {
+                Node n = (Node) nodes.elementAt(i);
+                if (n == a)
+                    return true;
+                if (n == b)
+                    return false;
+            }
+        }
 
-       return false;
+        return false;
     }
 
-
     /**
-      * NON-DOM: Remove attribute at specified index.
-      */
+     * NON-DOM: Remove attribute at specified index.
+     */
     protected void removeItem(int index) {
-       if (nodes != null && index < nodes.size()){
-           nodes.removeElementAt(index);
-       }
+        if (nodes != null && index < nodes.size()) {
+            nodes.removeElementAt(index);
+        }
     }
 
-
-    protected Object getItem (int index){
-        if (nodes !=null) {
+    protected Object getItem(int index) {
+        if (nodes != null) {
             return nodes.elementAt(index);
         }
         return null;
     }
 
-    protected int addItem (Node arg) {
-    	int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
-    	if (i >= 0) {
-            nodes.setElementAt(arg,i);
-    	} 
-        else {
-    	    // If we can't find by namespaceURI, localName, then we find by
-    	    // nodeName so we know where to insert.
-    	    i = findNamePoint(arg.getNodeName(),0);
+    protected int addItem(Node arg) {
+        int i = findNamePoint(arg.getNamespaceURI(), arg.getLocalName());
+        if (i >= 0) {
+            nodes.setElementAt(arg, i);
+        } else {
+            // If we can't find by namespaceURI, localName, then we find by
+            // nodeName so we know where to insert.
+            i = findNamePoint(arg.getNodeName(), 0);
             if (i >= 0) {
-                nodes.insertElementAt(arg,i);
-            } 
-            else {
+                nodes.insertElementAt(arg, i);
+            } else {
                 i = -1 - i; // Insert point (may be end of list)
                 if (null == nodes) {
                     nodes = new Vector(5, 10);
@@ -414,40 +426,41 @@
                 nodes.insertElementAt(arg, i);
             }
         }
-        return i;        
+        return i;
     }
 
     /**
      * NON-DOM: copy content of this map into the specified vector
      * 
-     * @param list   Vector to copy information into.
+     * @param list
+     *            Vector to copy information into.
      * @return Returns a copy of this node named map.
      */
-    protected Vector cloneMap(Vector list){
+    protected Vector cloneMap(Vector list) {
         if (list == null) {
             list = new Vector(5, 10);
         }
         list.setSize(0);
         if (nodes != null) {
-            for (int i=0; i<nodes.size(); i++) {
+            for (int i = 0; i < nodes.size(); i++) {
                 list.insertElementAt(nodes.elementAt(i), i);
             }
         }
-        
+
         return list;
     }
-    
-     protected int getNamedItemIndex(String namespaceURI, String localName) {
+
+    protected int getNamedItemIndex(String namespaceURI, String localName) {
         return findNamePoint(namespaceURI, localName);
-     }
+    }
 
     /**
-      * NON-DOM remove all elements from this map.
-      */
-    public void removeAll (){
+     * NON-DOM remove all elements from this map.
+     */
+    public void removeAll() {
         if (nodes != null) {
             nodes.removeAllElements();
         }
     }
-    
+
 }

Modified: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamespaceImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamespaceImpl.java?rev=367519&r1=367518&r2=367519&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamespaceImpl.java (original)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NamespaceImpl.java Mon Jan  9 23:53:43 2006
@@ -19,37 +19,45 @@
 
 public class NamespaceImpl implements OMNamespace {
 
-	private String nsUri;
-	private String nsPrefix;
-	
-	public NamespaceImpl(String uri) {
-		this.nsUri = uri;
-	}
-	
-	public NamespaceImpl(String uri, String prefix) {
-		this.nsUri = uri;
-		this.nsPrefix = prefix;
-	}
-	
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMNamespace#equals(java.lang.String, java.lang.String)
-	 */
-	public boolean equals(String uri, String prefix) {
-		return (this.nsUri == uri && this.nsPrefix == prefix);
-	}
-
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMNamespace#getPrefix()
-	 */
-	public String getPrefix() {
-		return this.nsPrefix;
-	}
-
-	/* (non-Javadoc)
-	 * @see org.apache.axis2.om.OMNamespace#getName()
-	 */
-	public String getName() {
-		return this.nsUri;
-	}
+    private String nsUri;
+
+    private String nsPrefix;
+
+    public NamespaceImpl(String uri) {
+        this.nsUri = uri;
+    }
+
+    public NamespaceImpl(String uri, String prefix) {
+        this.nsUri = uri;
+        this.nsPrefix = prefix;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis2.om.OMNamespace#equals(java.lang.String,
+     *      java.lang.String)
+     */
+    public boolean equals(String uri, String prefix) {
+        return (this.nsUri == uri && this.nsPrefix == prefix);
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis2.om.OMNamespace#getPrefix()
+     */
+    public String getPrefix() {
+        return this.nsPrefix;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis2.om.OMNamespace#getName()
+     */
+    public String getName() {
+        return this.nsUri;
+    }
 
 }

Modified: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeImpl.java?rev=367519&r1=367518&r2=367519&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeImpl.java (original)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeImpl.java Mon Jan  9 23:53:43 2006
@@ -35,8 +35,7 @@
 import java.io.OutputStream;
 import java.io.Writer;
 
-public abstract class NodeImpl implements Node, NodeList,OMNodeEx, Cloneable {
-
+public abstract class NodeImpl implements Node, NodeList, OMNodeEx, Cloneable {
 
     /**
      * Field builder
@@ -53,19 +52,21 @@
      */
     protected int nodeType;
 
-
-
-
     protected DocumentImpl ownerNode;
 
     // data
 
     protected short flags;
-    protected final static short OWNED        = 0x1<<1;
-    protected final static short FIRSTCHILD   = 0x1<<2;
-    protected final static short READONLY     = 0x1<<3;
-    protected final static short SPECIFIED    = 0x1<<4;
-    protected final static short NORMALIZED   = 0x1<<5;
+
+    protected final static short OWNED = 0x1 << 1;
+
+    protected final static short FIRSTCHILD = 0x1 << 2;
+
+    protected final static short READONLY = 0x1 << 3;
+
+    protected final static short SPECIFIED = 0x1 << 4;
+
+    protected final static short NORMALIZED = 0x1 << 5;
 
     //
     // Constructors
@@ -74,97 +75,92 @@
     protected NodeImpl(DocumentImpl ownerDocument) {
 
         this.ownerNode = ownerDocument;
-//        this.isOwned(true);
+        // this.isOwned(true);
 
     }
 
     protected NodeImpl() {
     }
 
-
-
     public void normalize() {
-        /* by default we do not have any children,
-             ParentNode overrides this behavior */
+        /*
+         * by default we do not have any children, ParentNode overrides this
+         * behavior
+         */
     }
 
-
     public boolean hasAttributes() {
-        return false;           // overridden in ElementImpl
+        return false; // overridden in ElementImpl
     }
 
-
     public boolean hasChildNodes() {
-        return false; //Override in ParentNode
+        return false; // Override in ParentNode
     }
 
-
     public String getLocalName() {
-        return null; //Override in AttrImpl and ElementImpl
+        return null; // Override in AttrImpl and ElementImpl
     }
 
     public String getNamespaceURI() {
-        return null; //Override in AttrImpl and ElementImpl
+        return null; // Override in AttrImpl and ElementImpl
     }
 
-
-
-
     public String getNodeValue() throws DOMException {
         return null;
     }
 
-
     /*
-      * Overidden in ElementImpl and AttrImpl.
-      */
+     * Overidden in ElementImpl and AttrImpl.
+     */
     public String getPrefix() {
         return null;
     }
 
     public void setNodeValue(String arg0) throws DOMException {
-        //Don't do anything, to be overridden in SOME Child classes
+        // Don't do anything, to be overridden in SOME Child classes
     }
 
-
     public void setPrefix(String prefix) throws DOMException {
-        throw new DOMException(DOMException.NAMESPACE_ERR,
-              DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN,
-                 "NAMESPACE_ERR", null));
+        throw new DOMException(DOMException.NAMESPACE_ERR, DOMMessageFormatter
+                .formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NAMESPACE_ERR",
+                        null));
     }
 
     /**
-     * Finds the document that this Node belongs to (the document in
-     * whose context the Node was created). The Node may or may not
+     * Finds the document that this Node belongs to (the document in whose
+     * context the Node was created). The Node may or may not
      */
     public Document getOwnerDocument() {
         return (Document) this.ownerNode;
     }
 
     /**
-     * Returns the collection of attributes associated with this node,
-     * or null if none. At this writing, Element is the only type of node
-     * which will ever have attributes.
-     *
+     * Returns the collection of attributes associated with this node, or null
+     * if none. At this writing, Element is the only type of node which will
+     * ever have attributes.
+     * 
      * @see ElementImpl
      */
     public NamedNodeMap getAttributes() {
         return null; // overridden in ElementImpl
     }
 
-    /** Gets the first child of this Node, or null if none.
+    /**
+     * Gets the first child of this Node, or null if none.
      * <P>
      * By default we do not have any children, ParentNode overrides this.
+     * 
      * @see ParentNode
      */
     public Node getFirstChild() {
         return null;
     }
 
-
-    /** Gets the last child of this Node, or null if none.
+    /**
+     * Gets the last child of this Node, or null if none.
      * <P>
      * By default we do not have any children, ParentNode overrides this.
+     * 
      * @see ParentNode
      */
     public Node getLastChild() {
@@ -173,13 +169,12 @@
 
     /** Returns the next child of this node's parent, or null if none. */
     public Node getNextSibling() {
-        return null;            // default behavior, overriden in ChildNode
+        return null; // default behavior, overriden in ChildNode
     }
 
-
     public Node getParentNode() {
-        return null;            // overriden by ChildNode
-        //Document, DocumentFragment, and Attribute will never have parents.
+        return null; // overriden by ChildNode
+        // Document, DocumentFragment, and Attribute will never have parents.
     }
 
     /*
@@ -191,28 +186,28 @@
 
     /** Returns the previous child of this node's parent, or null if none. */
     public Node getPreviousSibling() {
-        return null;            // default behavior, overriden in ChildNode
+        return null; // default behavior, overriden in ChildNode
     }
 
-//    public Node cloneNode(boolean deep) {
-//    	if(this instanceof OMElement) {
-//    		return (Node)((OMElement)this).cloneOMElement();
-//    	} else if(this instanceof OMText ){
-//    		return ((TextImpl)this).cloneText();
-//    	} else {
-//    		throw new UnsupportedOperationException("Only elements can be cloned right now");
-//    	}
-//    }
-//    
+    // public Node cloneNode(boolean deep) {
+    // if(this instanceof OMElement) {
+    // return (Node)((OMElement)this).cloneOMElement();
+    // } else if(this instanceof OMText ){
+    // return ((TextImpl)this).cloneText();
+    // } else {
+    // throw new UnsupportedOperationException("Only elements can be cloned
+    // right now");
+    // }
+    // }
+    //    
     public Node cloneNode(boolean deep) {
         NodeImpl newnode;
         try {
-            newnode = (NodeImpl)clone();
-        }
-        catch (CloneNotSupportedException e) {
+            newnode = (NodeImpl) clone();
+        } catch (CloneNotSupportedException e) {
             throw new RuntimeException("**Internal Error**" + e);
         }
-        newnode.ownerNode      = this.ownerNode;
+        newnode.ownerNode = this.ownerNode;
         newnode.isOwned(false);
 
         newnode.isReadonly(false);
@@ -220,37 +215,34 @@
         return newnode;
     }
 
-
     /*
-      * (non-Javadoc)
-      * 
-      * @see org.w3c.dom.Node#getChildNodes()
-      */
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#getChildNodes()
+     */
     public NodeList getChildNodes() {
         return this;
     }
 
-    public boolean isSupported(String feature, String version)
-    {
+    public boolean isSupported(String feature, String version) {
         throw new UnsupportedOperationException();
-        //TODO
+        // TODO
     }
 
-
     /*
-      * (non-Javadoc)
-      * 
-      * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node)
-      */
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#appendChild(org.w3c.dom.Node)
+     */
     public Node appendChild(Node newChild) throws DOMException {
         return insertBefore(newChild, null);
     }
 
     /*
-      * (non-Javadoc)
-      * 
-      * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node)
-      */
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#removeChild(org.w3c.dom.Node)
+     */
     public Node removeChild(Node oldChild) throws DOMException {
         throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessageFormatter
                 .formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR",
@@ -258,12 +250,12 @@
     }
 
     /*
-      * (non-Javadoc)
-      * 
-      * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)
-      */
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#insertBefore(org.w3c.dom.Node, org.w3c.dom.Node)
+     */
     public Node insertBefore(Node newChild, Node refChild) throws DOMException {
-        //Overridden in ParentNode
+        // Overridden in ParentNode
         throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                 DOMMessageFormatter.formatMessage(
                         DOMMessageFormatter.DOM_DOMAIN,
@@ -272,10 +264,10 @@
     }
 
     /*
-      * (non-Javadoc)
-      * 
-      * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)
-      */
+     * (non-Javadoc)
+     * 
+     * @see org.w3c.dom.Node#replaceChild(org.w3c.dom.Node, org.w3c.dom.Node)
+     */
     public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
         throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                 DOMMessageFormatter.formatMessage(
@@ -283,8 +275,6 @@
                         "HIERARCHY_REQUEST_ERR", null));
     }
 
-
-
     //
     // NodeList methods
     //
@@ -293,8 +283,9 @@
      * NodeList method: Returns the number of immediate children of this node.
      * <P>
      * By default we do not have any children, ParentNode overrides this.
+     * 
      * @see ParentNode
-     *
+     * 
      * @return Returns int.
      */
     public int getLength() {
@@ -302,12 +293,13 @@
     }
 
     /**
-     * NodeList method: Returns the Nth immediate child of this node, or
-     * null if the index is out of bounds.
+     * NodeList method: Returns the Nth immediate child of this node, or null if
+     * the index is out of bounds.
      * <P>
      * By default we do not have any children, ParentNode overrides this.
+     * 
      * @see ParentNode
-     *
+     * 
      * @return Returns org.w3c.dom.Node
      * @param index
      */
@@ -315,13 +307,9 @@
         return null;
     }
 
-
-
-
     /*
-    * Flags setters and getters
-    */
-
+     * Flags setters and getters
+     */
 
     final boolean isOwned() {
         return (flags & OWNED) != 0;
@@ -364,24 +352,28 @@
         if (!value && isNormalized() && ownerNode != null) {
             ownerNode.isNormalized(false);
         }
-        flags = (short) (value ?  flags | NORMALIZED : flags & ~NORMALIZED);
+        flags = (short) (value ? flags | NORMALIZED : flags & ~NORMALIZED);
     }
 
-    ///
-    ///OM Methods
-    ///
+    // /
+    // /OM Methods
+    // /
 
-    /* (non-Javadoc)
-      * @see org.apache.axis.om.OMNode#getParent()
-      */
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis.om.OMNode#getParent()
+     */
     public OMContainer getParent() throws OMException {
         return null; // overriden by ChildNode
-        //Document, DocumentFragment, and Attribute will never have parents.
+        // Document, DocumentFragment, and Attribute will never have parents.
     }
 
-    /* (non-Javadoc)
-      * @see org.apache.axis.om.OMNode#isComplete()
-      */
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis.om.OMNode#isComplete()
+     */
     public boolean isComplete() {
         return this.done;
     }
@@ -394,15 +386,19 @@
     /**
      * There no concept of caching in this OM-DOM implementation.
      */
-    public void serializeWithCache(OMOutputImpl omOutput) throws XMLStreamException {
+    public void serializeWithCache(OMOutputImpl omOutput)
+            throws XMLStreamException {
         this.serialize(omOutput);
     }
 
-    /* (non-Javadoc)
-      * @see org.apache.axis.om.OMNode#insertSiblingAfter(org.apache.axis.om.OMNode)
-      */
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis.om.OMNode#insertSiblingAfter
+     * (org.apache.axis.om.OMNode)
+     */
     public void insertSiblingAfter(OMNode sibling) throws OMException {
-        //Overridden in ChildNode
+        // Overridden in ChildNode
         throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                 DOMMessageFormatter.formatMessage(
                         DOMMessageFormatter.DOM_DOMAIN,
@@ -410,11 +406,14 @@
 
     }
 
-    /* (non-Javadoc)
-      * @see org.apache.axis.om.OMNode#insertSiblingBefore(org.apache.axis.om.OMNode)
-      */
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.apache.axis.om.OMNode#insertSiblingBefore
+     * (org.apache.axis.om.OMNode)
+     */
     public void insertSiblingBefore(OMNode sibling) throws OMException {
-        //Overridden in ChildNode
+        // Overridden in ChildNode
         throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                 DOMMessageFormatter.formatMessage(
                         DOMMessageFormatter.DOM_DOMAIN,
@@ -422,8 +421,6 @@
 
     }
 
-
-
     /**
      * Default behavior returns null, overriden in ChildNode.
      */
@@ -462,6 +459,7 @@
 
     /**
      * Sets the owner document.
+     * 
      * @param document
      */
     protected void setOwnerDocument(DocumentImpl document) {
@@ -475,7 +473,8 @@
         omOutput.flush();
     }
 
-    public void serializeAndConsume(XMLStreamWriter xmlWriter) throws XMLStreamException {
+    public void serializeAndConsume(XMLStreamWriter xmlWriter)
+            throws XMLStreamException {
         OMOutputImpl omOutput = new OMOutputImpl(xmlWriter);
         serializeAndConsume(omOutput);
         omOutput.flush();
@@ -483,12 +482,12 @@
 
     public OMNode detach() {
         throw new OMException(
-                    "Elements that doesn't have a parent can not be detached");
+                "Elements that doesn't have a parent can not be detached");
     }
 
     /*
-      * DOM-Level 3 methods 
-      */
+     * DOM-Level 3 methods
+     */
 
     public String getBaseURI() {
         // TODO TODO
@@ -558,35 +557,44 @@
         serialize(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
     }
 
-    public void serializeAndConsume(OutputStream output) throws XMLStreamException {
-        serializeAndConsume(XMLOutputFactory.newInstance().createXMLStreamWriter(output));
+    public void serializeAndConsume(OutputStream output)
+            throws XMLStreamException {
+        serializeAndConsume(XMLOutputFactory.newInstance()
+                .createXMLStreamWriter(output));
     }
 
     public void serializeAndConsume(Writer writer) throws XMLStreamException {
-        serializeAndConsume(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
+        serializeAndConsume(XMLOutputFactory.newInstance()
+                .createXMLStreamWriter(writer));
     }
 
-    public void serialize(OutputStream output, OMOutputFormat format) throws XMLStreamException {    
-        OMOutputImpl omOutput = new  OMOutputImpl(output, format);
+    public void serialize(OutputStream output, OMOutputFormat format)
+            throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(output, format);
         serialize(omOutput);
         omOutput.flush();
     }
 
-    public void serialize(Writer writer, OMOutputFormat format) throws XMLStreamException {
-        OMOutputImpl omOutput = new  OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
+    public void serialize(Writer writer, OMOutputFormat format)
+            throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(XMLOutputFactory.newInstance()
+                .createXMLStreamWriter(writer));
         omOutput.setOutputFormat(format);
         serialize(omOutput);
         omOutput.flush();
     }
 
-    public void serializeAndConsume(OutputStream output, OMOutputFormat format) throws XMLStreamException {
-        OMOutputImpl omOutput = new  OMOutputImpl(output, format);
+    public void serializeAndConsume(OutputStream output, OMOutputFormat format)
+            throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(output, format);
         serializeAndConsume(omOutput);
         omOutput.flush();
     }
 
-    public void serializeAndConsume(Writer writer, OMOutputFormat format) throws XMLStreamException {
-        OMOutputImpl omOutput = new  OMOutputImpl(XMLOutputFactory.newInstance().createXMLStreamWriter(writer));
+    public void serializeAndConsume(Writer writer, OMOutputFormat format)
+            throws XMLStreamException {
+        OMOutputImpl omOutput = new OMOutputImpl(XMLOutputFactory.newInstance()
+                .createXMLStreamWriter(writer));
         omOutput.setOutputFormat(format);
         serializeAndConsume(omOutput);
         omOutput.flush();

Modified: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeListImpl.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeListImpl.java?rev=367519&r1=367518&r2=367519&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeListImpl.java (original)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/NodeListImpl.java Mon Jan  9 23:53:43 2006
@@ -26,87 +26,106 @@
 /**
  * Implementation of org.w3c.dom.NodeList
  */
-public class NodeListImpl implements NodeList  {
-	
-    protected NodeImpl rootNode; 
-    protected String tagName;  
+public class NodeListImpl implements NodeList {
+
+    protected NodeImpl rootNode;
+
+    protected String tagName;
+
     protected Vector nodes;
-    
+
     protected String nsName;
+
     protected boolean enableNS = false;
-	
-	
+
     /** Constructor. */
     public NodeListImpl(NodeImpl rootNode, String tagName) {
         this.rootNode = rootNode;
-        this.tagName  = (tagName != null && !tagName.equals("")) ? tagName : null;
+        this.tagName = (tagName != null && !tagName.equals("")) ? tagName
+                : null;
         nodes = new Vector();
-    }  
+    }
 
     /** Constructor for Namespace support. */
-    public NodeListImpl(NodeImpl rootNode,
-                            String namespaceURI, String localName) {
+    public NodeListImpl(NodeImpl rootNode, String namespaceURI, 
+                                                    String localName) {
         this(rootNode, localName);
-        this.nsName = (namespaceURI != null && !namespaceURI.equals("")) ? namespaceURI : null;
-        if(this.nsName != null) {
-        	enableNS = true;
+        this.nsName = (namespaceURI != null && !namespaceURI.equals("")) 
+                       ? namespaceURI
+                       : null;
+        if (this.nsName != null) {
+            enableNS = true;
+        }
+    }
+
+    /**
+     * Returns the number of nodes.
+     * 
+     * @see org.w3c.dom.NodeList#getLength()
+     */
+    public int getLength() {
+        Iterator children;
+        if (this.tagName == null) {
+            children = ((OMContainerEx) rootNode).getChildren();
+        } else if (!enableNS) {
+            children = ((OMContainerEx) rootNode)
+                    .getChildrenWithName(new QName(this.tagName));
+        } else {
+            if (DOMUtil.getPrefix(this.tagName) != null) {
+                children = ((OMContainerEx) rootNode)
+                        .getChildrenWithName(new QName(this.nsName, DOMUtil
+                                .getLocalName(this.tagName), DOMUtil
+                                .getPrefix(this.tagName)));
+            } else {
+                children = ((OMContainerEx) rootNode)
+                        .getChildrenWithName(new QName(this.nsName, DOMUtil
+                                .getLocalName(this.tagName)));
+            }
         }
+        int count = 0;
+        while (children.hasNext()) {
+            count++;
+            children.next();
+        }
+        return count;
     }
 
-	/**
-	 * Returns the number of nodes.
-	 * @see org.w3c.dom.NodeList#getLength()
-	 */
-	public int getLength() {
-		Iterator children;
-		if(this.tagName == null) {
-			children = ((OMContainerEx)rootNode).getChildren();
-		} else if(!enableNS) {
-			children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.tagName));
-		} else {
-			if(DOMUtil.getPrefix(this.tagName) != null) {
-				children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.nsName, DOMUtil.getLocalName(this.tagName), DOMUtil.getPrefix(this.tagName)));
-			} else {
-				children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.nsName, DOMUtil.getLocalName(this.tagName)));
-			}
-		}
-		int count  = 0;
-		while (children.hasNext()) {
-			count++;
-			children.next();
-		}
-		return count;
-	}
-
-	/**
-	 * Returns the node at the given index.
-	 * Returns null if the index is invalid. 
-	 * @see org.w3c.dom.NodeList#item(int)
-	 */
-	public Node item(int index) {
-		Iterator children;
-
-		if(this.tagName == null) {
-			children = ((OMContainerEx)rootNode).getChildren();
-		} else if(!enableNS) {
-			children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.tagName));
-		} else {
-			if(DOMUtil.getPrefix(this.tagName) != null) {
-				children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.nsName, DOMUtil.getLocalName(this.tagName), DOMUtil.getPrefix(this.tagName)));
-			} else {
-				children = ((OMContainerEx)rootNode).getChildrenWithName(new QName(this.nsName, DOMUtil.getLocalName(this.tagName)));
-			}
-		}
-
-		int count  = 0;
-		while (children.hasNext()) {
-			if(count == index) {
-				return (Node)children.next();
-			} else {
-				children.next();
-			}
-			count++;
-		}
-		return null;
-	}
+    /**
+     * Returns the node at the given index. Returns null if the index is
+     * invalid.
+     * 
+     * @see org.w3c.dom.NodeList#item(int)
+     */
+    public Node item(int index) {
+        Iterator children;
+
+        if (this.tagName == null) {
+            children = ((OMContainerEx) rootNode).getChildren();
+        } else if (!enableNS) {
+            children = ((OMContainerEx) rootNode)
+                    .getChildrenWithName(new QName(this.tagName));
+        } else {
+            if (DOMUtil.getPrefix(this.tagName) != null) {
+                children = ((OMContainerEx) rootNode)
+                        .getChildrenWithName(new QName(this.nsName, DOMUtil
+                                .getLocalName(this.tagName), DOMUtil
+                                .getPrefix(this.tagName)));
+            } else {
+                children = ((OMContainerEx) rootNode)
+                        .getChildrenWithName(new QName(this.nsName, DOMUtil
+                                .getLocalName(this.tagName)));
+            }
+        }
+
+        int count = 0;
+        while (children.hasNext()) {
+            if (count == index) {
+                return (Node) children.next();
+            } else {
+                children.next();
+            }
+            count++;
+        }
+        return null;
+    }
 }

Modified: webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/ParentNode.java?rev=367519&r1=367518&r2=367519&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/ParentNode.java (original)
+++ webservices/axis2/trunk/java/modules/doom/src/org/apache/axis2/om/impl/dom/ParentNode.java Mon Jan  9 23:53:43 2006
@@ -32,413 +32,414 @@
 
 public abstract class ParentNode extends ChildNode implements OMContainerEx {
 
+    protected ChildNode firstChild;
 
-	protected ChildNode firstChild;
-	
-	protected ChildNode lastChild;
-	
-
-	
-	/**
-	 * @param ownerDocument
-	 */
-	protected ParentNode(DocumentImpl ownerDocument) {
-		super(ownerDocument);
-	}
-	
-	protected ParentNode() {
-	}
-	
-	// /
-	// /OMContainer methods
-	///
-	
-	public void addChild(OMNode omNode) {
-		this.appendChild((Node)omNode);
-	}
-	
-	
-	public void buildNext() {
-		if(!this.done)
-			builder.next();
-	}
-	
-	public Iterator getChildren() {
-		return new OMChildrenIterator(this.firstChild);
-	}
-	
-	/**
-	 * Returns an iterator of child nodes having a given qname.
-	 * @see org.apache.axis2.om.OMContainer#getChildrenWithName(javax.xml.namespace.QName)
-	 */
-	public Iterator getChildrenWithName(QName elementQName) throws OMException {
-		return new OMChildrenQNameIterator(getFirstOMChild(),
-                elementQName);
-	}
-	
-	/**
-	 * Returns the first OMElement child node.
-	 * @see org.apache.axis2.om.OMContainer#getFirstChildWithName(javax.xml.namespace.QName)
-	 */
-	public OMElement getFirstChildWithName(QName elementQName)
-			throws OMException {
-		Iterator children = new OMChildrenQNameIterator(getFirstOMChild(),
+    protected ChildNode lastChild;
+
+    /**
+     * @param ownerDocument
+     */
+    protected ParentNode(DocumentImpl ownerDocument) {
+        super(ownerDocument);
+    }
+
+    protected ParentNode() {
+    }
+
+    // /
+    // /OMContainer methods
+    // /
+
+    public void addChild(OMNode omNode) {
+        this.appendChild((Node) omNode);
+    }
+
+    public void buildNext() {
+        if (!this.done)
+            builder.next();
+    }
+
+    public Iterator getChildren() {
+        return new OMChildrenIterator(this.firstChild);
+    }
+
+    /**
+     * Returns an iterator of child nodes having a given qname.
+     * 
+     * @see org.apache.axis2.om.OMContainer#getChildrenWithName
+     * (javax.xml.namespace.QName)
+     */
+    public Iterator getChildrenWithName(QName elementQName) throws OMException {
+        return new OMChildrenQNameIterator(getFirstOMChild(), elementQName);
+    }
+
+    /**
+     * Returns the first OMElement child node.
+     * 
+     * @see org.apache.axis2.om.OMContainer#getFirstChildWithName
+     * (javax.xml.namespace.QName)
+     */
+    public OMElement getFirstChildWithName(QName elementQName)
+            throws OMException {
+        Iterator children = new OMChildrenQNameIterator(getFirstOMChild(),
                 elementQName);
-		while (children.hasNext()) {
-			OMNode node = (OMNode) children.next();
-			
-			//Return the first OMElement node that is found
-			if(node instanceof OMElement) {
-				return (OMElement)node;
-			}
-		}
-		return null;
-	}
-	
-	public OMNode getFirstOMChild() {
+        while (children.hasNext()) {
+            OMNode node = (OMNode) children.next();
+
+            // Return the first OMElement node that is found
+            if (node instanceof OMElement) {
+                return (OMElement) node;
+            }
+        }
+        return null;
+    }
+
+    public OMNode getFirstOMChild() {
         while ((firstChild == null) && !done) {
             buildNext();
         }
         return firstChild;
-	}
-	
-	public void setFirstChild(OMNode omNode) {
+    }
+
+    public void setFirstChild(OMNode omNode) {
         if (firstChild != null) {
             ((OMNodeEx) omNode).setParent(this);
         }
-        this.firstChild = (ChildNode)omNode;
-	}
-	
-	
-	///
-	///DOM Node methods
-	///	
-	
-	public NodeList getChildNodes() {
-		if (!this.done) {
-			this.build();
-		}
-		return new NodeListImpl(this, null,null);
-	}
-	
-	public Node getFirstChild() {
-		return (Node)this.getFirstOMChild();
-	}
-	
-	public Node getLastChild() {
-		if(!this.done) {
-			this.build();
-		}
-		return this.lastChild;
-	}
-			
-	public boolean hasChildNodes() {
+        this.firstChild = (ChildNode) omNode;
+    }
+
+    // /
+    // /DOM Node methods
+    // /
+
+    public NodeList getChildNodes() {
+        if (!this.done) {
+            this.build();
+        }
+        return new NodeListImpl(this, null, null);
+    }
+
+    public Node getFirstChild() {
+        return (Node) this.getFirstOMChild();
+    }
+
+    public Node getLastChild() {
+        if (!this.done) {
+            this.build();
+        }
+        return this.lastChild;
+    }
+
+    public boolean hasChildNodes() {
         while ((firstChild == null) && !done) {
             buildNext();
         }
-		return this.firstChild != null;
-	}
-	
-	/**
-	 * Inserts newChild before the refChild.
-	 * If the refChild is null then the newChild is made the last child.  
-	 */
-	public Node insertBefore(Node newChild, Node refChild) throws DOMException {
-	
-		ChildNode newDomChild = (ChildNode)newChild;
-		ChildNode refDomChild = (ChildNode)refChild;
-		
-		if(this == newChild || !isAncestor(newChild)) {
-			throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
-					DOMMessageFormatter.formatMessage(
-							DOMMessageFormatter.DOM_DOMAIN,
-							"HIERARCHY_REQUEST_ERR", null));
-		}
-		
-		if(!(this instanceof Document) && !(this.ownerNode == newDomChild.getOwnerDocument())) {
-			throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
-					DOMMessageFormatter.formatMessage(
-							DOMMessageFormatter.DOM_DOMAIN,
-							"WRONG_DOCUMENT_ERR", null));			
-		}
-		
-		if(this.isReadonly()) {
-			throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
-					DOMMessageFormatter.formatMessage(
-							DOMMessageFormatter.DOM_DOMAIN,
-							"NO_MODIFICATION_ALLOWED_ERR", null));
-		}
-		
-		if(this instanceof Document) {
-			if(((DocumentImpl)this).documentElement != null && !(newDomChild instanceof CommentImpl)) {
-				//Throw exception since there cannot be two document elements
-				throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
-						DOMMessageFormatter.formatMessage(
-								DOMMessageFormatter.DOM_DOMAIN,
-								"HIERARCHY_REQUEST_ERR", null));
-			} else if(newDomChild instanceof ElementImpl) {
-				if(newDomChild.parentNode == null) {
-					newDomChild.parentNode = this;
-				}
-				//set the document element
-				((DocumentImpl)this).documentElement = (ElementImpl)newDomChild;
-			}
-		}
-		
-		if(refChild == null) { //Append the child to the end of the list
-			//if there are no children 
-			if(this.lastChild == null && firstChild == null ) {
-				this.lastChild = newDomChild;
-				this.firstChild = newDomChild;
-				this.firstChild.isFirstChild(true);
-				newDomChild.setParent(this);
-			} else {
-				this.lastChild.nextSibling = newDomChild;
-				newDomChild.previousSibling = this.lastChild;
-			
-				this.lastChild = newDomChild;
-			}
-			if(newDomChild.parentNode == null) {
-				newDomChild.parentNode = this;
-			}
-			return newChild;
-		} else {
-			Iterator children = this.getChildren(); 
-			boolean found = false;
-			while(children.hasNext()) {
-				ChildNode tempNode = (ChildNode)children.next();
-				
-				if(tempNode.equals(refChild)) { 
-					//RefChild found
-					if(tempNode.isFirstChild()) { //If the refChild is the first child
-						
-						if(newChild instanceof DocumentFragmentimpl) {
-							//The new child is a DocumentFragment
-							DocumentFragmentimpl docFrag = (DocumentFragmentimpl)newChild;
-							this.firstChild = docFrag.firstChild;
-							docFrag.lastChild.nextSibling = refDomChild;
-							refDomChild.previousSibling = docFrag.lastChild.nextSibling; 
-							
-						} else {
-							
-							//Make the newNode the first Child
-							this.firstChild = newDomChild;
-							
-							newDomChild.nextSibling = refDomChild;
-							refDomChild.previousSibling = newDomChild;
-							
-							this.firstChild.isFirstChild(true);
-							refDomChild.isFirstChild(false);
-							newDomChild.previousSibling = null; //Just to be sure :-)
-							
-						}
-					} else { //If the refChild is not the fist child
-						ChildNode previousNode = refDomChild.previousSibling;
-						
-						if(newChild instanceof DocumentFragmentimpl) {
-							//the newChild is a document fragment
-							DocumentFragmentimpl docFrag = (DocumentFragmentimpl)newChild;
-							
-							previousNode.nextSibling = docFrag.firstChild;
-							docFrag.firstChild.previousSibling = previousNode;
-							
-							docFrag.lastChild.nextSibling = refDomChild;
-							refDomChild.previousSibling = docFrag.lastChild;
-						} else {
-							
-							previousNode.nextSibling = newDomChild;
-							newDomChild.previousSibling = previousNode;
-							
-							newDomChild.nextSibling = refDomChild;
-							refDomChild.previousSibling = newDomChild;
-						}
-						
-					}
-					found = true;
-					break;
-				}
-			}
-			
-			if(!found) {
-				throw new DOMException(DOMException.NOT_FOUND_ERR,
-						DOMMessageFormatter.formatMessage(
-								DOMMessageFormatter.DOM_DOMAIN,
-								"NOT_FOUND_ERR", null));
-			}
-			
-			if(newDomChild.parentNode == null) {
-				newDomChild.parentNode = this;
-			}
-			
-			return newChild;
-		}
-	}
-	
-	/**
-	 * Replaces the oldChild with the newChild.
-	 */
-	public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
-		ChildNode newDomChild = (ChildNode)newChild;
-		ChildNode oldDomChild = (ChildNode)oldChild;
-		
-		if(this == newChild || !isAncestor(newChild)) {
-				throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
-						DOMMessageFormatter.formatMessage(
-								DOMMessageFormatter.DOM_DOMAIN,
-								"HIERARCHY_REQUEST_ERR", null));
-		}
-		
-		if(!this.ownerNode.equals(newDomChild.ownerNode)) {
-			throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
-					DOMMessageFormatter.formatMessage(
-							DOMMessageFormatter.DOM_DOMAIN,
-							"WRONG_DOCUMENT_ERR", null));			
-		}
-		
-		if (this.isReadonly()) { 
-			throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
-					DOMMessageFormatter.formatMessage(
-							DOMMessageFormatter.DOM_DOMAIN,
-							"NO_MODIFICATION_ALLOWED_ERR", null));
-		}
-		
-		Iterator children = this.getChildren(); 
-		boolean found = false;
-		while(children.hasNext()) {
-			ChildNode tempNode = (ChildNode)children.next();
-			if(tempNode.equals(oldChild)) {
-				if(newChild instanceof DocumentFragmentimpl) {
-					DocumentFragmentimpl docFrag = (DocumentFragmentimpl)newDomChild;
-					ChildNode child = (ChildNode)docFrag.getFirstChild();
-					child.parentNode = this;
-					this.replaceChild(child, oldChild);
-				} else {
-					if(oldDomChild.isFirstChild()) {
-						oldDomChild.detach();
-						this.addChild(newDomChild);
-					} else {
-						newDomChild.nextSibling = oldDomChild.nextSibling;
-						newDomChild.previousSibling = oldDomChild.previousSibling;
-						
-						oldDomChild.previousSibling.nextSibling = newDomChild;
-						
-						//If the old child is not the last
-						if(oldDomChild.nextSibling != null) {
-							oldDomChild.nextSibling.previousSibling = newDomChild;
-						} else {
-							this.lastChild = newDomChild;
-						}
-						
-						if(newDomChild.parentNode == null) {
-							newDomChild.parentNode = this;
-						}
-					}
-				}
-				found = true;
-				
-				//remove the old child's references to this tree
-				oldDomChild.nextSibling = null;
-				oldDomChild.previousSibling = null;
-				oldDomChild.parentNode = null;
-			}	
-		}
-		
-		
-		if(!found) 
-			throw new DOMException(DOMException.NOT_FOUND_ERR,
-					DOMMessageFormatter.formatMessage(
-							DOMMessageFormatter.DOM_DOMAIN,
-							"NOT_FOUND_ERR", null));
-		
-		return oldChild;
-	}
-	
-	
-	/**
-	 * Removes the given child from the DOM Tree.
-	 */
-	public Node removeChild(Node oldChild) throws DOMException {
-		//Check if this node is readonly
-		if(this.isReadonly()) {
-			throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
-					DOMMessageFormatter.formatMessage(
-							DOMMessageFormatter.DOM_DOMAIN,
-							"NO_MODIFICATION_ALLOWED_ERR", null));
-		}
-		
-		//Check if the Child is there
-		Iterator children = this.getChildren();
-		boolean childFound = false;
-		while(children.hasNext()) {
-			ChildNode tempNode = (ChildNode)children.next();
-			if(tempNode.equals(oldChild)) {
-				
-				if(tempNode.isFirstChild()) {
-					//If this is the first child
-					this.firstChild = null;
-					this.lastChild = null;
-					tempNode.parentNode = null;
-				} else if (this.lastChild == tempNode) {
-					//not the first child, but the last child 
-					ChildNode prevSib = tempNode.previousSibling;
-					prevSib.nextSibling = null;
-					tempNode.parentNode = null;
-					tempNode.previousSibling = null;
-				} else {
-	
-					ChildNode oldDomChild = (ChildNode)oldChild;
-					ChildNode privChild = oldDomChild.previousSibling;
-					
-					privChild.nextSibling = oldDomChild.nextSibling;
-					oldDomChild.nextSibling.previousSibling = privChild;
-					
-					//Remove old child's references to this tree
-					oldDomChild.nextSibling = null;
-					oldDomChild.previousSibling = null;
-				}
-				//Child found
-				childFound = true;
-			}
-		}
-		
-		if(!childFound) 
-			throw new DOMException(DOMException.NOT_FOUND_ERR,
-					DOMMessageFormatter.formatMessage(
-							DOMMessageFormatter.DOM_DOMAIN,
-							"NOT_FOUND_ERR", null));
-		
-		return oldChild;
-	}
-
-	
-	
-	private boolean isAncestor(Node newNode) {
-		
-		//TODO isAncestor
-		return true;
-	}
-	
+        return this.firstChild != null;
+    }
+
+    /**
+     * Inserts newChild before the refChild. If the refChild is null then the
+     * newChild is made the last child.
+     */
+    public Node insertBefore(Node newChild, Node refChild) throws DOMException {
+
+        ChildNode newDomChild = (ChildNode) newChild;
+        ChildNode refDomChild = (ChildNode) refChild;
+
+        if (this == newChild || !isAncestor(newChild)) {
+            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                    DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN,
+                            "HIERARCHY_REQUEST_ERR", null));
+        }
+
+        if (!(this instanceof Document)
+                && !(this.ownerNode == newDomChild.getOwnerDocument())) {
+            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
+                    DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN,
+                            "WRONG_DOCUMENT_ERR", null));
+        }
+
+        if (this.isReadonly()) {
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN,
+                            "NO_MODIFICATION_ALLOWED_ERR", null));
+        }
+
+        if (this instanceof Document) {
+            if (((DocumentImpl) this).documentElement != null
+                    && !(newDomChild instanceof CommentImpl)) {
+                // Throw exception since there cannot be two document elements
+                throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                        DOMMessageFormatter.formatMessage(
+                                DOMMessageFormatter.DOM_DOMAIN,
+                                "HIERARCHY_REQUEST_ERR", null));
+            } else if (newDomChild instanceof ElementImpl) {
+                if (newDomChild.parentNode == null) {
+                    newDomChild.parentNode = this;
+                }
+                // set the document element
+                ((DocumentImpl) this).documentElement = (ElementImpl) newDomChild;
+            }
+        }
+
+        if (refChild == null) { // Append the child to the end of the list
+            // if there are no children
+            if (this.lastChild == null && firstChild == null) {
+                this.lastChild = newDomChild;
+                this.firstChild = newDomChild;
+                this.firstChild.isFirstChild(true);
+                newDomChild.setParent(this);
+            } else {
+                this.lastChild.nextSibling = newDomChild;
+                newDomChild.previousSibling = this.lastChild;
+
+                this.lastChild = newDomChild;
+            }
+            if (newDomChild.parentNode == null) {
+                newDomChild.parentNode = this;
+            }
+            return newChild;
+        } else {
+            Iterator children = this.getChildren();
+            boolean found = false;
+            while (children.hasNext()) {
+                ChildNode tempNode = (ChildNode) children.next();
+
+                if (tempNode.equals(refChild)) {
+                    // RefChild found
+                    if (tempNode.isFirstChild()) { // If the refChild is the
+                                                    // first child
+
+                        if (newChild instanceof DocumentFragmentimpl) {
+                            // The new child is a DocumentFragment
+                            DocumentFragmentimpl docFrag = 
+                                                (DocumentFragmentimpl) newChild;
+                            this.firstChild = docFrag.firstChild;
+                            docFrag.lastChild.nextSibling = refDomChild;
+                            refDomChild.previousSibling = 
+                                                docFrag.lastChild.nextSibling;
+
+                        } else {
+
+                            // Make the newNode the first Child
+                            this.firstChild = newDomChild;
+
+                            newDomChild.nextSibling = refDomChild;
+                            refDomChild.previousSibling = newDomChild;
+
+                            this.firstChild.isFirstChild(true);
+                            refDomChild.isFirstChild(false);
+                            newDomChild.previousSibling = null; // Just to be
+                                                                // sure :-)
+
+                        }
+                    } else { // If the refChild is not the fist child
+                        ChildNode previousNode = refDomChild.previousSibling;
+
+                        if (newChild instanceof DocumentFragmentimpl) {
+                            // the newChild is a document fragment
+                            DocumentFragmentimpl docFrag = 
+                                                (DocumentFragmentimpl) newChild;
+
+                            previousNode.nextSibling = docFrag.firstChild;
+                            docFrag.firstChild.previousSibling = previousNode;
+
+                            docFrag.lastChild.nextSibling = refDomChild;
+                            refDomChild.previousSibling = docFrag.lastChild;
+                        } else {
+
+                            previousNode.nextSibling = newDomChild;
+                            newDomChild.previousSibling = previousNode;
+
+                            newDomChild.nextSibling = refDomChild;
+                            refDomChild.previousSibling = newDomChild;
+                        }
+
+                    }
+                    found = true;
+                    break;
+                }
+            }
+
+            if (!found) {
+                throw new DOMException(DOMException.NOT_FOUND_ERR,
+                        DOMMessageFormatter.formatMessage(
+                                DOMMessageFormatter.DOM_DOMAIN,
+                                "NOT_FOUND_ERR", null));
+            }
+
+            if (newDomChild.parentNode == null) {
+                newDomChild.parentNode = this;
+            }
+
+            return newChild;
+        }
+    }
+
+    /**
+     * Replaces the oldChild with the newChild.
+     */
+    public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
+        ChildNode newDomChild = (ChildNode) newChild;
+        ChildNode oldDomChild = (ChildNode) oldChild;
+
+        if (this == newChild || !isAncestor(newChild)) {
+            throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                    DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN,
+                            "HIERARCHY_REQUEST_ERR", null));
+        }
+
+        if (!this.ownerNode.equals(newDomChild.ownerNode)) {
+            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
+                    DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN,
+                            "WRONG_DOCUMENT_ERR", null));
+        }
+
+        if (this.isReadonly()) {
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN,
+                            "NO_MODIFICATION_ALLOWED_ERR", null));
+        }
+
+        Iterator children = this.getChildren();
+        boolean found = false;
+        while (children.hasNext()) {
+            ChildNode tempNode = (ChildNode) children.next();
+            if (tempNode.equals(oldChild)) {
+                if (newChild instanceof DocumentFragmentimpl) {
+                    DocumentFragmentimpl docFrag = 
+                                            (DocumentFragmentimpl) newDomChild;
+                    ChildNode child = (ChildNode) docFrag.getFirstChild();
+                    child.parentNode = this;
+                    this.replaceChild(child, oldChild);
+                } else {
+                    if (oldDomChild.isFirstChild()) {
+                        oldDomChild.detach();
+                        this.addChild(newDomChild);
+                    } else {
+                        newDomChild.nextSibling = oldDomChild.nextSibling;
+                        newDomChild.previousSibling = oldDomChild.previousSibling;
+
+                        oldDomChild.previousSibling.nextSibling = newDomChild;
+
+                        // If the old child is not the last
+                        if (oldDomChild.nextSibling != null) {
+                            oldDomChild.nextSibling.previousSibling = newDomChild;
+                        } else {
+                            this.lastChild = newDomChild;
+                        }
+
+                        if (newDomChild.parentNode == null) {
+                            newDomChild.parentNode = this;
+                        }
+                    }
+                }
+                found = true;
+
+                // remove the old child's references to this tree
+                oldDomChild.nextSibling = null;
+                oldDomChild.previousSibling = null;
+                oldDomChild.parentNode = null;
+            }
+        }
+
+        if (!found)
+            throw new DOMException(DOMException.NOT_FOUND_ERR,
+                    DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR",
+                            null));
+
+        return oldChild;
+    }
+
+    /**
+     * Removes the given child from the DOM Tree.
+     */
+    public Node removeChild(Node oldChild) throws DOMException {
+        // Check if this node is readonly
+        if (this.isReadonly()) {
+            throw new DOMException(DOMException.NO_MODIFICATION_ALLOWED_ERR,
+                    DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN,
+                            "NO_MODIFICATION_ALLOWED_ERR", null));
+        }
+
+        // Check if the Child is there
+        Iterator children = this.getChildren();
+        boolean childFound = false;
+        while (children.hasNext()) {
+            ChildNode tempNode = (ChildNode) children.next();
+            if (tempNode.equals(oldChild)) {
+
+                if (tempNode.isFirstChild()) {
+                    // If this is the first child
+                    this.firstChild = null;
+                    this.lastChild = null;
+                    tempNode.parentNode = null;
+                } else if (this.lastChild == tempNode) {
+                    // not the first child, but the last child
+                    ChildNode prevSib = tempNode.previousSibling;
+                    prevSib.nextSibling = null;
+                    tempNode.parentNode = null;
+                    tempNode.previousSibling = null;
+                } else {
+
+                    ChildNode oldDomChild = (ChildNode) oldChild;
+                    ChildNode privChild = oldDomChild.previousSibling;
+
+                    privChild.nextSibling = oldDomChild.nextSibling;
+                    oldDomChild.nextSibling.previousSibling = privChild;
+
+                    // Remove old child's references to this tree
+                    oldDomChild.nextSibling = null;
+                    oldDomChild.previousSibling = null;
+                }
+                // Child found
+                childFound = true;
+            }
+        }
+
+        if (!childFound)
+            throw new DOMException(DOMException.NOT_FOUND_ERR,
+                    DOMMessageFormatter.formatMessage(
+                            DOMMessageFormatter.DOM_DOMAIN, "NOT_FOUND_ERR",
+                            null));
+
+        return oldChild;
+    }
+
+    private boolean isAncestor(Node newNode) {
+
+        // TODO isAncestor
+        return true;
+    }
+
     public Node cloneNode(boolean deep) {
 
-    	ParentNode newnode = (ParentNode) super.cloneNode(deep);
+        ParentNode newnode = (ParentNode) super.cloneNode(deep);
 
         // set owner document
         newnode.ownerNode = ownerNode;
 
-    	// Need to break the association w/ original kids
-    	newnode.firstChild = null;
-    	newnode.lastChild = null;
+        // Need to break the association w/ original kids
+        newnode.firstChild = null;
+        newnode.lastChild = null;
 
         // Then, if deep, clone the kids too.
-    	if (deep) {
-            for (ChildNode child = firstChild;
-                 child != null;
-                 child = child.nextSibling) {
+        if (deep) {
+            for (ChildNode child = firstChild; child != null; 
+                    child = child.nextSibling) {
                 newnode.appendChild(child.cloneNode(true));
             }
         }
 
-    	return newnode;
+        return newnode;
 
     }
 }



Mime
View raw message