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 2012/06/30 11:30:49 UTC

svn commit: r1355675 [1/2] - in /webservices/commons/trunk/modules/axiom/modules: axiom-api/src/main/java/org/apache/axiom/om/ axiom-api/src/main/java/org/apache/axiom/om/impl/ axiom-api/src/main/java/org/apache/axiom/om/impl/builder/ axiom-api/src/mai...

Author: veithen
Date: Sat Jun 30 09:30:42 2012
New Revision: 1355675

URL: http://svn.apache.org/viewvc?rev=1355675&view=rev
Log:
AXIOM-429: Ensure that OMContainer#addChild always adds the new child as the last child.

Added:
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/document/TestAddChildIncomplete.java   (with props)
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/element/TestAddChildIncomplete.java   (with props)
Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMContainerEx.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNodeEx.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMFactoryEx.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAP11BuilderHelper.java
    webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerHelper.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
    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/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultReasonImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
    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-impl/src/main/java/org/apache/axiom/om/impl/llom/OMLeafNode.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPMessageImpl.java
    webservices/commons/trunk/modules/axiom/modules/axiom-tests/src/test/java/org/apache/axiom/om/OMBodyTest.java
    webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/OMContainer.java Sat Jun 30 09:30:42 2012
@@ -46,10 +46,10 @@ public interface OMContainer extends OMS
     OMXMLParserWrapper getBuilder();
 
     /**
-     * Adds the given node as the last child. One must preserve the order of children, in this
-     * operation. Tip : appending the new child is preferred.
-     *
+     * Adds the given node as the last child of this container.
+     * 
      * @param omNode
+     *            the node to be added to this container
      */
     // TODO: specify whether the node is removed from its original location
     // TODO: specify what happens if the node has been created by a foreign OMFactory

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMContainerEx.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMContainerEx.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMContainerEx.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMContainerEx.java Sat Jun 30 09:30:42 2012
@@ -23,10 +23,8 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMNode;
 
 /**
- * Interface OMContainerEx
- * <p/>
- * Internal Implementation detail. Adding special interface to stop folks from accidently using
- * OMContainer. Please use at your own risk. May corrupt the data integrity.
+ * Interface that is used internally by Axiom and that should not be considered being part of the
+ * public API.
  */
 public interface OMContainerEx extends OMContainer {
     public void setComplete(boolean state);
@@ -54,4 +52,8 @@ public interface OMContainerEx extends O
      *         the builder has not yet started to build the first child
      */
     public OMNode getFirstOMChildIfAvailable();
+    
+    public OMNode getLastKnownOMChild();
+    
+    public void addChild(OMNode omNode, boolean fromBuilder);
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNodeEx.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNodeEx.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNodeEx.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/OMNodeEx.java Sat Jun 30 09:30:42 2012
@@ -27,10 +27,8 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamWriter;
 
 /**
- * Interface OMNodeEx
- * <p/>
- * Internal Implementation detail. Adding special interface to stop folks from accidently using
- * OMNode. Please use at your own risk. May corrupt the data integrity.
+ * Interface that is used internally by Axiom and that should not be considered being part of the
+ * public API.
  */
 public interface OMNodeEx extends OMNode {
     public void setNextOMSibling(OMNode node);

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMFactoryEx.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMFactoryEx.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMFactoryEx.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/OMFactoryEx.java Sat Jun 30 09:30:42 2012
@@ -18,10 +18,15 @@
  */
 package org.apache.axiom.om.impl.builder;
 
+import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMDocType;
 import org.apache.axiom.om.OMDocument;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMProcessingInstruction;
+import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 
 /**
@@ -39,4 +44,17 @@ public interface OMFactoryEx extends OMF
      */
     OMElement createOMElement(String localName, OMContainer parent,
                                      OMXMLParserWrapper builder);
+
+    OMText createOMText(OMContainer parent, Object dataHandler, boolean optimize, boolean fromBuilder);
+    
+    OMText createOMText(OMContainer parent, String text, int type, boolean fromBuilder);
+    
+    OMComment createOMComment(OMContainer parent, String content, boolean fromBuilder);
+    
+    OMDocType createOMDocType(OMContainer parent, String content, boolean fromBuilder);
+    
+    OMProcessingInstruction createOMProcessingInstruction(OMContainer parent,
+            String piTarget, String piData, boolean fromBuilder);
+    
+    OMNode importNode(OMNode child);
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/SAXOMBuilder.java Sat Jun 30 09:30:42 2012
@@ -28,6 +28,7 @@ import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMElementEx;
 import org.apache.axiom.om.impl.OMNodeEx;
@@ -42,7 +43,7 @@ import java.util.List;
 
 import javax.xml.XMLConstants;
 
-public class SAXOMBuilder extends DefaultHandler implements LexicalHandler {
+public class SAXOMBuilder extends DefaultHandler implements LexicalHandler, OMXMLParserWrapper {
     private OMDocument document;
     
     OMElement root = null;
@@ -96,7 +97,7 @@ public class SAXOMBuilder extends Defaul
     }
 
     public void startDocument() throws SAXException {
-        document = factory.createOMDocument(null);
+        document = factory.createOMDocument(this);
     }
 
     public void endDocument() throws SAXException {
@@ -111,8 +112,7 @@ public class SAXOMBuilder extends Defaul
     }
 
     protected OMElement createNextElement(String localName) throws OMException {
-        OMElement element = factory.createOMElement(localName, getContainer(), null);
-        ((OMElementEx)element).setComplete(false);
+        OMElement element = factory.createOMElement(localName, getContainer(), this);
         addNode(element);
         return element;
     }
@@ -215,7 +215,7 @@ public class SAXOMBuilder extends Defaul
 
     public void characterData(char[] ch, int start, int length, int nodeType)
             throws SAXException {
-        addNode(factory.createOMText(getContainer(), new String(ch, start, length), nodeType));
+        addNode(factory.createOMText(getContainer(), new String(ch, start, length), nodeType, true));
     }
 
     public void characters(char[] ch, int start, int length)
@@ -230,7 +230,7 @@ public class SAXOMBuilder extends Defaul
 
     public void processingInstruction(String target, String data)
             throws SAXException {
-        addNode(factory.createOMProcessingInstruction(getContainer(), target, data));
+        addNode(factory.createOMProcessingInstruction(getContainer(), target, data, true));
     }
 
     public void comment(char[] ch, int start, int length) throws SAXException {
@@ -238,7 +238,7 @@ public class SAXOMBuilder extends Defaul
             // Do nothing: the comment appears before the root element.
             return;
         } 
-        addNode(factory.createOMComment(getContainer(), new String(ch, start, length)));
+        addNode(factory.createOMComment(getContainer(), new String(ch, start, length), true));
     }
 
     public void skippedEntity(String name) throws SAXException {
@@ -271,4 +271,56 @@ public class SAXOMBuilder extends Defaul
             throw new OMException("Tree not complete");
         }
     }
+
+    public int next() throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void discard(OMElement el) throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    public void setCache(boolean b) throws OMException {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean isCache() {
+        throw new UnsupportedOperationException();
+    }
+
+    public Object getParser() {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean isCompleted() {
+        throw new UnsupportedOperationException();
+    }
+
+    public OMElement getDocumentElement() {
+        throw new UnsupportedOperationException();
+    }
+
+    public OMElement getDocumentElement(boolean discardDocument) {
+        throw new UnsupportedOperationException();
+    }
+
+    public short getBuilderType() {
+        throw new UnsupportedOperationException();
+    }
+
+    public void registerExternalContentHandler(Object obj) {
+        throw new UnsupportedOperationException();
+    }
+
+    public Object getRegisteredContentHandler() {
+        throw new UnsupportedOperationException();
+    }
+
+    public String getCharacterEncoding() {
+        throw new UnsupportedOperationException();
+    }
+
+    public void close() {
+        throw new UnsupportedOperationException();
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXBuilder.java Sat Jun 30 09:30:42 2012
@@ -271,12 +271,11 @@ public abstract class StAXBuilder implem
                     throw new OMException(ex);
                 }
             }
-            OMText text = omfactory.createOMText(dataHandlerObject, dataHandlerReader.isOptimized());
+            OMText text = omfactory.createOMText(omContainer, dataHandlerObject, dataHandlerReader.isOptimized(), true);
             String contentID = dataHandlerReader.getContentID();
             if (contentID != null) {
                 text.setContentID(contentID);
             }
-            omContainer.addChild(text);
             return text;
         } else {
             // Some parsers (like Woodstox) parse text nodes lazily and may throw a
@@ -288,7 +287,7 @@ public abstract class StAXBuilder implem
                 parserException = ex;
                 throw ex;
             }
-            return omfactory.createOMText(omContainer, text, textType);
+            return omfactory.createOMText(omContainer, text, textType, true);
         }
     }
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Sat Jun 30 09:30:42 2012
@@ -341,7 +341,20 @@ public class StAXOMBuilder extends StAXB
         } else {
             parent = document;
         }
