ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1308090 - 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/document/ axiom-dom-testsuite/src/main/java/org/apache/axio...
Date Sun, 01 Apr 2012 12:11:54 GMT
Author: veithen
Date: Sun Apr  1 12:11:53 2012
New Revision: 1308090

URL: http://svn.apache.org/viewvc?rev=1308090&view=rev
Log:
Increased the DOM test coverage and resolved a couple of minor issues.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildWrongDocument.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestGetOwnerDocument.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildCyclic.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildSelf.java
  (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildWrongDocument.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/ChildNode.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.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=1308090&r1=1308089&r2=1308090&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
Sun Apr  1 12:11:53 2012
@@ -37,6 +37,7 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.document.TestAdoptNodeToSameDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestAdoptNodeWithParent(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestAllowedChildren(dbf));
+        addTest(new org.apache.axiom.ts.dom.document.TestAppendChildWrongDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestCreateAttribute(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNS(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNSWithoutNamespace(dbf));
@@ -48,8 +49,12 @@ public class DOMTestSuiteBuilder extends
         addTest(new org.apache.axiom.ts.dom.document.TestCreateText(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestDocumentSiblings(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestGetDomConfigDefaults(dbf));
+        addTest(new org.apache.axiom.ts.dom.document.TestGetOwnerDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.document.TestNormalizeDocumentNamespace(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestAppendChild(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestAppendChildCyclic(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestAppendChildSelf(dbf));
+        addTest(new org.apache.axiom.ts.dom.element.TestAppendChildWrongDocument(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestAttributes(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestAttributes2(dbf));
         addTest(new org.apache.axiom.ts.dom.element.TestAttributes3(dbf));

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildWrongDocument.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildWrongDocument.java?rev=1308090&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildWrongDocument.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAppendChildWrongDocument.java
Sun Apr  1 12:11:53 2012
@@ -0,0 +1,51 @@
+/*
+ * 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.document;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Tests that {@link Node#appendChild(Node)} throws an appropriate exception if an attempt
is made to
+ * append a child that has a different owner document.
+ */
+public class TestAppendChildWrongDocument extends DOMTestCase {
+    public TestAppendChildWrongDocument(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    protected void runTest() throws Throwable {
+        DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
+        Document document1 = documentBuilder.newDocument();
+        Document document2 = documentBuilder.newDocument();
+        Element element = document2.createElementNS(null, "element");
+        try {
+            document1.appendChild(element);
+            fail("Expected DOMException");
+        } catch (DOMException ex) {
+            assertEquals(DOMException.WRONG_DOCUMENT_ERR, ex.code);
+        }
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestGetOwnerDocument.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestGetOwnerDocument.java?rev=1308090&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestGetOwnerDocument.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestGetOwnerDocument.java
Sun Apr  1 12:11:53 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.document;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+/**
+ * Tests that {@link Node#getOwnerDocument()} returns <code>null</code> if the
node is a
+ * {@link Document}.
+ */
+public class TestGetOwnerDocument extends DOMTestCase {
+    public TestGetOwnerDocument(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        assertNull(document.getOwnerDocument());
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildCyclic.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildCyclic.java?rev=1308090&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildCyclic.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildCyclic.java
Sun Apr  1 12:11:53 2012
@@ -0,0 +1,53 @@
+/*
+ * 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.element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Tests that {@link Node#appendChild(Node)} throws an appropriate exception if the invocation
would
+ * result in a cyclic relationship. This occurs if the node to append is an ancestor of the
node to
+ * which is appended.
+ */
+public class TestAppendChildCyclic extends DOMTestCase {
+    public TestAppendChildCyclic(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        Element grandparent = document.createElementNS(null, "grandparent");
+        Element parent = document.createElementNS(null, "parent");
+        grandparent.appendChild(parent);
+        Element element = document.createElementNS(null, "element");
+        parent.appendChild(element);
+        try {
+            element.appendChild(grandparent);
+            fail("Expected DOMException");
+        } catch (DOMException ex) {
+            assertEquals(DOMException.HIERARCHY_REQUEST_ERR, ex.code);
+        }
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildSelf.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildSelf.java?rev=1308090&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildSelf.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildSelf.java
Sun Apr  1 12:11:53 2012
@@ -0,0 +1,48 @@
+/*
+ * 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.element;
+
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+
+/**
+ * Tests that {@link Node#appendChild(Node)} throws an appropriate exception if an attempt
is made
+ * to add a node as a child of itself.
+ */
+public class TestAppendChildSelf extends DOMTestCase {
+    public TestAppendChildSelf(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    protected void runTest() throws Throwable {
+        Document document = dbf.newDocumentBuilder().newDocument();
+        Element element = document.createElementNS("urn:test", "test");
+        try {
+            element.appendChild(element);
+            fail("Expected DOMException");
+        } catch (DOMException ex) {
+            assertEquals(DOMException.HIERARCHY_REQUEST_ERR, ex.code);
+        }
+    }
+}

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

Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildWrongDocument.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildWrongDocument.java?rev=1308090&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildWrongDocument.java
(added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestAppendChildWrongDocument.java
Sun Apr  1 12:11:53 2012
@@ -0,0 +1,53 @@
+/*
+ * 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.element;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.axiom.ts.dom.DOMTestCase;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * Tests that {@link Node#appendChild(Node)} throws an appropriate exception if an attempt
is made to
+ * append a child that has a different owner document.
+ */
+public class TestAppendChildWrongDocument extends DOMTestCase {
+    public TestAppendChildWrongDocument(DocumentBuilderFactory dbf) {
+        super(dbf);
+    }
+
+    protected void runTest() throws Throwable {
+        DocumentBuilder documentBuilder = dbf.newDocumentBuilder();
+        Document document1 = documentBuilder.newDocument();
+        Document document2 = documentBuilder.newDocument();
+        Element element = document1.createElementNS(null, "element");
+        Text text = document2.createTextNode("test");
+        try {
+            element.appendChild(text);
+            fail("Expected DOMException");
+        } catch (DOMException ex) {
+            assertEquals(DOMException.WRONG_DOCUMENT_ERR, ex.code);
+        }
+    }
+}

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

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java?rev=1308090&r1=1308089&r2=1308090&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ChildNode.java
Sun Apr  1 12:11:53 2012
@@ -59,6 +59,12 @@ public abstract class ChildNode extends 
         super(factory);
     }
 
+    /**
+     * Get the owner document of this node. In contrast to {@link Node#getOwnerDocument()},
this
+     * method returns a non null value when invoked on a {@link Document} instance.
+     * 
+     * @return the owner document
+     */
     DocumentImpl ownerDocument() {
         if (ownerNode == null) {
             return null;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java?rev=1308090&r1=1308089&r2=1308090&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentImpl.java
Sun Apr  1 12:11:53 2012
@@ -94,6 +94,19 @@ public class DocumentImpl extends Parent
         this.done = true;
     }
 
+    DocumentImpl ownerDocument() {
+        return this;
+    }
+
+    public Document getOwnerDocument() {
+        return null;
+    }
+
+    protected Object clone() throws CloneNotSupportedException {
+        // TODO Auto-generated method stub
+        return super.clone();
+    }
+
     // /
     // /OMNode methods
     // //

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=1308090&r1=1308089&r2=1308090&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
Sun Apr  1 12:11:53 2012
@@ -212,26 +212,25 @@ public abstract class ParentNode extends
         ChildNode newDomChild = (ChildNode) newChild;
         ChildNode refDomChild = (ChildNode) refChild;
 
-        if (this == newChild || !isAncestor(newChild)) {
+        if (ownerDocument() != newDomChild.ownerDocument()) {
+            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
+                                   DOMMessageFormatter.formatMessage(
+                                           DOMMessageFormatter.DOM_DOMAIN,
+                                           DOMException.WRONG_DOCUMENT_ERR, null));
+        }
+
+        if (isAncestorOrSelf(newChild)) {
             throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                                    DOMMessageFormatter.formatMessage(
                                            DOMMessageFormatter.DOM_DOMAIN,
                                            DOMException.HIERARCHY_REQUEST_ERR, null));
         }
 
-        if (newDomChild.parentNode() != null && newDomChild.ownerDocument() == ownerDocument())
{
+        if (newDomChild.parentNode() != null) {
             //If the newChild is already in the tree remove it
             newDomChild.parentNode().removeChild(newDomChild);
         }
 
-        if (!(this instanceof Document)
-                && !(ownerDocument() == newDomChild.getOwnerDocument())) {
-            throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
-                                   DOMMessageFormatter.formatMessage(
-                                           DOMMessageFormatter.DOM_DOMAIN,
-                                           DOMException.WRONG_DOCUMENT_ERR, null));
-        }
-
         if (this instanceof Document) {
             if (newDomChild instanceof ElementImpl) {
                 if (((DocumentImpl) this).getOMDocumentElement(false) != null) {
@@ -380,7 +379,7 @@ public abstract class ParentNode extends
             return this.removeChild(oldChild);
         }
 
-        if (this == newChild || !isAncestor(newChild)) {
+        if (isAncestorOrSelf(newChild)) {
             throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR,
                                    DOMMessageFormatter.formatMessage(
                                            DOMMessageFormatter.DOM_DOMAIN,
@@ -481,10 +480,22 @@ public abstract class ParentNode extends
         }
     }
 
-    private boolean isAncestor(Node newNode) {
-
-        // TODO isAncestor
-        return true;
+    /**
+     * Checks if the given node is an ancestor (or identical) to this node.
+     * 
+     * @param node
+     *            the node to check
+     * @return <code>true</code> if the node is an ancestor or indentical to
this node
+     */
+    private boolean isAncestorOrSelf(Node node) {
+        Node currentNode = this;
+        do {
+            if (currentNode == node) {
+                return true;
+            }
+            currentNode = currentNode.getParentNode();
+        } while (currentNode != null);
+        return false;
     }
 
     public Node cloneNode(boolean deep) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1308090&r1=1308089&r2=1308090&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
(original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
Sun Apr  1 12:11:53 2012
@@ -40,6 +40,7 @@ public class OMImplementationTest extend
         
         // TODO: doesn't work because the test trigger a call to importNode which will build
the descendant
         builder.exclude(org.apache.axiom.ts.om.document.TestSerializeAndConsumeWithIncompleteDescendant.class);
+        builder.exclude(org.apache.axiom.ts.om.document.TestIsCompleteAfterAddingIncompleteChild.class);
         
         // TODO: Axiom should throw an exception if an attempt is made to create a cyclic
parent-child relationship
         builder.exclude(TestInsertSiblingAfterOnChild.class);



Mime
View raw message