You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2009/02/05 11:57:32 UTC
svn commit: r741074 - in
/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src:
main/java/org/apache/axiom/om/impl/dom/ParentNode.java
test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java
Author: veithen
Date: Thu Feb 5 10:57:31 2009
New Revision: 741074
URL: http://svn.apache.org/viewvc?rev=741074&view=rev
Log:
WSCOMMONS-435: Applied patch provided by Andrei Ivanov and added some test cases for removeChild.
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/ElementImplTest.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=741074&r1=741073&r2=741074&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 Thu Feb 5 10:57:31 2009
@@ -481,9 +481,15 @@
if (this.firstChild == tempNode) {
// If this is the first child
- this.firstChild = null;
- this.lastChild = null;
+ ChildNode nextSib = tempNode.nextSibling;
+ this.firstChild = nextSib;
+ if (nextSib == null) {
+ this.lastChild = null;
+ } else {
+ nextSib.previousSibling = null;
+ }
tempNode.parentNode = null;
+ tempNode.nextSibling = null;
} else if (this.lastChild == tempNode) {
// not the first child, but the last child
ChildNode prevSib = tempNode.previousSibling;
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java?rev=741074&r1=741073&r2=741074&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/ElementImplTest.java Thu Feb 5 10:57:31 2009
@@ -31,6 +31,7 @@
import org.w3c.dom.Text;
import org.xml.sax.InputSource;
+import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.ByteArrayOutputStream;
@@ -88,7 +89,49 @@
}
});
}
+
+ public void testRemoveSingleChild() throws Exception {
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ Element element = builder.parse(new InputSource(new StringReader(
+ "<root><a/></root>"))).getDocumentElement();
+ element.removeChild(element.getFirstChild());
+ assertNull(element.getFirstChild());
+ assertNull(element.getLastChild());
+ }
+ });
+ }
+
+ // Regression test for WSCOMMONS-435
+ public void testRemoveFirstChild() throws Exception {
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ Element element = builder.parse(new InputSource(new StringReader(
+ "<root><a/><b/><c/></root>"))).getDocumentElement();
+ element.removeChild(element.getFirstChild());
+ Node firstChild = element.getFirstChild();
+ assertNotNull(firstChild);
+ assertEquals("b", firstChild.getNodeName());
+ }
+ });
+ }
+ public void testRemoveLastChild() throws Exception {
+ DOMTestUtil.execute(new DOMTestUtil.Test() {
+ public void execute(DocumentBuilderFactory dbf) throws Exception {
+ DocumentBuilder builder = dbf.newDocumentBuilder();
+ Element element = builder.parse(new InputSource(new StringReader(
+ "<root><a/><b/><c/></root>"))).getDocumentElement();
+ element.removeChild(element.getLastChild());
+ Node lastChild = element.getLastChild();
+ assertNotNull(lastChild);
+ assertEquals("b", lastChild.getNodeName());
+ }
+ });
+ }
+
/** Testing the NodeList returned with the elements's children */
public void testGetElementsByTagName() throws Exception {
DOMTestUtil.execute(new DOMTestUtil.Test() {