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 2013/01/26 13:25:50 UTC

svn commit: r1438886 - in /webservices/axiom/trunk/modules: axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/ axiom-testsuite/src/main/java/org/apache/axiom/ts/om/ axiom-testsuite/src/main/jav...

Author: veithen
Date: Sat Jan 26 12:25:49 2013
New Revision: 1438886

URL: http://svn.apache.org/viewvc?rev=1438886&view=rev
Log:
Fixed an issue with insertSibling(After|Before).

Added:
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingAfterSameParent.java   (with props)
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingBeforeSameParent.java   (with props)
Modified:
    webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
    webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
    webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java?rev=1438886&r1=1438885&r2=1438886&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/NodeImpl.java Sat Jan 26 12:25:49 2013
@@ -634,6 +634,9 @@ public abstract class NodeImpl implement
         } else if (this == sibling) {
             throw new OMException("Inserting self as the sibling is not allowed");
         }
+        if (sibling.getParent() != null) {
+            sibling.detach();
+        }
         ((OMNodeEx) sibling).setParent((OMContainer)parentNode);
         if (sibling instanceof NodeImpl) {
             NodeImpl domSibling = (NodeImpl) sibling;
@@ -662,6 +665,9 @@ public abstract class NodeImpl implement
         } else if (this == sibling) {
             throw new OMException("Inserting self as the sibling is not allowed");
         }
+        if (sibling.getParent() != null) {
+            sibling.detach();
+        }
         if (sibling instanceof NodeImpl) {
             // ChildNode domSibling = (ChildNode)sibling;
             // domSibling.nextSibling = this;

Modified: webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java?rev=1438886&r1=1438885&r2=1438886&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java (original)
+++ webservices/axiom/trunk/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java Sat Jan 26 12:25:49 2013
@@ -164,6 +164,9 @@ public abstract class OMNodeImpl extends
         } else if (this == sibling) {
             throw new OMException("Inserting self as the sibling is not allowed");
         }
+        if (sibling.getParent() != null) {
+            sibling.detach();
+        }
         ((OMNodeEx) sibling).setParent(parent);
         if (sibling instanceof OMNodeImpl) {
             OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
@@ -193,6 +196,9 @@ public abstract class OMNodeImpl extends
         } else if (this == sibling) {
             throw new OMException("Inserting self as the sibling is not allowed");
         }
+        if (sibling.getParent() != null) {
+            sibling.detach();
+        }
         if (sibling instanceof OMNodeImpl) {
             OMNodeImpl siblingImpl = (OMNodeImpl) sibling;
             

Modified: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1438886&r1=1438885&r2=1438886&view=diff
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Sat Jan 26 12:25:49 2013
@@ -421,10 +421,12 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnChild(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnOrphan(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnSelf(metaFactory));
+        addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingAfterSameParent(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBefore(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnChild(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnOrphan(metaFactory));
         addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBeforeOnSelf(metaFactory));
+        addTest(new org.apache.axiom.ts.om.node.TestInsertSiblingBeforeSameParent(metaFactory));
         if (supportsOMSourcedElement) {
             for (int i=0; i<OMSourcedElementVariant.INSTANCES.length; i++) {
                 OMSourcedElementVariant variant = OMSourcedElementVariant.INSTANCES[i];

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingAfterSameParent.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingAfterSameParent.java?rev=1438886&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingAfterSameParent.java (added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingAfterSameParent.java Sat Jan 26 12:25:49 2013
@@ -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.om.node;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMNode#insertSiblingAfter(OMNode)} if the node is already a sibling.
+ */
+public class TestInsertSiblingAfterSameParent extends AxiomTestCase {
+    public TestInsertSiblingAfterSameParent(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory fac = metaFactory.getOMFactory();
+        OMElement parent = fac.createOMElement("test", null);
+        OMText text1 = fac.createOMText("text1");
+        OMText text2 = fac.createOMText("text2");
+        OMText text3 = fac.createOMText("text3");
+        parent.addChild(text1);
+        parent.addChild(text2);
+        parent.addChild(text3);
+        text1.insertSiblingAfter(text3);
+        assertSame(parent, text3.getParent());
+        Iterator it = parent.getChildren();
+        assertSame(text1, it.next());
+        assertSame(text3, it.next());
+        assertSame(text2, it.next());
+        assertFalse(it.hasNext());
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingAfterSameParent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingBeforeSameParent.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingBeforeSameParent.java?rev=1438886&view=auto
==============================================================================
--- webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingBeforeSameParent.java (added)
+++ webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingBeforeSameParent.java Sat Jan 26 12:25:49 2013
@@ -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.om.node;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.ts.AxiomTestCase;
+
+/**
+ * Tests the behavior of {@link OMNode#insertSiblingBefore(OMNode)} if the node is already a sibling.
+ */
+public class TestInsertSiblingBeforeSameParent extends AxiomTestCase {
+    public TestInsertSiblingBeforeSameParent(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    protected void runTest() throws Throwable {
+        OMFactory fac = metaFactory.getOMFactory();
+        OMElement parent = fac.createOMElement("test", null);
+        OMText text1 = fac.createOMText("text1");
+        OMText text2 = fac.createOMText("text2");
+        OMText text3 = fac.createOMText("text3");
+        parent.addChild(text1);
+        parent.addChild(text2);
+        parent.addChild(text3);
+        text2.insertSiblingBefore(text3);
+        assertSame(parent, text3.getParent());
+        Iterator it = parent.getChildren();
+        assertSame(text1, it.next());
+        assertSame(text3, it.next());
+        assertSame(text2, it.next());
+        assertFalse(it.hasNext());
+    }
+}

Propchange: webservices/axiom/trunk/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/node/TestInsertSiblingBeforeSameParent.java
------------------------------------------------------------------------------
    svn:eol-style = native