Author: ruchithf
Date: Wed Mar 14 13:16:54 2007
New Revision: 518301

URL: http://svn.apache.org/viewvc?view=rev&rev=518301
Log:
Handle document fragments properly

Modified:
    
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/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?view=diff&rev=518301&r1=518300&r2=518301
==============================================================================
--- 
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
 Wed Mar 14 13:16:54 2007
@@ -204,11 +204,26 @@
                 ((DocumentImpl) this).documentElement = (ElementImpl) 
newDomChild;
             }
         }
-
+        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) {
-                this.lastChild = newDomChild;
+                if(compositeChild) {
+                    this.lastChild = endChild;
+                } else {
+                    this.lastChild = newDomChild;
+                }
                 this.firstChild = newDomChild;
                 this.firstChild.isFirstChild(true);
                 newDomChild.setParent(this);
@@ -216,7 +231,11 @@
                 this.lastChild.nextSibling = newDomChild;
                 newDomChild.previousSibling = this.lastChild;
 
-                this.lastChild = newDomChild;
+                if(compositeChild) {
+                    this.lastChild = endChild;
+                } else {
+                    this.lastChild = newDomChild;
+                }
                 this.lastChild.nextSibling = null;
             }
             if (newDomChild.parentNode == null) {
@@ -340,9 +359,15 @@
                             (DocumentFragmentImpl) newDomChild;
                     ChildNode child = (ChildNode) docFrag.getFirstChild();
                     this.replaceChild(child, oldChild);
-                    if (child != null) {
+                    
+                    //set the parent of all kids to me
+                    while(child != null) {
                         child.parentNode = this;
+                        child = child.nextSibling;
                     }
+
+                    this.lastChild = (ChildNode)docFrag.getLastChild();
+                    
                 } else {
                     if (this.firstChild == oldDomChild) {
 
@@ -357,6 +382,7 @@
 
                         //Set the new first child
                         this.firstChild = newDomChild;
+                        
 
                     } else {
                         newDomChild.nextSibling = oldDomChild.nextSibling;



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to