You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2012/05/28 21:37:05 UTC

svn commit: r1343373 - in /webservices/commons/trunk/modules/axiom/modules: axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/ axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/ axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/

Author: veithen
Date: Mon May 28 19:37:05 2012
New Revision: 1343373

URL: http://svn.apache.org/viewvc?rev=1343373&view=rev
Log:
Avoid unnecessary overrides: instead of defining a method in NodeImpl and then overriding it in ParentNode, define the two implementations in ParentNode and LeafNode.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestGetChildNodes.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java?rev=1343373&r1=1343372&r2=1343373&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/DOMTestSuiteBuilder.java Mon May 28 19:37:05 2012
@@ -94,6 +94,7 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.element.attributes.TestSetNamedItemNSWrongDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.element.attributes.TestSetNamedItemWrongDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.text.TestAppendData(dbf));
+        addTest(new org.apache.axiom.ts.dom.text.TestGetChildNodes(dbf));
         addTest(new org.apache.axiom.ts.dom.text.TestGetWholeText(dbf));
         addTest(new org.apache.axiom.ts.dom.text.TestGetWholeTextWithCDATASection(dbf));
         addTest(new org.apache.axiom.ts.dom.text.TestGetWholeTextWithComment(dbf));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestGetChildNodes.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestGetChildNodes.java?rev=1343373&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestGetChildNodes.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestGetChildNodes.java Mon May 28 19:37:05 2012
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.dom.text;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+
+public class TestGetChildNodes extends DOMTestCase {
+    public TestGetChildNodes(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        Text text = document.createTextNode("test");
+        NodeList children = text.getChildNodes();
+        assertNotNull(children);
+        assertEquals(0, children.getLength());
+    }
+}

Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/text/TestGetChildNodes.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java?rev=1343373&r1=1343372&r2=1343373&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/CharacterImpl.java Mon May 28 19:37:05 2012
@@ -126,12 +126,4 @@ public abstract class CharacterImpl exte
         int end = Math.min(count + offset, textValue.length());
         return this.textValue.substring(offset, end);
     }
-
-    /**
-     * Returns the length of the string value.
-     */
-    public int getLength() {
-        return (this.textValue != null) ? this.textValue.length() : 0;
-	}
-		
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java?rev=1343373&r1=1343372&r2=1343373&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/LeafNode.java Mon May 28 19:37:05 2012
@@ -19,9 +19,11 @@
 package org.apache.axiom.om.impl.dom;
 
 import org.apache.axiom.om.OMFactory;
+import org.w3c.dom.DOMException;
 import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
 