+        
+        // TODO: dirty hack part 1
+        // The custom builder will use addNode to insert the new node into the tree. However,
+        // addNode is expected to always add the new child at the end and will attempt to
+        // build the parent node. We temporarily set complete to true to avoid this.
+        // There is really an incompatibility between the contract of addNode and the
+        // custom builder API. This should be fixed in Axiom 1.3.
+        ((OMContainerEx)parent).setComplete(true);
+        
         OMNode node = customBuilder.create(namespace, localPart, parent, parser, factory);
+        
+        // TODO: dirty hack part 2
+        ((OMContainerEx)parent).setComplete(false);
+        
         if (log.isDebugEnabled()) {
             if (node != null) {
                 log.debug("The CustomBuilder, " + customBuilder.toString() + 
@@ -471,11 +484,11 @@ public class StAXOMBuilder extends StAXB
     protected OMNode createComment() throws OMException {
         OMNode node;
         if (lastNode == null) {
-            node = omfactory.createOMComment(document, parser.getText());
+            node = omfactory.createOMComment(document, parser.getText(), true);
         } else if (lastNode.isComplete()) {
-            node = omfactory.createOMComment(lastNode.getParent(), parser.getText());
+            node = omfactory.createOMComment(lastNode.getParent(), parser.getText(), true);
         } else {
-            node = omfactory.createOMComment((OMElement) lastNode, parser.getText());
+            node = omfactory.createOMComment((OMElement) lastNode, parser.getText(), true);
         }
         return node;
     }
@@ -491,7 +504,7 @@ public class StAXOMBuilder extends StAXB
             return null;
         }
         String dtdText = getDTDText();
-        lastNode = omfactory.createOMDocType(document, dtdText);
+        lastNode = omfactory.createOMDocType(document, dtdText, true);
         return lastNode;
     }
     
@@ -538,13 +551,13 @@ public class StAXOMBuilder extends StAXB
         String target = parser.getPITarget();
         String data = parser.getPIData();
         if (lastNode == null) {
-            node = omfactory.createOMProcessingInstruction(document, target, data);
+            node = omfactory.createOMProcessingInstruction(document, target, data, true);
         } else if (lastNode.isComplete()) {
-            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data);
+            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data, true);
         } else if (lastNode instanceof OMText) {
-            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data);
+            node = omfactory.createOMProcessingInstruction(lastNode.getParent(), target, data, true);
         } else {
-            node = omfactory.createOMProcessingInstruction((OMContainer) lastNode, target, data);
+            node = omfactory.createOMProcessingInstruction((OMContainer) lastNode, target, data, true);
         }
         return node;
     }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAP11BuilderHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAP11BuilderHelper.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAP11BuilderHelper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/soap/impl/builder/SOAP11BuilderHelper.java Sat Jun 30 09:30:42 2012
@@ -20,6 +20,7 @@
 package org.apache.axiom.soap.impl.builder;
 
 import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.exception.OMBuilderException;
 import org.apache.axiom.soap.SOAP11Constants;
