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 sc...@apache.org on 2007/09/21 03:35:09 UTC

svn commit: r577957 - in /webservices/commons/trunk/modules/axiom/modules: axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java axiom-tests/src/test/java/org/apache/axiom/om/OMBodyTest.java

Author: scheu
Date: Thu Sep 20 18:35:09 2007
New Revision: 577957

URL: http://svn.apache.org/viewvc?rev=577957&view=rev
Log:
WSCOMMONS-217
Contributor:Rich Scheuerle
Small adjustment to avoid corruption of nextSibling and prevSibling pointers.
Also added a validation test.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMBodyTest.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java?rev=577957&r1=577956&r2=577957&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMElementImpl.java Thu Sep 20 18:35:09 2007
@@ -231,23 +231,31 @@
 
     /** Method addChild. */
     private void addChild(OMNodeImpl child) {
-        //the order of these statements is VERY important
-        //Since setting the parent has a detach method inside
-        //it strips down all the rerefences to siblings.
-        //setting the siblings should take place AFTER setting the parent
+        if (child.parent == this &&
+            child == lastChild) {
+            // The child is already the last node. 
+            // We don't need to detach and re-add it.
+        } else {
+            // Normal Case
+            
+            // The order of these statements is VERY important
+            // Since setting the parent has a detach method inside
+            // it strips down all the rerefences to siblings.
+            // setting the siblings should take place AFTER setting the parent
 
-        child.setParent(this);
+            child.setParent(this);
 
-        if (firstChild == null) {
-            firstChild = child;
-            child.previousSibling = null;
-        } else {
-            child.previousSibling = (OMNodeImpl) lastChild;
-            ((OMNodeImpl) lastChild).nextSibling = child;
-        }
+            if (firstChild == null) {
+                firstChild = child;
+                child.previousSibling = null;
+            } else {
+                child.previousSibling = (OMNodeImpl) lastChild;
+                ((OMNodeImpl) lastChild).nextSibling = child;
+            }
 
-        child.nextSibling = null;
-        lastChild = child;
+            child.nextSibling = null;
+            lastChild = child;
+        }
 
         if (!child.isComplete()) {
             this.setComplete(false);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMBodyTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMBodyTest.java?rev=577957&r1=577956&r2=577957&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMBodyTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMBodyTest.java Thu Sep 20 18:35:09 2007
@@ -1,62 +1,91 @@
-/*
- * 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.om;
-
-import org.apache.axiom.soap.SOAPBody;
-import org.apache.axiom.soap.SOAPProcessingException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-public class OMBodyTest extends OMTestCase implements OMConstants {
-    SOAPBody soapBody;
-    private Log log = LogFactory.getLog(getClass());
-
-    public OMBodyTest(String testName) {
-        super(testName);
-    }
-
-    /*
-     * @see TestCase#setUp()
-     */
-    protected void setUp() throws Exception {
-        super.setUp();
-        soapBody = soapEnvelope.getBody();
-    }
-
-    /*
-     * Class under test for SOAPFault addFault()
-     */
-    public void testAddFault() {
-        log.debug("Adding SOAP fault to body ....");
-        try {
-            soapBody.addChild(
-                    soapFactory.createSOAPFault(soapBody,
-                                                new Exception("Testing soap fault")));
-        } catch (SOAPProcessingException e) {
-            log.info(e.getMessage());
-            fail(e.getMessage());
-        }
-        log.debug("\t checking for SOAP Fault ...");
-        assertTrue("SOAP body has no SOAP fault", soapBody.hasFault());
-        log.debug("\t checking for not-nullity ...");
-        assertTrue("SOAP body has no SOAP fault", soapBody.getFault() != null);
-    }
-
-}
+/*
+ * 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.om;
+
+import org.apache.axiom.soap.SOAPBody;
+import org.apache.axiom.soap.SOAPProcessingException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.xml.namespace.QName;
+
+public class OMBodyTest extends OMTestCase implements OMConstants {
+    SOAPBody soapBody;
+    private Log log = LogFactory.getLog(getClass());
+
+    public OMBodyTest(String testName) {
+        super(testName);
+    }
+
+    /*
+     * @see TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        super.setUp();
+        soapBody = soapEnvelope.getBody();
+    }
+
+    /*
+     * Class under test for SOAPFault addFault()
+     */
+    public void testAddFault() {
+        log.debug("Adding SOAP fault to body ....");
+        try {
+            soapBody.addChild(
+                    soapFactory.createSOAPFault(soapBody,
+                                                new Exception("Testing soap fault")));
+        } catch (SOAPProcessingException e) {
+            log.info(e.getMessage());
+            fail(e.getMessage());
+        }
+        log.debug("\t checking for SOAP Fault ...");
+        assertTrue("SOAP body has no SOAP fault", soapBody.hasFault());
+        log.debug("\t checking for not-nullity ...");
+        assertTrue("SOAP body has no SOAP fault", soapBody.getFault() != null);
+    }
+    
+    /**
+     * Ensure that invoking addChild twice on the same element only
+     * adds the child one time.
+     */
+    public void testAddChildTwice() {
+        log.debug("Add Child Twice");
+        OMElement om1 = soapFactory.createOMElement("child1", "http://myChild", "pre");
+        OMElement om2 = soapFactory.createOMElement("child2", "http://myChild", "pre");
+        soapBody.addChild(om1);
+        soapBody.addChild(om1);  // NOOP..Expected behavior: child removed and then added
+        soapBody.addChild(om2);
+        
+        OMElement node = (OMElement) soapBody.
+          getFirstChildWithName(new QName("http://myChild", "child1"));
+        node = (OMElement) node.detach();
+        
+        assertTrue("Node is missing", node != null);
+        assertTrue("Node has the wrong name " + node.getLocalName(), 
+                   node.getLocalName().equals("child1"));
+        
+        node = (OMElement) soapBody.
+          getFirstChildWithName(new QName("http://myChild", "child2"));
+        assertTrue("Node is missing", node != null);
+        assertTrue("Node has the wrong name " + node.getLocalName(), 
+                   node.getLocalName().equals("child2"));
+    }
+
+}



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: commons-dev-help@ws.apache.org