-public abstract class LeafNode extends ChildNode {
+public abstract class LeafNode extends ChildNode implements NodeList {
     private ParentNode ownerNode;
     
     private ChildNode previousSibling;
@@ -59,6 +61,45 @@ public abstract class LeafNode extends C
     final void internalSetNextSibling(ChildNode nextSibling) {
         this.nextSibling = nextSibling;
     }
+    
+    public final NodeList getChildNodes() {
+        return this;
+    }
+
+    public final int getLength() {
+        return 0;
+    }
+
+    public final Node item(int index) {
+        return null;
+    }
+
+    public final Node appendChild(Node newChild) throws DOMException {
+        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                DOMMessageFormatter.formatMessage(
+                        DOMMessageFormatter.DOM_DOMAIN,
+                        DOMException.HIERARCHY_REQUEST_ERR, null));
+    }
+
+    public final Node removeChild(Node oldChild) throws DOMException {
+        throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessageFormatter
+                .formatMessage(DOMMessageFormatter.DOM_DOMAIN, DOMException.NOT_FOUND_ERR,
+                               null));
+    }
+
+    public final Node insertBefore(Node newChild, Node refChild) throws DOMException {
+        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                               DOMMessageFormatter.formatMessage(
+                                       DOMMessageFormatter.DOM_DOMAIN,
+                                       DOMException.HIERARCHY_REQUEST_ERR, null));
+    }
+
+    public final Node replaceChild(Node newChild, Node oldChild) throws DOMException {
+        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
+                               DOMMessageFormatter.formatMessage(
+                                       DOMMessageFormatter.DOM_DOMAIN,
+                                       DOMException.HIERARCHY_REQUEST_ERR, null));
+    }
 
     public Node cloneNode(boolean deep) {
         LeafNode newnode = (LeafNode)super.cloneNode(deep);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1343373&r1=1343372&r2=1343373&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java Mon May 28 19:37:05 2012
@@ -24,12 +24,11 @@ import org.apache.axiom.om.OMXMLParserWr
 import org.w3c.dom.DOMException;
 import org.w3c.dom.NamedNodeMap;
 import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
 import org.w3c.dom.UserDataHandler;
 
 import java.util.Hashtable;
 
-public abstract class NodeImpl implements Node, NodeList, Cloneable {
+public abstract class NodeImpl implements Node, Cloneable {
 
     /** Holds the user data objects */
     private Hashtable userData; // Will be initialized in setUserData()
@@ -179,97 +178,12 @@ public abstract class NodeImpl implement
         return newnode;
     }
 
-    /*
-     * (non-Javadoc)
-     * 
-     * @see org.w3c.dom.Node#getChildNodes()
-     */
-    public NodeList getChildNodes() {
-        return this;
-    }
-
     public boolean isSupported(String feature, String version) {
         throw new UnsupportedOperationException();
         // TODO
     }
 
     /*
-     * (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)
-     */
-    public Node removeChild(Node oldChild) throws DOMException {
-        throw new DOMException(DOMException.NOT_FOUND_ERR, DOMMessageFormatter
-                .formatMessage(DOMMessageFormatter.DOM_DOMAIN, DOMException.NOT_FOUND_ERR,
-                               null));
-    }
-
-    /*
-     * (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
-        throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
-                               DOMMessageFormatter.formatMessage(
-                                       DOMMessageFormatter.DOM_DOMAIN,
-                                       DOMException.HIERARCHY_REQUEST_ERR, null));
-
-    }
-
-    /*
-     * (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(
-                                       DOMMessageFormatter.DOM_DOMAIN,
-                                       DOMException.HIERARCHY_REQUEST_ERR, null));
-    }
-
-    //
-    // NodeList methods
-    //
-
-    /**
-     * NodeList method: Returns the number of immediate children of this node.
-     * <p/>
-     * By default we do not have any children, ParentNode overrides this.
-     *
-     * @return Returns int.
-     * @see ParentNode
-     */
-    public int getLength() {
-        return 0;
-    }
-
-    /**
-     * 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.
-     *
-     * @param index
-     * @return Returns org.w3c.dom.Node
-     * @see ParentNode
-     */
-    public Node item(int index) {
-        return null;
-    }
-
-    /*
      * Flags setters and getters
      */
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=1343373&r1=1343372&r2=1343373&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java Mon May 28 19:37:05 2012
@@ -205,6 +205,10 @@ public abstract class ParentNode extends
         return this.firstChild != null;
     }
 
+    public final Node appendChild(Node newChild) throws DOMException {
+        return insertBefore(newChild, null);
+    }
+
     /**
      * Inserts newChild before the refChild. If the refChild is null then the newChild is made the
      * last child.
@@ -372,7 +376,7 @@ public abstract class ParentNode extends
     }
 
     /** Replaces the oldChild with the newChild. */
-    public Node replaceChild(Node newChild, Node oldChild) throws DOMException {
+    public final Node replaceChild(Node newChild, Node oldChild) throws DOMException {
         ChildNode newDomChild = (ChildNode) newChild;
         ChildNode oldDomChild = (ChildNode) oldChild;
 
@@ -460,7 +464,7 @@ public abstract class ParentNode extends
     }
 
     /** Removes the given child from the DOM Tree. */
-    public Node removeChild(Node oldChild) throws DOMException {
+    public final Node removeChild(Node oldChild) throws DOMException {
         if (oldChild.getParentNode() == this) {
             ((ChildNode)oldChild).detach(true);
             return oldChild;