Author: veithen
Date: Sat Apr 14 14:48:07 2012
New Revision: 1326115
URL: http://svn.apache.org/viewvc?rev=1326115&view=rev
Log:
AXIOM-412: Implemented rule (4) for OMNode#detach.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestDetach.java
(with props)
Modified:
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/ParentNode.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/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=1326115&r1=1326114&r2=1326115&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 Apr 14 14:48:07 2012
@@ -173,8 +173,12 @@ public abstract class ChildNode extends
}
public void setParent(OMContainer element) {
+ setParent(element, false);
+ }
+
+ void setParent(OMContainer element, boolean useDomSemantics) {
if (element == null) {
- ownerNode = ownerDocument();
+ ownerNode = useDomSemantics ? ownerDocument() : null;
hasParent(false);
} else if (element instanceof ParentNode) {
ownerNode = (ParentNode) element;
@@ -215,7 +219,7 @@ public abstract class ChildNode extends
if (parentNode != null && parentNode.lastChild == this) {
parentNode.lastChild = previousSibling;
}
- setParent(null);
+ setParent(null, false);
this.previousSibling = null;
}
return (OMNode)this;
@@ -274,7 +278,7 @@ public abstract class ChildNode extends
parentNode.setFirstChild((OMNode)siblingImpl);
siblingImpl.previousSibling = null;
} else {
- siblingImpl.setParent(parentNode);
+ siblingImpl.setParent(parentNode, false);
previousSibling.setNextOMSibling((OMNode)siblingImpl);
siblingImpl.setPreviousOMSibling((OMNode)previousSibling);
}
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=1326115&r1=1326114&r2=1326115&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
Sat Apr 14 14:48:07 2012
@@ -235,7 +235,7 @@ public abstract class ParentNode extends
DOMException.HIERARCHY_REQUEST_ERR, null));
}
if (newDomChild.parentNode() == null) {
- newDomChild.setParent(this);
+ newDomChild.setParent(this, useDomSemantics);
}
} else if (!(newDomChild instanceof CommentImpl
|| newDomChild instanceof ProcessingInstructionImpl
@@ -254,7 +254,7 @@ public abstract class ParentNode extends
this.lastChild = newDomChild;
this.firstChild = newDomChild;
this.firstChild.isFirstChild(true);
- newDomChild.setParent(this);
+ newDomChild.setParent(this, useDomSemantics);
} else {
this.lastChild.nextSibling = newDomChild;
newDomChild.previousSibling = this.lastChild;
@@ -262,7 +262,7 @@ public abstract class ParentNode extends
this.lastChild.nextSibling = null;
}
if (newDomChild.parentNode() == null) {
- newDomChild.setParent(this);
+ newDomChild.setParent(this, useDomSemantics);
}
} else {
Iterator children = this.getChildren();
@@ -282,7 +282,7 @@ public abstract class ParentNode extends
ChildNode child = docFrag.firstChild;
while (child != null) {
- child.setParent(this);
+ child.setParent(this, useDomSemantics);
child = child.nextSibling;
}
@@ -317,7 +317,7 @@ public abstract class ParentNode extends
ChildNode child = docFrag.firstChild;
while (child != null) {
- child.setParent(this);
+ child.setParent(this, useDomSemantics);
child = child.nextSibling;
}
@@ -352,7 +352,7 @@ public abstract class ParentNode extends
}
if (newDomChild.parentNode() == null) {
- newDomChild.setParent(this);
+ newDomChild.setParent(this, useDomSemantics);
}
}
@@ -395,7 +395,7 @@ public abstract class ParentNode extends
//set the parent of all kids to me
while(child != null) {
- child.setParent(this);
+ child.setParent(this, true);
child = child.nextSibling;
}
@@ -410,7 +410,7 @@ public abstract class ParentNode extends
}
//Cleanup the current first child
- this.firstChild.setParent(null);
+ this.firstChild.setParent(null, true);
this.firstChild.nextSibling = null;
//Set the new first child
@@ -432,14 +432,14 @@ public abstract class ParentNode extends
}
- newDomChild.setParent(this);
+ newDomChild.setParent(this, true);
}
found = true;
// remove the old child's references to this tree
oldDomChild.nextSibling = null;
oldDomChild.previousSibling = null;
- oldDomChild.setParent(null);
+ oldDomChild.setParent(null, true);
}
}
@@ -488,7 +488,7 @@ public abstract class ParentNode extends
ParentNode newnode = (ParentNode) super.cloneNode(deep);
// set parent and owner document
- newnode.setParent(null);
+ newnode.setParent(null, true);
// Need to break the association w/ original kids
newnode.firstChild = null;
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=1326115&r1=1326114&r2=1326115&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
Sat Apr 14 14:48:07 2012
@@ -41,6 +41,7 @@ public class OMDOMTestSuiteBuilder exten
addTest(new
org.apache.axiom.ts.omdom.document.TestImportNode(metaFactory));
addTest(new
org.apache.axiom.ts.omdom.element.TestAddAttributeReplace(metaFactory));
addTest(new
org.apache.axiom.ts.omdom.element.TestAddChildFromForeignDocument(metaFactory));
+ addTest(new org.apache.axiom.ts.omdom.element.TestDetach(metaFactory));
addTest(new
org.apache.axiom.ts.omdom.element.TestGetNamespaceNormalized(metaFactory));
addTest(new
org.apache.axiom.ts.omdom.element.TestRemoveAttribute(metaFactory));
addTest(new
org.apache.axiom.ts.omdom.element.TestRemoveChildIncomplete(metaFactory));
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestDetach.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestDetach.java?rev=1326115&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestDetach.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestDetach.java
Sat Apr 14 14:48:07 2012
@@ -0,0 +1,46 @@
+/*
+ * 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 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 after a node has been removed from its parent using {@link
OMNode#detach()}, it will
+ * have a new owner document.
+ */
+public class TestDetach extends AxiomTestCase {
+ public TestDetach(OMMetaFactory metaFactory) {
+ super(metaFactory);
+ }
+
+ protected void runTest() throws Throwable {
+ Document document =
((DOMMetaFactory)metaFactory).newDocumentBuilderFactory().newDocumentBuilder().newDocument();
+ Element parent = document.createElementNS(null, "parent");
+ Element child = document.createElementNS(null, "child");
+ parent.appendChild(child);
+ ((OMElement)child).detach();
+ assertNotSame(document, child.getOwnerDocument());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/omdom/element/TestDetach.java
------------------------------------------------------------------------------
svn:eol-style = native