@@ -144,9 +145,9 @@ public class SOAP11BuilderHelper extends
             int token = parser.next();
             while (token != XMLStreamReader.END_ELEMENT) {
                 if (token == XMLStreamReader.CHARACTERS) {
-                    factory.createOMText(value, parser.getText());
+                    factory.createOMText(value, parser.getText(), OMNode.TEXT_NODE, true);
                 } else if (token == XMLStreamReader.CDATA) {
-                    factory.createOMText(value, parser.getText());
+                    factory.createOMText(value, parser.getText(), OMNode.TEXT_NODE, true);
                 } else {
                     throw new SOAPProcessingException(
                     "Only Characters are allowed here");

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerHelper.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerHelper.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerHelper.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerHelper.java Sat Jun 30 09:30:42 2012
@@ -21,9 +21,14 @@ package org.apache.axiom.om.impl.common;
 import javax.xml.stream.XMLStreamReader;
 
 import org.apache.axiom.om.OMContainer;
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.OMXMLStreamReader;
 import org.apache.axiom.om.OMXMLStreamReaderConfiguration;
+import org.apache.axiom.om.impl.OMContainerEx;
+import org.apache.axiom.om.impl.OMNodeEx;
+import org.apache.axiom.om.impl.builder.OMFactoryEx;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.util.OMXMLStreamReaderValidator;
 import org.apache.commons.logging.Log;
@@ -84,4 +89,53 @@ public final class OMContainerHelper {
         return reader;
     }
     
+    public static void addChild(OMContainerEx container, OMNode omNode, boolean fromBuilder) {
+        OMNodeEx child;
+        if (fromBuilder) {
+            // If the new child was provided by the builder, we know that it was created by
+            // the same factory
+            child = (OMNodeEx)omNode;
+        } else {
+            // Careful here: if the child was created by another Axiom implementation, it doesn't
+            // necessarily implement OMNodeEx
+            if (omNode.getOMFactory().getMetaFactory() == container.getOMFactory().getMetaFactory()) {
+                child = (OMNodeEx)omNode;
+            } else {
+                child = (OMNodeEx)((OMFactoryEx)container.getOMFactory()).importNode(omNode);
+            }
+            if (!container.isComplete()) {
+                container.build();
+            }
+            if (child.getParent() == container && child == container.getLastKnownOMChild()) {
+                // The child is already the last node. 
+                // We don't need to detach and re-add it.
+                return;
+            }
+        }
+        if (child.getParent() != null) {
+            child.detach();
+        }
+        
+        child.setParent(container);
+
+        if (container.getFirstOMChildIfAvailable() == null) {
+            container.setFirstChild(child);
+        } else {
+            OMNode lastChild = container.getLastKnownOMChild();
+            child.setPreviousOMSibling(lastChild);
+            ((OMNodeEx)lastChild).setNextOMSibling(child);
+        }
+        container.setLastChild(child);
+
+        // For a normal OMNode, the incomplete status is
+        // propogated up the tree.  
+        // However, a OMSourcedElement is self-contained 
+        // (it has an independent parser source).
+        // So only propogate the incomplete setting if this
+        // is a normal OMNode
+        if (!child.isComplete() && 
+            !(child instanceof OMSourcedElement)) {
+            container.setComplete(false);
+        }
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/DocumentFragmentImpl.java Sat Jun 30 09:30:42 2012
@@ -22,6 +22,7 @@ package org.apache.axiom.om.impl.dom;
 import org.apache.axiom.om.OMCloneOptions;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.OMContainerEx;
 import org.w3c.dom.DocumentFragment;
 import org.w3c.dom.Node;
 
@@ -29,7 +30,7 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamWriter;
 
 public class DocumentFragmentImpl extends RootNode implements
-        DocumentFragment {
+        DocumentFragment, OMContainerEx {
 
     private ParentNode ownerNode;
     

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ElementImpl.java Sat Jun 30 09:30:42 2012
@@ -111,7 +111,7 @@ public class ElementImpl extends ParentN
         this.builder = builder;
         this.done = builder == null;
         if (parentNode != null) {
-            parentNode.addChild(this);
+            parentNode.addChild(this, builder != null);
         }
         this.attributes = new AttributeMap(this);
         namespace = generateNSDecl ? handleNamespace(ns) : ns;

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=1355675&r1=1355674&r2=1355675&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 Jun 30 09:30:42 2012
@@ -20,31 +20,25 @@
 package org.apache.axiom.om.impl.dom;
 
 import org.apache.axiom.om.OMCloneOptions;
-import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMDocType;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMProcessingInstruction;
 import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.OMXMLStreamReaderConfiguration;
+import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.common.OMChildrenLocalNameIterator;
 import org.apache.axiom.om.impl.common.OMChildrenNamespaceIterator;
 import org.apache.axiom.om.impl.common.OMChildrenQNameIterator;
 import org.apache.axiom.om.impl.common.OMContainerHelper;
 import org.apache.axiom.om.impl.common.OMDescendantsIterator;
-import org.apache.axiom.om.impl.dom.factory.OMDOMFactory;
 import org.apache.axiom.om.impl.jaxp.OMSource;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
 import org.w3c.dom.DOMException;
 import org.w3c.dom.Document;
-import org.w3c.dom.Element;
 import org.w3c.dom.Node;
 import org.w3c.dom.NodeList;
 
@@ -73,11 +67,11 @@ public abstract class ParentNode extends
     }
     
     public void addChild(OMNode omNode) {
-        if (omNode.getOMFactory() instanceof OMDOMFactory) {
-            insertBefore((Node)omNode, null, false);
-        } else {
-            addChild(importNode(omNode));
-        }
+        addChild(omNode, false);
+    }
+
+    public void addChild(OMNode omNode, boolean fromBuilder) {
+        OMContainerHelper.addChild((OMContainerEx)this, omNode, fromBuilder);
     }
 
     public void buildNext() {
@@ -150,6 +144,10 @@ public abstract class ParentNode extends
         return (OMNode)firstChild;
     }
 
+    public OMNode getLastKnownOMChild() {
+        return (OMNode)lastChild;
+    }
+
     public void setFirstChild(OMNode omNode) {
         if (firstChild != null) {
             ((OMNodeEx) omNode).setParent((OMContainer)this);
@@ -516,68 +514,6 @@ public abstract class ParentNode extends
     
     abstract ParentNode shallowClone(OMCloneOptions options, ParentNode targetParent, boolean namespaceRepairing);
 
-    /**
-     * This method is intended only to be used by Axiom intenals when merging Objects from different
-     * Axiom implementations to the DOOM implementation.
-     *
-     * @param child
-     */
-    protected OMNode importNode(OMNode child) {
-        int type = child.getType();
-        switch (type) {
-            case (OMNode.ELEMENT_NODE): {
-                OMElement childElement = (OMElement) child;
-                OMElement newElement = (new StAXOMBuilder(this.factory,
-                                                          childElement.getXMLStreamReader()))
-                        .getDocumentElement();
-                newElement.build();
-                return (OMNode)ownerDocument().importNode((Element) newElement,
-                                                          true);
-            }
-            case (OMNode.TEXT_NODE): {
-                OMText importedText = (OMText) child;
-                OMText newText;
-                if (importedText.isBinary()) {
-                    boolean isOptimize = importedText.isOptimized();
-                    newText = this.factory.createOMText(importedText
-                            .getDataHandler(), isOptimize);
-                } else if (importedText.isCharacters()) {
-                    newText = new TextImpl(importedText.getTextCharacters(), this.factory);
-                } else {
-                    newText = new TextImpl(importedText.getText(), this.factory);
-                }
-                return newText;
-            }
-
-            case (OMNode.PI_NODE): {
-                OMProcessingInstruction importedPI = (OMProcessingInstruction) child;
-                OMProcessingInstruction newPI = this.factory
-                        .createOMProcessingInstruction((OMContainer)this,
-                                                       importedPI.getTarget(),
-                                                       importedPI.getValue());
-                return newPI;
-            }
-            case (OMNode.COMMENT_NODE): {
-                OMComment importedComment = (OMComment) child;
-                OMComment newComment = this.factory.createOMComment((OMContainer)this,
-                                                                    importedComment.getValue());
-                newComment = new CommentImpl(importedComment.getValue(),
-                                             this.factory);
-                return newComment;
-            }
-            case (OMNode.DTD_NODE): {
-                OMDocType importedDocType = (OMDocType) child;
-                OMDocType newDocType = this.factory.createOMDocType((OMContainer)this,
-                                                                    importedDocType.getValue());
-                return newDocType;
-            }
-            default: {
-                throw new UnsupportedOperationException(
-                        "Not Implemented Yet for the given node type");
-            }
-        }
-    }
-    
     public String getTextContent() throws DOMException {
         Node child = getFirstChild();
         if (child != null) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/factory/OMDOMFactory.java Sat Jun 30 09:30:42 2012
@@ -36,7 +36,9 @@ import org.apache.axiom.om.OMProcessingI
 import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.builder.OMFactoryEx;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.dom.AttrImpl;
 import org.apache.axiom.om.impl.dom.CDATASectionImpl;
@@ -194,6 +196,10 @@ public class OMDOMFactory implements OMF
     }
 
     public OMText createOMText(OMContainer parent, String text, int type) {
+        return createOMText(parent, text, type, false);
+    }
+    
+    public OMText createOMText(OMContainer parent, String text, int type, boolean fromBuilder) {
         if (parent == null) {
             return createOMText(text, type);
         } else if (parent instanceof DocumentImpl) {
@@ -206,7 +212,7 @@ public class OMDOMFactory implements OMF
             } else {
                 txt = new TextImpl(text, type, this);
             }
-            parent.addChild(txt);
+            ((OMContainerEx)parent).addChild(txt, fromBuilder);
             return txt;
         }
     }
@@ -263,7 +269,16 @@ public class OMDOMFactory implements OMF
      * @see org.apache.axiom.om.OMFactory#createOMText(Object, boolean)
      */
     public OMText createOMText(Object dataHandler, boolean optimize) {
-        return new TextImpl(dataHandler, optimize, this);
+        return createOMText(null, dataHandler, optimize, false);
+    }
+
+    public OMText createOMText(OMContainer parent, Object dataHandler, boolean optimize,
+            boolean fromBuilder) {
+        TextImpl text = new TextImpl(dataHandler, optimize, this);
+        if (parent != null) {
+            ((OMContainerEx)parent).addChild(text, fromBuilder);
+        }
+        return text;
     }
 
     public OMText createOMText(String contentID, DataHandlerProvider dataHandlerProvider,
@@ -298,28 +313,41 @@ public class OMDOMFactory implements OMF
     }
 
     public OMDocType createOMDocType(OMContainer parent, String content) {
+        return createOMDocType(parent, content, false);
+    }
+    
+    public OMDocType createOMDocType(OMContainer parent, String content, boolean fromBuilder) {
         DocumentTypeImpl docType = new DocumentTypeImpl(this);
         docType.setValue(content);
         if (parent != null) {
-            parent.addChild(docType);
+            ((OMContainerEx)parent).addChild(docType, fromBuilder);
         }
         return docType;
     }
 
     public OMProcessingInstruction createOMProcessingInstruction(
             OMContainer parent, String piTarget, String piData) {
+        return createOMProcessingInstruction(parent, piTarget, piData, false);
+    }
+    
+    public OMProcessingInstruction createOMProcessingInstruction(
+            OMContainer parent, String piTarget, String piData, boolean fromBuilder) {
         ProcessingInstructionImpl pi =
             new ProcessingInstructionImpl(piTarget, piData, this);
         if (parent != null) {
-            parent.addChild(pi);
+            ((OMContainerEx)parent).addChild(pi, fromBuilder);
         }
         return pi;
     }
 
     public OMComment createOMComment(OMContainer parent, String content) {
+        return createOMComment(parent, content, false);
+    }
+    
+    public OMComment createOMComment(OMContainer parent, String content, boolean fromBuilder) {
         CommentImpl comment = new CommentImpl(content, this);
         if (parent != null) {
-            parent.addChild(comment);
+            ((OMContainerEx)parent).addChild(comment, fromBuilder);
         }
         return comment;
     }
@@ -327,4 +355,61 @@ public class OMDOMFactory implements OMF
     public OMDocument createOMDocument(OMXMLParserWrapper builder) {
         return new DocumentImpl(builder, this);
     }
+
+    /**
+     * This method is intended only to be used by Axiom intenals when merging Objects from different
+     * Axiom implementations to the DOOM implementation.
+     *
+     * @param child
+     */
+    public OMNode importNode(OMNode child) {
+        int type = child.getType();
+        switch (type) {
+            case (OMNode.ELEMENT_NODE): {
+                OMElement childElement = (OMElement) child;
+                OMElement newElement = (new StAXOMBuilder(this,
+                                                          childElement.getXMLStreamReader()))
+                        .getDocumentElement();
+                newElement.build();
+                return newElement;
+            }
+            case (OMNode.TEXT_NODE): {
+                OMText importedText = (OMText) child;
+                OMText newText;
+                if (importedText.isBinary()) {
+                    boolean isOptimize = importedText.isOptimized();
+                    newText = createOMText(importedText
+                            .getDataHandler(), isOptimize);
+                } else if (importedText.isCharacters()) {
+                    newText = new TextImpl(importedText.getTextCharacters(), this);
+                } else {
+                    newText = new TextImpl(importedText.getText(), this);
+                }
+                return newText;
+            }
+
+            case (OMNode.PI_NODE): {
+                OMProcessingInstruction importedPI = (OMProcessingInstruction) child;
+                OMProcessingInstruction newPI =
+                        createOMProcessingInstruction(null, importedPI.getTarget(),
+                                                       importedPI.getValue());
+                return newPI;
+            }
+            case (OMNode.COMMENT_NODE): {
+                OMComment importedComment = (OMComment) child;
+                OMComment newComment = createOMComment(null, importedComment.getValue());
+                newComment = new CommentImpl(importedComment.getValue(), this);
+                return newComment;
+            }
+            case (OMNode.DTD_NODE): {
+                OMDocType importedDocType = (OMDocType) child;
+                OMDocType newDocType = createOMDocType(null, importedDocType.getValue());
+                return newDocType;
+            }
+            default: {
+                throw new UnsupportedOperationException(
+                        "Not Implemented Yet for the given node type");
+            }
+        }
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java Sat Jun 30 09:30:42 2012
@@ -100,7 +100,7 @@ public class SOAPEnvelopeImpl extends SO
         }
     }
 
-    public void addChild(OMNode child) {
+    public void addChild(OMNode child, boolean fromBuilder) {
         // SOAP 1.1 allows for arbitrary elements after SOAPBody so do NOT check for
         // node types when appending to SOAP 1.1 envelope.
         if (getVersion() instanceof SOAP12Version) {
@@ -137,7 +137,7 @@ public class SOAPEnvelopeImpl extends SO
                 }
             }
         }
-        super.addChild(child);
+        super.addChild(child, fromBuilder);
     }
 
     public Node insertBefore(Node newChild, Node refChild) throws DOMException {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPMessageImpl.java Sat Jun 30 09:30:42 2012
@@ -54,7 +54,7 @@ public class SOAPMessageImpl extends Doc
 
     public void setSOAPEnvelope(SOAPEnvelope envelope)
             throws SOAPProcessingException {
-        this.addChild(envelope);
+        this.addChild(envelope, true);
     }
 
     protected void internalSerialize(XMLStreamWriter writer, boolean cache,

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap11/SOAP11FaultReasonImpl.java Sat Jun 30 09:30:42 2012
@@ -94,6 +94,6 @@ public class SOAP11FaultReasonImpl exten
 
     protected OMElement createClone(OMCloneOptions options, ParentNode targetParent,
             boolean generateNSDecl) {
-        return new SOAP11FaultReasonImpl(targetParent, namespace, builder, factory, generateNSDecl);
+        return new SOAP11FaultReasonImpl(targetParent, namespace, null, factory, generateNSDecl);
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultReasonImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultReasonImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultReasonImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/soap12/SOAP12FaultReasonImpl.java Sat Jun 30 09:30:42 2012
@@ -68,6 +68,6 @@ public class SOAP12FaultReasonImpl exten
 
     protected OMElement createClone(OMCloneOptions options, ParentNode targetParent,
             boolean generateNSDecl) {
-        return new SOAP12FaultReasonImpl(targetParent, namespace, builder, factory, generateNSDecl);
+        return new SOAP12FaultReasonImpl(targetParent, namespace, null, factory, generateNSDecl);
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/OMImplementationTest.java Sat Jun 30 09:30:42 2012
@@ -27,6 +27,7 @@ import org.apache.axiom.ts.om.builder.Te
 import org.apache.axiom.ts.om.container.TestSerialize;
 import org.apache.axiom.ts.om.document.TestDigest;
 import org.apache.axiom.ts.om.element.TestGetChildrenWithName4;
+import org.apache.axiom.ts.om.element.TestSerializationWithTwoNonBuiltOMElements;
 import org.apache.axiom.ts.om.factory.TestCreateOMElementWithGeneratedPrefix;
 import org.apache.axiom.ts.om.factory.TestCreateOMElementWithNamespaceInScope1;
 import org.apache.axiom.ts.om.node.TestInsertSiblingAfterOnChild;
@@ -64,6 +65,9 @@ public class OMImplementationTest extend
         // TODO: if there is a comment node surrounded by text, then these text nodes need to be merged
         builder.exclude(TestDigest.class, "(|(file=digest3.xml)(file=digest4.xml))");
         
+        // TODO
+        builder.exclude(TestSerializationWithTwoNonBuiltOMElements.class);
+        
         return builder.build();
     }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMCommentImpl.java Sat Jun 30 09:30:42 2012
@@ -38,8 +38,8 @@ public class OMCommentImpl extends OMLea
      * @param contentText
      */
     public OMCommentImpl(OMContainer parentNode, String contentText,
-                         OMFactory factory) {
-        super(parentNode, factory);
+                         OMFactory factory, boolean fromBuilder) {
+        super(parentNode, factory, fromBuilder);
         this.value = contentText;
     }
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocTypeImpl.java Sat Jun 30 09:30:42 2012
@@ -38,20 +38,11 @@ public class OMDocTypeImpl extends OMLea
      * @param contentText
      */
     public OMDocTypeImpl(OMContainer parentNode, String contentText,
-                         OMFactory factory) {
-        super(parentNode, factory);
+                         OMFactory factory, boolean fromBuilder) {
+        super(parentNode, factory, fromBuilder);
         this.value = contentText;
     }
 
-    /**
-     * Constructor OMDocTypeImpl.
-     *
-     * @param parentNode
-     */
-    public OMDocTypeImpl(OMContainer parentNode, OMFactory factory) {
-        this(parentNode, null, factory);
-    }
-
     public final int getType() {
         return OMNode.DTD_NODE;
     }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMDocumentImpl.java Sat Jun 30 09:30:42 2012
@@ -24,12 +24,10 @@ import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.OMXMLStreamReaderConfiguration;
 import org.apache.axiom.om.impl.MTOMXMLStreamWriter;
 import org.apache.axiom.om.impl.OMContainerEx;
-import org.apache.axiom.om.impl.OMNodeEx;
 import org.apache.axiom.om.impl.common.OMChildrenLocalNameIterator;
 import org.apache.axiom.om.impl.common.OMChildrenNamespaceIterator;
 import org.apache.axiom.om.impl.common.OMChildrenQNameIterator;
@@ -110,16 +108,12 @@ public class OMDocumentImpl extends OMSe
     }
 
     public OMElement getOMDocumentElement() {
-        return getOMDocumentElement(true);
-    }
-
-    private OMElement getOMDocumentElement(boolean build) {
-        OMNode child = build ? getFirstOMChild() : getFirstOMChildIfAvailable();
+        OMNode child = getFirstOMChild();
         while (child != null) {
             if (child instanceof OMElement) {
                 return (OMElement)child;
             }
-            child = build ? child.getNextOMSibling() : ((OMNodeEx)child).getNextOMSiblingIfAvailable();
+            child = child.getNextOMSibling();
         }
         return null;
     }
@@ -155,45 +149,15 @@ public class OMDocumentImpl extends OMSe
         this.done = state;
     }
 
-    /**
-     * Adds child to the element. One can decide whether to append the child or to add to the front
-     * of the children list.
-     *
-     * @param child
-     */
     public void addChild(OMNode child) {
-        if (child instanceof OMElement) {
-            if (getOMDocumentElement(false) == null) {
-                addChild((OMNodeImpl) child);
-            } else {
-                throw new OMException("Document element already exists");
-            }
-        } else {
-            addChild((OMNodeImpl) child);
-        }
+        addChild(child, false);
     }
 
-    /**
-     * Method addChild.
-     *
-     * @param child
-     */
-    private void addChild(OMNodeImpl child) {
-        if (firstChild == null) {
-            firstChild = child;
-            child.setPreviousOMSibling(null);
-        } else {
-            child.setPreviousOMSibling(lastChild);
-            ((OMNodeEx) lastChild).setNextOMSibling(child);
-        }
-        child.setNextOMSibling(null);
-        child.setParent(this);
-        lastChild = child;
-
-        if (!child.isComplete() && 
-            !(child instanceof OMSourcedElement)) {
-            this.setComplete(false);
+    public void addChild(OMNode omNode, boolean fromBuilder) {
+        if (!fromBuilder && omNode instanceof OMElement && getOMDocumentElement() != null) {
+            throw new OMException("Document element already exists");
         }
+        OMContainerHelper.addChild(this, omNode, fromBuilder);
     }
 
     /**
@@ -249,6 +213,10 @@ public class OMDocumentImpl extends OMSe
         return firstChild;
     }
 
+    public OMNode getLastKnownOMChild() {
+        return lastChild;
+    }
+
     /**
      * Method getFirstChildWithName.
      *

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=1355675&r1=1355674&r2=1355675&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 Sat Jun 30 09:30:42 2012
@@ -28,7 +28,6 @@ import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.OMXMLStreamReaderConfiguration;
 import org.apache.axiom.om.impl.OMContainerEx;
@@ -45,7 +44,6 @@ import org.apache.axiom.om.impl.common.O
 import org.apache.axiom.om.impl.common.OMElementImplUtil;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.jaxp.OMSource;
-import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
 import org.apache.axiom.om.impl.traverse.OMChildrenIterator;
 import org.apache.axiom.om.impl.util.EmptyIterator;
 import org.apache.axiom.om.impl.util.OMSerializerUtil;
@@ -120,7 +118,7 @@ public class OMElementImpl extends OMNod
         this.builder = builder;
         this.done = builder == null;
         if (parent != null) {
-            parent.addChild(this);
+            ((OMContainerEx)parent).addChild(this, builder != null);
         }
         this.ns = generateNSDecl ? handleNamespace(ns) : ns;
     }
@@ -219,18 +217,13 @@ public class OMElementImpl extends OMNod
         }
     }
 
-    /**
-     * Adds child to the element. One can decide whether to append the child or to add to the front
-     * of the children list.
-     */
-    public void addChild(OMNode child) {
-        if (child.getOMFactory() instanceof OMLinkedListImplFactory) {
-            addChild((OMNodeImpl) child);
-        } else {
-            addChild(importNode(child));
-        }
+    public void addChild(OMNode omNode) {
+        addChild(omNode, false);
     }
 
+    public void addChild(OMNode omNode, boolean fromBuilder) {
+        OMContainerHelper.addChild(this, omNode, fromBuilder);
+    }
 
     /**
      * Searches for children with a given QName and returns an iterator to traverse through the
@@ -295,45 +288,6 @@ public class OMElementImpl extends OMNod
 
     }
 
-    /** Method addChild. */
-    private void addChild(OMNodeImpl child) {
-        if (child.parent == this && child == lastChild && done) {
-            // The child is already the last node. 
-            // We don't need to detach and re-add it.
-        } else {
-            // Normal Case
-            
-            if (child.parent != null) {
-                child.detach();
-            }
-            
-            child.setParent(this);
-
-            if (firstChild == null) {
-                firstChild = child;
-                child.previousSibling = null;
-            } else {
-                child.previousSibling = (OMNodeImpl) lastChild;
-                ((OMNodeImpl) lastChild).nextSibling = child;
-            }
-
-            child.nextSibling = null;
-            lastChild = child;
-        }
-
-        // For a normal OMNode, the incomplete status is
-        // propogated up the tree.  
-        // However, a OMSourcedElement is self-contained 
-        // (it has an independent parser source).
-        // So only propogate the incomplete setting if this
-        // is a normal OMNode
-        if (!child.isComplete() && 
-            !(child instanceof OMSourcedElement)) {
-            this.setComplete(false);
-        }
-
-    }
-
     /**
      * Returns a collection of this element. Children can be of types OMElement, OMText.
      *
@@ -696,6 +650,9 @@ public class OMElementImpl extends OMNod
         return firstChild;
     }
 
+    public OMNode getLastKnownOMChild() {
+        return lastChild;
+    }
 
     /** Method setFirstChild. */
     public void setFirstChild(OMNode firstChild) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMLeafNode.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMLeafNode.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMLeafNode.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMLeafNode.java Sat Jun 30 09:30:42 2012
@@ -22,12 +22,13 @@ import org.apache.axiom.om.OMContainer;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMXMLParserWrapper;
+import org.apache.axiom.om.impl.OMContainerEx;
 
 public abstract class OMLeafNode extends OMNodeImpl {
-    public OMLeafNode(OMContainer parent, OMFactory factory) {
+    public OMLeafNode(OMContainer parent, OMFactory factory, boolean fromBuilder) {
         super(factory);
         if (parent != null) {
-            parent.addChild(this);
+            ((OMContainerEx)parent).addChild(this, fromBuilder);
         }
     }
 

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMNodeImpl.java Sat Jun 30 09:30:42 2012
@@ -23,18 +23,13 @@ import javax.xml.stream.XMLStreamExcepti
 import javax.xml.stream.XMLStreamWriter;
 
 import org.apache.axiom.om.OMCloneOptions;
-import org.apache.axiom.om.OMComment;
 import org.apache.axiom.om.OMContainer;
-import org.apache.axiom.om.OMDocType;
-import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMFactory;
 import org.apache.axiom.om.OMNode;
-import org.apache.axiom.om.OMProcessingInstruction;
-import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.impl.OMContainerEx;
 import org.apache.axiom.om.impl.OMNodeEx;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.builder.OMFactoryEx;
 import org.apache.axiom.om.impl.llom.factory.OMLinkedListImplFactory;
 
 /** Class OMNodeImpl */
@@ -121,7 +116,7 @@ public abstract class OMNodeImpl extends
         if (node == null || node.getOMFactory() instanceof OMLinkedListImplFactory) {
             this.nextSibling = (OMNodeImpl) node;
         } else {
-            this.nextSibling = (OMNodeImpl) importNode(node);
+            this.nextSibling = (OMNodeImpl) ((OMFactoryEx)factory).importNode(node);
         }
         this.nextSibling = (OMNodeImpl) node;
     }
@@ -234,7 +229,7 @@ public abstract class OMNodeImpl extends
                 previousSibling.getOMFactory() instanceof OMLinkedListImplFactory) {
             this.previousSibling = (OMNodeImpl) previousSibling;
         } else {
-            this.previousSibling = (OMNodeImpl) importNode(previousSibling);
+            this.previousSibling = (OMNodeImpl) ((OMFactoryEx)factory).importNode(previousSibling);
         }
     }
 
@@ -252,60 +247,6 @@ public abstract class OMNodeImpl extends
         }
     }
 
-    /**
-     * This method is intended only to be used by Axiom intenals when merging Objects from different
-     * Axiom implementations to the LLOM implementation.
-     *
-     * @param child
-     */
-    protected OMNode importNode(OMNode child) {
-        int type = child.getType();
-        switch (type) {
-            case (OMNode.ELEMENT_NODE): {
-                OMElement childElement = (OMElement) child;
-                OMElement newElement = (new StAXOMBuilder(this.factory, childElement
-                        .getXMLStreamReader())).getDocumentElement();
-                newElement.buildWithAttachments();
-                return newElement;
-            }
-            case (OMNode.TEXT_NODE): {
-                OMText importedText = (OMText) child;
-                OMText newText;
-                if (importedText.isBinary()) {
-                    boolean isOptimize = importedText.isOptimized();
-                    newText = this.factory.createOMText(importedText
-                            .getDataHandler(), isOptimize);
-                } else if (importedText.isCharacters()) {
-                    newText = this.factory.createOMText(null, importedText
-                            .getTextCharacters(), importedText.getType());
-                } else {
-                    newText = this.factory.createOMText(null, importedText
-                            .getText()/*, importedText.getOMNodeType()*/);
-                }
-                return newText;
-            }
-
-            case (OMNode.PI_NODE): {
-                OMProcessingInstruction importedPI = (OMProcessingInstruction) child;
-                return factory.createOMProcessingInstruction(null,
-                                                                  importedPI.getTarget(),
-                                                                  importedPI.getValue());
-            }
-            case (OMNode.COMMENT_NODE): {
-                OMComment importedComment = (OMComment) child;
-                return factory.createOMComment(null, importedComment.getValue());
-            }
-            case (OMNode.DTD_NODE) : {
-                OMDocType importedDocType = (OMDocType) child;
-                return factory.createOMDocType(null, importedDocType.getValue());
-            }
-            default: {
-                throw new UnsupportedOperationException(
-                        "Not Implemented Yet for the given node type");
-            }
-        }
-    }
-
     public void internalSerialize(XMLStreamWriter writer) throws XMLStreamException {
         internalSerialize(writer, true);
     }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMProcessingInstructionImpl.java Sat Jun 30 09:30:42 2012
@@ -40,22 +40,12 @@ public class OMProcessingInstructionImpl
      * @param value
      */
     public OMProcessingInstructionImpl(OMContainer parentNode, String target,
-                                       String value, OMFactory factory) {
-        super(parentNode, factory);
+                                       String value, OMFactory factory, boolean fromBuilder) {
+        super(parentNode, factory, fromBuilder);
         this.target = target;
         this.value = value;
     }
 
-    /**
-     * Constructor OMProcessingInstructionImpl.
-     *
-     * @param parentNode
-     */
-    public OMProcessingInstructionImpl(OMContainer parentNode,
-                                       OMFactory factory) {
-        this(parentNode, null, null, factory);
-    }
-
     public final int getType() {
         return OMNode.PI_NODE;
     }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMSourcedElementImpl.java Sat Jun 30 09:30:42 2012
@@ -839,6 +839,11 @@ public class OMSourcedElementImpl extend
         super.addChild(omNode);
     }
 
+    public void addChild(OMNode omNode, boolean fromBuilder) {
+        forceExpand();
+        super.addChild(omNode, fromBuilder);
+    }
+
     public Iterator getChildrenWithName(QName elementQName) {
         forceExpand();
         return super.getChildrenWithName(elementQName);
@@ -878,6 +883,10 @@ public class OMSourcedElementImpl extend
         return super.getFirstOMChildIfAvailable();
     }
 
+    public OMNode getLastKnownOMChild() {
+        return super.getLastKnownOMChild();
+    }
+
     public void buildNext() {
         forceExpand();
         super.buildNext();

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/OMTextImpl.java Sat Jun 30 09:30:42 2012
@@ -86,7 +86,7 @@ public class OMTextImpl extends OMLeafNo
      *                 Constants for this can be found in OMNode.
      */
     public OMTextImpl(String s, int nodeType, OMFactory factory) {
-        this(null, s, nodeType, factory);
+        this(null, s, nodeType, factory, false);
     }
 
     /**
@@ -96,7 +96,7 @@ public class OMTextImpl extends OMLeafNo
      * @param text
      */
     public OMTextImpl(OMContainer parent, String text, OMFactory factory) {
-        this(parent, text, TEXT_NODE, factory);
+        this(parent, text, TEXT_NODE, factory, false);
     }
     
     /**
@@ -106,7 +106,7 @@ public class OMTextImpl extends OMLeafNo
      * @param factory
      */
     public OMTextImpl(OMContainer parent, OMTextImpl source, OMFactory factory) {
-        super(parent, factory);
+        super(parent, factory, false);
         // Copy the value of the text
         this.value = source.value;
         this.nodeType = source.nodeType;
@@ -134,15 +134,15 @@ public class OMTextImpl extends OMLeafNo
     }
 
     public OMTextImpl(OMContainer parent, String text, int nodeType,
-                      OMFactory factory) {
-        super(parent, factory);
+                      OMFactory factory, boolean fromBuilder) {
+        super(parent, factory, fromBuilder);
         this.value = text == null ? EMTPY_STRING : text;
         this.nodeType = nodeType;
     }
 
     public OMTextImpl(OMContainer parent, char[] charArray, int nodeType,
                       OMFactory factory) {
-        super(parent, factory);
+        super(parent, factory, false);
         this.charArray = charArray;
         this.nodeType = nodeType;
     }
@@ -154,7 +154,7 @@ public class OMTextImpl extends OMLeafNo
 
     public OMTextImpl(OMContainer parent, QName text, int nodeType,
                       OMFactory factory) {
-        super(parent, factory);
+        super(parent, factory, false);
         if (text == null) throw new IllegalArgumentException("QName text arg cannot be null!");
         this.calcNS = true;
         this.textNS =
@@ -188,15 +188,15 @@ public class OMTextImpl extends OMLeafNo
 
     /** @param dataHandler To send binary optimised content Created programatically. */
     public OMTextImpl(Object dataHandler, OMFactory factory) {
-        this(dataHandler, true, factory);
+        this(null, dataHandler, true, factory, false);
     }
 
     /**
      * @param dataHandler
      * @param optimize    To send binary content. Created progrmatically.
      */
-    public OMTextImpl(Object dataHandler, boolean optimize, OMFactory factory) {
-        super(factory);
+    public OMTextImpl(OMContainer parent, Object dataHandler, boolean optimize, OMFactory factory, boolean fromBuilder) {
+        super(parent, factory, fromBuilder);
         this.dataHandlerObject = dataHandler;
         this.isBinary = true;
         this.optimize = optimize;

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/om/impl/llom/factory/OMLinkedListImplFactory.java Sat Jun 30 09:30:42 2012
@@ -30,11 +30,13 @@ import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMException;
 import org.apache.axiom.om.OMMetaFactory;
 import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMNode;
 import org.apache.axiom.om.OMProcessingInstruction;
 import org.apache.axiom.om.OMSourcedElement;
 import org.apache.axiom.om.OMText;
 import org.apache.axiom.om.OMXMLParserWrapper;
 import org.apache.axiom.om.impl.builder.OMFactoryEx;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 import org.apache.axiom.om.impl.common.OMNamespaceImpl;
 import org.apache.axiom.om.impl.llom.OMAttributeImpl;
 import org.apache.axiom.om.impl.llom.OMCommentImpl;
@@ -189,7 +191,11 @@ public class OMLinkedListImplFactory imp
     }
 
     public OMText createOMText(OMContainer parent, String text, int type) {
-        return new OMTextImpl(parent, text, type, this);
+        return createOMText(parent, text, type, false);
+    }
+
+    public OMText createOMText(OMContainer parent, String text, int type, boolean fromBuilder) {
+        return new OMTextImpl(parent, text, type, this, fromBuilder);
     }
 
     public OMText createOMText(OMContainer parent, char[] charArary, int type) {
@@ -234,7 +240,11 @@ public class OMLinkedListImplFactory imp
      * @return Returns OMText.
      */
     public OMText createOMText(Object dataHandler, boolean optimize) {
-        return new OMTextImpl(dataHandler, optimize, this);
+        return createOMText(null, dataHandler, optimize, false);
+    }
+
+    public OMText createOMText(OMContainer parent, Object dataHandler, boolean optimize, boolean fromBuilder) {
+        return new OMTextImpl(parent, dataHandler, optimize, this, fromBuilder);
     }
 
     public OMText createOMText(String contentID, DataHandlerProvider dataHandlerProvider,
@@ -292,7 +302,11 @@ public class OMLinkedListImplFactory imp
      * @return Returns doctype.
      */
     public OMDocType createOMDocType(OMContainer parent, String content) {
-        return new OMDocTypeImpl(parent, content, this);
+        return createOMDocType(parent, content, false);
+    }
+
+    public OMDocType createOMDocType(OMContainer parent, String content, boolean fromBuilder) {
+        return new OMDocTypeImpl(parent, content, this, fromBuilder);
     }
 
     /**
@@ -305,7 +319,12 @@ public class OMLinkedListImplFactory imp
      */
     public OMProcessingInstruction createOMProcessingInstruction(OMContainer parent,
                                                                  String piTarget, String piData) {
-        return new OMProcessingInstructionImpl(parent, piTarget, piData, this);
+        return createOMProcessingInstruction(parent, piTarget, piData, false);
+    }
+
+    public OMProcessingInstruction createOMProcessingInstruction(OMContainer parent,
+            String piTarget, String piData, boolean fromBuilder) {
+        return new OMProcessingInstructionImpl(parent, piTarget, piData, this, fromBuilder);
     }
 
     /**
@@ -316,7 +335,11 @@ public class OMLinkedListImplFactory imp
      * @return Returns OMComment.
      */
     public OMComment createOMComment(OMContainer parent, String content) {
-        return new OMCommentImpl(parent, content, this);
+        return createOMComment(parent, content, false);
+    }
+
+    public OMComment createOMComment(OMContainer parent, String content, boolean fromBuilder) {
+        return new OMCommentImpl(parent, content, this, fromBuilder);
     }
 
     /* (non-Javadoc)
@@ -332,4 +355,58 @@ public class OMLinkedListImplFactory imp
     public OMDocument createOMDocument(OMXMLParserWrapper builder) {
         return new OMDocumentImpl(builder, this);
     }
+
+    /**
+     * This method is intended only to be used by Axiom intenals when merging Objects from different
+     * Axiom implementations to the LLOM implementation.
+     *
+     * @param child
+     */
+    public OMNode importNode(OMNode child) {
+        int type = child.getType();
+        switch (type) {
+            case (OMNode.ELEMENT_NODE): {
+                OMElement childElement = (OMElement) child;
+                OMElement newElement = (new StAXOMBuilder(this, childElement
+                        .getXMLStreamReader())).getDocumentElement();
+                newElement.buildWithAttachments();
+                return newElement;
+            }
+            case (OMNode.TEXT_NODE): {
+                OMText importedText = (OMText) child;
+                OMText newText;
+                if (importedText.isBinary()) {
+                    boolean isOptimize = importedText.isOptimized();
+                    newText = createOMText(importedText
+                            .getDataHandler(), isOptimize);
+                } else if (importedText.isCharacters()) {
+                    newText = createOMText(null, importedText
+                            .getTextCharacters(), importedText.getType());
+                } else {
+                    newText = createOMText(null, importedText
+                            .getText()/*, importedText.getOMNodeType()*/);
+                }
+                return newText;
+            }
+
+            case (OMNode.PI_NODE): {
+                OMProcessingInstruction importedPI = (OMProcessingInstruction) child;
+                return createOMProcessingInstruction(null,
+                                                                  importedPI.getTarget(),
+                                                                  importedPI.getValue());
+            }
+            case (OMNode.COMMENT_NODE): {
+                OMComment importedComment = (OMComment) child;
+                return createOMComment(null, importedComment.getValue());
+            }
+            case (OMNode.DTD_NODE) : {
+                OMDocType importedDocType = (OMDocType) child;
+                return createOMDocType(null, importedDocType.getValue());
+            }
+            default: {
+                throw new UnsupportedOperationException(
+                        "Not Implemented Yet for the given node type");
+            }
+        }
+    }
 }

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPBodyImpl.java Sat Jun 30 09:30:42 2012
@@ -235,9 +235,9 @@ public abstract class SOAPBodyImpl exten
         }
     }
 
-    public void addChild(OMNode child) {
+    public void addChild(OMNode child, boolean fromBuilder) {
         this.enableLookAhead = false;
-        super.addChild(child);
+        super.addChild(child, fromBuilder);
     }
 
     protected OMElement createClone(OMCloneOptions options, OMContainer targetParent) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java Sat Jun 30 09:30:42 2012
@@ -112,7 +112,7 @@ public class SOAPEnvelopeImpl extends SO
      * Add a SOAPHeader or SOAPBody object
      * @param child an OMNode to add - must be either a SOAPHeader or a SOAPBody
      */
-    public void addChild(OMNode child) {
+    public void addChild(OMNode child, boolean fromBuilder) {
         // SOAP 1.1 allows for arbitrary elements after SOAPBody so do NOT check for
         // node types when appending to SOAP 1.1 envelope.
         if (getVersion() instanceof SOAP12Version) {
@@ -149,7 +149,7 @@ public class SOAPEnvelopeImpl extends SO
                 }
             }
         }
-        super.addChild(child);        
+        super.addChild(child, fromBuilder);        
     }
     
     /**

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPHeaderImpl.java Sat Jun 30 09:30:42 2012
@@ -174,7 +174,7 @@ public abstract class SOAPHeaderImpl ext
     }
 
     
-    public void addChild(OMNode child) {
+    public void addChild(OMNode child, boolean fromBuilder) {
         
         // Make sure a proper element is added.  The children of a SOAPHeader should be
         // SOAPHeaderBlock objects.
@@ -189,7 +189,7 @@ public abstract class SOAPHeaderImpl ext
                 log.debug(exceptionToString(e));
             }
         }
-        super.addChild(child);
+        super.addChild(child, fromBuilder);
     }
     
     public static String exceptionToString(Throwable e) {

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPMessageImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPMessageImpl.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPMessageImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPMessageImpl.java Sat Jun 30 09:30:42 2012
@@ -52,7 +52,7 @@ public class SOAPMessageImpl extends OMD
     }
 
     public void setSOAPEnvelope(SOAPEnvelope envelope) throws SOAPProcessingException {
-        super.addChild(envelope);
+        super.addChild(envelope, true);
     }
 
     public void setOMDocumentElement(OMElement rootElement) {

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=1355675&r1=1355674&r2=1355675&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 Sat Jun 30 09:30:42 2012
@@ -45,10 +45,10 @@ public class OMBodyTest extends OMTestCa
      * Class under test for SOAPFault addFault()
      */
     public void testAddFault() {
+        SOAPBody soapBody = soapFactory.createSOAPBody();
         log.debug("Adding SOAP fault to body ....");
-        soapBody.addChild(
-                soapFactory.createSOAPFault(soapBody,
-                                            new Exception("Testing soap fault")));
+        soapFactory.createSOAPFault(soapBody,
+                                    new Exception("Testing soap fault"));
         log.debug("\t checking for SOAP Fault ...");
         assertTrue("SOAP body has no SOAP fault", soapBody.hasFault());
         log.debug("\t checking for not-nullity ...");

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1355675&r1=1355674&r2=1355675&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Sat Jun 30 09:30:42 2012
@@ -101,6 +101,7 @@ public class OMTestSuiteBuilder extends 
                 }
             }
         }
+        addTest(new org.apache.axiom.ts.om.document.TestAddChildIncomplete(metaFactory));
         addTest(new org.apache.axiom.ts.om.document.TestDigest(metaFactory, "digest1.xml", "MD5", "3e5d68c6607bc56c9c171560e4f19db9"));
         addTest(new org.apache.axiom.ts.om.document.TestDigest(metaFactory, "digest2.xml", "SHA1", "3c47a807517d867d42ffacb2d3e9da81895d5aac"));
         addTest(new org.apache.axiom.ts.om.document.TestDigest(metaFactory, "digest3.xml", "SHA", "41466144c1cab4234fb127cfb8cf92f9"));
@@ -128,6 +129,7 @@ public class OMTestSuiteBuilder extends 
         addTest(new org.apache.axiom.ts.om.element.TestAddAttributeWithoutNamespace(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestAddChild(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestAddChild2(metaFactory));
+        addTest(new org.apache.axiom.ts.om.element.TestAddChildIncomplete(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestAddChildWithParent(metaFactory));
         addTest(new org.apache.axiom.ts.om.element.TestAddChildWithSameParent(metaFactory, true));
         addTest(new org.apache.axiom.ts.om.element.TestAddChildWithSameParent(metaFactory, false));