Author: veithen
Date: Sat Oct 1 20:17:43 2011
New Revision: 1178085
URL: http://svn.apache.org/viewvc?rev=1178085&view=rev
Log:
Fixed some issues and removed some unreachable code in DOOM's insertBefore
method.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBefore.java
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.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/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=1178085&r1=1178084&r2=1178085&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 Oct 1 20:17:43 2011
@@ -48,6 +48,8 @@ public class DOMTestSuiteBuilder extends
addTest(new
org.apache.axiom.ts.dom.element.TestGetElementsByTagNameWithWildcard(dbf));
addTest(new
org.apache.axiom.ts.dom.element.TestGetNamespaceURIWithNoNamespace(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestGetTextContent(dbf));
+ addTest(new org.apache.axiom.ts.dom.element.TestInsertBefore(dbf));
+ addTest(new
org.apache.axiom.ts.dom.element.TestInsertBeforeWithDocumentFragment(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestRemoveFirstChild(dbf));
addTest(new org.apache.axiom.ts.dom.element.TestRemoveLastChild(dbf));
addTest(new
org.apache.axiom.ts.dom.element.TestRemoveSingleChild(dbf));
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBefore.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/TestInsertBefore.java?rev=1178085&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBefore.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBefore.java
Sat Oct 1 20:17:43 2011
@@ -0,0 +1,63 @@
+/*
+ * 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.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class TestInsertBefore extends DOMTestCase {
+ public TestInsertBefore(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+
+ Element parent1 = document.createElementNS(null, "parent1");
+ Element a = document.createElementNS(null, "a");
+ Element b = document.createElementNS(null, "b");
+ Element c = document.createElementNS(null, "c");
+ parent1.appendChild(a);
+ parent1.appendChild(b);
+ parent1.appendChild(c);
+
+ Element parent2 = document.createElementNS(null, "parent1");
+ Element d = document.createElementNS(null, "d");
+ Element e = document.createElementNS(null, "e");
+ parent2.appendChild(d);
+ parent2.appendChild(e);
+
+ parent2.insertBefore(b, e);
+
+ NodeList children = parent1.getChildNodes();
+ assertEquals(2, children.getLength());
+ assertSame(a, children.item(0));
+ assertSame(c, children.item(1));
+
+ children = parent2.getChildNodes();
+ assertEquals(3, children.getLength());
+ assertSame(d, children.item(0));
+ assertSame(b, children.item(1));
+ assertSame(e, children.item(2));
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBefore.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.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/TestInsertBeforeWithDocumentFragment.java?rev=1178085&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.java
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.java
Sat Oct 1 20:17:43 2011
@@ -0,0 +1,63 @@
+/*
+ * 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.Document;
+import org.w3c.dom.DocumentFragment;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+public class TestInsertBeforeWithDocumentFragment extends DOMTestCase {
+ public TestInsertBeforeWithDocumentFragment(DocumentBuilderFactory dbf) {
+ super(dbf);
+ }
+
+ protected void runTest() throws Throwable {
+ Document document = dbf.newDocumentBuilder().newDocument();
+
+ DocumentFragment fragment = document.createDocumentFragment();
+ Element x = document.createElementNS(null, "x");
+ Element y = document.createElementNS(null, "y");
+ fragment.appendChild(x);
+ fragment.appendChild(y);
+
+ Element element = document.createElementNS(null, "parent1");
+ Element a = document.createElementNS(null, "a");
+ Element b = document.createElementNS(null, "b");
+ element.appendChild(a);
+ element.appendChild(b);
+
+ element.insertBefore(fragment, b);
+
+ NodeList children = element.getChildNodes();
+ assertEquals(4, children.getLength());
+ assertSame(a, children.item(0));
+ assertSame(x, children.item(1));
+ assertSame(y, children.item(2));
+ assertSame(b, children.item(3));
+
+ assertSame(element, x.getParentNode());
+ assertSame(element, y.getParentNode());
+
+ assertNull(fragment.getFirstChild());
+ }
+}
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-dom-testsuite/src/main/java/org/apache/axiom/ts/dom/element/TestInsertBeforeWithDocumentFragment.java
------------------------------------------------------------------------------
svn:eol-style = native
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=1178085&r1=1178084&r2=1178085&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 Oct 1 20:17:43 2011
@@ -253,38 +253,18 @@ public abstract class ParentNode extends
DOMException.HIERARCHY_REQUEST_ERR, null));
}
}
- boolean compositeChild = newDomChild.nextSibling != null;
- ChildNode endChild = null;
-
- if(compositeChild) {
- ChildNode tempNextChild = newDomChild.nextSibling;
- while(tempNextChild != null) {
- tempNextChild.parentNode = this;
- endChild = tempNextChild;
- tempNextChild = tempNextChild.nextSibling;
- }
- }
if (refChild == null) { // Append the child to the end of the list
// if there are no children
if (this.lastChild == null && firstChild == null) {
- if(compositeChild) {
- this.lastChild = endChild;
- } else {
- this.lastChild = newDomChild;
- }
+ this.lastChild = newDomChild;
this.firstChild = newDomChild;
this.firstChild.isFirstChild(true);
newDomChild.setParent(this);
} else {
this.lastChild.nextSibling = newDomChild;
newDomChild.previousSibling = this.lastChild;
-
- if(compositeChild) {
- this.lastChild = endChild;
- } else {
- this.lastChild = newDomChild;
- }
+ this.lastChild = newDomChild;
this.lastChild.nextSibling = null;
}
if (newDomChild.parentNode == null) {
@@ -306,11 +286,20 @@ public abstract class ParentNode extends
// The new child is a DocumentFragment
DocumentFragmentImpl docFrag =
(DocumentFragmentImpl) newChild;
+
+ ChildNode child = docFrag.firstChild;
+ while (child != null) {
+ child.parentNode = this;
+ child = child.nextSibling;
+ }
+
this.firstChild = docFrag.firstChild;
docFrag.lastChild.nextSibling = refDomChild;
refDomChild.previousSibling =
docFrag.lastChild.nextSibling;
+ docFrag.firstChild = null;
+ docFrag.lastChild = null;
} else {
// Make the newNode the first Child
@@ -333,11 +322,20 @@ public abstract class ParentNode extends
DocumentFragmentImpl docFrag =
(DocumentFragmentImpl) newChild;
+ ChildNode child = docFrag.firstChild;
+ while (child != null) {
+ child.parentNode = this;
+ child = child.nextSibling;
+ }
+
previousNode.nextSibling = docFrag.firstChild;
docFrag.firstChild.previousSibling = previousNode;
docFrag.lastChild.nextSibling = refDomChild;
refDomChild.previousSibling = docFrag.lastChild;
+
+ docFrag.firstChild = null;
+ docFrag.lastChild = null;
} else {
previousNode.nextSibling = newDomChild;