Author: veithen
Date: Sun Apr 1 13:33:52 2012
New Revision: 1308113
URL: http://svn.apache.org/viewvc?rev=1308113&view=rev
Log:
AXIOM-412: Implemented rule (3).
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestAddChildFromForeignDocument.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingAfterFromForeignDocument.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingBeforeFromForeignDocument.java
(with props)
Modified:
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
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java
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=1308113&r1=1308112&r2=1308113&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 13:33:52 2012
@@ -78,16 +78,10 @@ public abstract class ParentNode extends
public void addChild(OMNode omNode) {
if (omNode.getOMFactory() instanceof OMDOMFactory) {
- Node domNode = (Node) omNode;
- if (ownerDocument() != null &&
!domNode.getOwnerDocument().equals(ownerDocument())) {
- this.appendChild(ownerDocument().importNode(domNode, true));
- } else {
- this.appendChild(domNode);
- }
+ insertBefore((Node)omNode, null, false);
} else {
addChild(importNode(omNode));
}
-
}
public void buildNext() {
@@ -208,11 +202,14 @@ public abstract class ParentNode extends
* last child.
*/
public Node insertBefore(Node newChild, Node refChild) throws DOMException
{
-
+ return insertBefore(newChild, refChild, true);
+ }
+
+ private Node insertBefore(Node newChild, Node refChild, boolean
useDomSemantics) {
ChildNode newDomChild = (ChildNode) newChild;
ChildNode refDomChild = (ChildNode) refChild;
- if (ownerDocument() != newDomChild.ownerDocument()) {
+ if (useDomSemantics && ownerDocument() != newDomChild.ownerDocument())
{
throw new DOMException(DOMException.WRONG_DOCUMENT_ERR,
DOMMessageFormatter.formatMessage(
DOMMessageFormatter.DOM_DOMAIN,
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=1308113&r1=1308112&r2=1308113&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 13:33:52 2012
@@ -38,10 +38,6 @@ public class OMImplementationTest extend
public static TestSuite suite() {
OMTestSuiteBuilder builder = new OMTestSuiteBuilder(new
OMDOMMetaFactory(), false);
- // 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);
builder.exclude(TestInsertSiblingBeforeOnChild.class);
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java?rev=1308113&r1=1308112&r2=1308113&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/OMDOMTestSuiteBuilder.java
Sun Apr 1 13:33:52 2012
@@ -36,9 +36,12 @@ public class OMDOMTestSuiteBuilder exten
protected void addTests() {
addTest(new
org.apache.axiom.ts.omdom.attr.TestGetNamespaceNormalized(metaFactory));
+ addTest(new
org.apache.axiom.ts.omdom.element.TestAddChildFromForeignDocument(metaFactory));
addTest(new
org.apache.axiom.ts.omdom.element.TestGetNamespaceNormalized(metaFactory));
addTest(new
org.apache.axiom.ts.omdom.element.TestRemoveChildIncomplete(metaFactory));
addTest(new
org.apache.axiom.ts.omdom.factory.TestCreateOMTextCDATASection(metaFactory));
addTest(new
org.apache.axiom.ts.omdom.factory.TestCreateOMTextCDATASectionWithParent(metaFactory));
+ addTest(new
org.apache.axiom.ts.omdom.node.TestInsertSiblingAfterFromForeignDocument(metaFactory));
+ addTest(new
org.apache.axiom.ts.omdom.node.TestInsertSiblingBeforeFromForeignDocument(metaFactory));
}
}
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestAddChildFromForeignDocument.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestAddChildFromForeignDocument.java?rev=1308113&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestAddChildFromForeignDocument.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestAddChildFromForeignDocument.java
Sun Apr 1 13:33:52 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.omdom.element;
+
+import javax.xml.parsers.DocumentBuilder;
+
+import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.dom.DOMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * Tests that {@link OMContainer#addChild(OMNode)} automatically adopts (in
the sense of DOM) the
+ * child node if it doesn't have the same owner document.
+ */
+public class TestAddChildFromForeignDocument extends AxiomTestCase {
+ public TestAddChildFromForeignDocument(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ DocumentBuilder db =
((DOMMetaFactory)metaFactory).newDocumentBuilderFactory().newDocumentBuilder();
+ Document document1 = db.newDocument();
+ Element element1 = document1.createElementNS(null, "element1");
+ Document document2 = db.newDocument();
+ Element element2 = document2.createElementNS(null, "element2");
+ ((OMElement)element1).addChild((OMElement)element2);
+ // Assert that the new child is not a copy, but the original element
+ assertSame(element2, element1.getFirstChild());
+ // Assert that the owner document of element2 was changed
+ assertSame(document1, element2.getOwnerDocument());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestAddChildFromForeignDocument.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingAfterFromForeignDocument.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingAfterFromForeignDocument.java?rev=1308113&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingAfterFromForeignDocument.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingAfterFromForeignDocument.java
Sun Apr 1 13:33:52 2012
@@ -0,0 +1,55 @@
+/*
+ * 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.omdom.node;
+
+import javax.xml.parsers.DocumentBuilder;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.dom.DOMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+/**
+ * Tests that {@link OMNode#insertSiblingAfter(OMNode)} automatically adopts
(in the sense of DOM)
+ * the sibling if it doesn't have the same owner document.
+ */
+public class TestInsertSiblingAfterFromForeignDocument extends AxiomTestCase {
+ public TestInsertSiblingAfterFromForeignDocument(OMMetaFactory
metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ DocumentBuilder db =
((DOMMetaFactory)metaFactory).newDocumentBuilderFactory().newDocumentBuilder();
+ Document document1 = db.newDocument();
+ Element element1 = document1.createElementNS(null, "element1");
+ Text text = document1.createTextNode("test");
+ element1.appendChild(text);
+ Document document2 = db.newDocument();
+ Element element2 = document2.createElementNS(null, "element2");
+ ((OMNode)text).insertSiblingAfter((OMElement)element2);
+ // Assert that the new child is not a copy, but the original element
+ assertSame(element2, element1.getLastChild());
+ // Assert that the owner document of element2 was changed
+ assertSame(document1, element2.getOwnerDocument());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingAfterFromForeignDocument.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingBeforeFromForeignDocument.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingBeforeFromForeignDocument.java?rev=1308113&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingBeforeFromForeignDocument.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingBeforeFromForeignDocument.java
Sun Apr 1 13:33:52 2012
@@ -0,0 +1,55 @@
+/*
+ * 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.omdom.node;
+
+import javax.xml.parsers.DocumentBuilder;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.dom.DOMMetaFactory;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.Text;
+
+/**
+ * Tests that {@link OMNode#insertSiblingBefore(OMNode)} automatically adopts
(in the sense of DOM)
+ * the sibling if it doesn't have the same owner document.
+ */
+public class TestInsertSiblingBeforeFromForeignDocument extends AxiomTestCase {
+ public TestInsertSiblingBeforeFromForeignDocument(OMMetaFactory
metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ DocumentBuilder db =
((DOMMetaFactory)metaFactory).newDocumentBuilderFactory().newDocumentBuilder();
+ Document document1 = db.newDocument();
+ Element element1 = document1.createElementNS(null, "element1");
+ Text text = document1.createTextNode("test");
+ element1.appendChild(text);
+ Document document2 = db.newDocument();
+ Element element2 = document2.createElementNS(null, "element2");
+ ((OMNode)text).insertSiblingBefore((OMElement)element2);
+ // Assert that the new child is not a copy, but the original element
+ assertSame(element2, element1.getFirstChild());
+ // Assert that the owner document of element2 was changed
+ assertSame(document1, element2.getOwnerDocument());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/node/TestInsertSiblingBeforeFromForeignDocument.java
------------------------------------------------------------------------------
svn:eol-style = native