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/03/10 14:55:21 UTC
svn commit: r1299206 - 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/src/main/java/org/apache/axiom/om/impl/...
Author: veithen
Date: Sat Mar 10 13:55:20 2012
New Revision: 1299206
URL: http://svn.apache.org/viewvc?rev=1299206&view=rev
Log:
Correctly implement Document#adoptNode.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeToSameDocument.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeWithParent.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-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNode.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/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.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=1299206&r1=1299205&r2=1299206&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 Sat Mar 10 13:55:20 2012
@@ -36,6 +36,8 @@ public class DOMTestSuiteBuilder extends
addTest(new org.apache.axiom.ts.dom.attr.TestSetPrefixNotNullWithoutNamespace(dbf));
addTest(new org.apache.axiom.ts.dom.builder.TestWhitespaceAroundDocumentElement(dbf));
addTest(new org.apache.axiom.ts.dom.document.TestAdoptNode(dbf));
+ 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.TestCreateAttribute(dbf));
addTest(new org.apache.axiom.ts.dom.document.TestCreateAttributeNS(dbf));
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNode.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/TestAdoptNode.java?rev=1299206&r1=1299205&r2=1299206&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNode.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNode.java Sat Mar 10 13:55:20 2012
@@ -24,8 +24,12 @@ import javax.xml.parsers.DocumentBuilder
import org.apache.axiom.ts.dom.DOMTestCase;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
+import org.w3c.dom.Node;
import org.w3c.dom.Text;
+/**
+ * Tests the behavior of {@link Document#adoptNode(Node)}.
+ */
public class TestAdoptNode extends DOMTestCase {
public TestAdoptNode(DocumentBuilderFactory dbf) {
super(dbf);
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeToSameDocument.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/TestAdoptNodeToSameDocument.java?rev=1299206&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeToSameDocument.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeToSameDocument.java Sat Mar 10 13:55:20 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.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * Tests the behavior of {@link Document#adoptNode(Node)} if the node is
+ * already owned by the document. In this case, the method is still expected
+ * to detach the node from its parent.
+ */
+public class TestAdoptNodeToSameDocument extends DOMTestCase {
+ public TestAdoptNodeToSameDocument(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ Document document = builder.newDocument();
+ Element parent = document.createElementNS(null, "test");
+ Text node = document.createTextNode("test");
+ parent.appendChild(node);
+ assertSame(node, document.adoptNode(node));
+ assertSame(document, node.getOwnerDocument());
+ assertNull(node.getParentNode());
+ assertNull(parent.getFirstChild());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeToSameDocument.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeWithParent.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/TestAdoptNodeWithParent.java?rev=1299206&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeWithParent.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeWithParent.java Sat Mar 10 13:55:20 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.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.Text;
+
+/**
+ * Tests the behavior of {@link Document#adoptNode(Node)} if the node to adopt has a parent. In this
+ * case, the method must detach the node from its parent first.
+ */
+public class TestAdoptNodeWithParent extends DOMTestCase {
+ public TestAdoptNodeWithParent(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ Document document1 = builder.newDocument();
+ Document document2 = builder.newDocument();
+ Element parent = document1.createElementNS(null, "test");
+ Text node = document1.createTextNode("test");
+ parent.appendChild(node);
+ assertSame(node, document2.adoptNode(node));
+ assertSame(document2, node.getOwnerDocument());
+ assertNull(node.getParentNode());
+ assertNull(parent.getFirstChild());
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/document/TestAdoptNodeWithParent.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=1299206&r1=1299205&r2=1299206&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 Sat Mar 10 13:55:20 2012
@@ -77,7 +77,7 @@ public abstract class ChildNode extends
* @param document
*/
void setOwnerDocument(DocumentImpl document) {
- if (ownerNode != null) {
+ if (hasParent()) {
throw new IllegalStateException();
}
this.ownerNode = document;
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=1299206&r1=1299205&r2=1299206&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 Sat Mar 10 13:55:20 2012
@@ -533,8 +533,16 @@ public class DocumentImpl extends Parent
}
public Node adoptNode(Node node) throws DOMException {
- //OK... I'm cheating here, a BIG TODO
- return this.importNode(node, true);
+ if (node instanceof ChildNode) {
+ ChildNode childNode = (ChildNode)node;
+ if (childNode.hasParent()) {
+ childNode.detach();
+ }
+ childNode.setOwnerDocument(this);
+ return childNode;
+ } else {
+ return null;
+ }
}
public String getDocumentURI() {
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java?rev=1299206&r1=1299205&r2=1299206&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/DOMImplementationTest.java Sat Mar 10 13:55:20 2012
@@ -23,13 +23,10 @@ import junit.framework.TestSuite;
import org.apache.axiom.om.impl.dom.jaxp.DOOMDocumentBuilderFactory;
import org.apache.axiom.ts.dom.DOMTestSuiteBuilder;
-import org.apache.axiom.ts.dom.document.TestAdoptNode;
public class DOMImplementationTest extends TestCase {
public static TestSuite suite() {
DOMTestSuiteBuilder builder = new DOMTestSuiteBuilder(new DOOMDocumentBuilderFactory(), true);
- // TODO: adoptNode is not correctly implemented
- builder.exclude(TestAdoptNode.class);
return builder.build();
}
}