Author: veithen
Date: Wed Jul 16 23:24:00 2014
New Revision: 1611215

URL: http://svn.apache.org/r1611215
Log:
Move more code into the core model.

Modified:
    
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
    
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java
    
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
    
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerSupport.aj

Modified: 
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj?rev=1611215&r1=1611214&r2=1611215&view=diff
==============================================================================
--- 
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
 (original)
+++ 
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreChildNodeSupport.aj
 Wed Jul 16 23:24:00 2014
@@ -24,8 +24,8 @@ import org.apache.axiom.om.impl.builder.
 
 public aspect CoreChildNodeSupport {
     private CoreParentNode CoreChildNode.owner;
-    private CoreChildNode CoreChildNode.nextSibling;
-    private CoreChildNode CoreChildNode.previousSibling;
+    CoreChildNode CoreChildNode.nextSibling;
+    CoreChildNode CoreChildNode.previousSibling;
     
     /**
      * Check if this node has a parent.
@@ -128,12 +128,12 @@ public aspect CoreChildNodeSupport {
         } else if (this == sibling) {
             throw new OMException("Inserting self as the sibling is not 
allowed");
         }
-        // TODO: need to detach sibling (but the Axiom API impl already does 
this before calling us)
+        sibling.coreDetach(null);
         sibling.internalSetParent(parent);
         CoreChildNode nextSibling = coreGetNextSibling();
         sibling.previousSibling = this;
         if (nextSibling == null) {
-            parent.coreSetLastChild(sibling);
+            parent.lastChild = sibling;
         } else {
             nextSibling.previousSibling = sibling;
         }
@@ -149,16 +149,41 @@ public aspect CoreChildNodeSupport {
         } else if (this == sibling) {
             throw new OMException("Inserting self as the sibling is not 
allowed");
         }
-        // TODO: need to detach sibling (but the Axiom API impl already does 
this before calling us)
+        sibling.coreDetach(null);
         sibling.internalSetParent(parent);
         CoreChildNode previousSibling = this.previousSibling;
         sibling.nextSibling = this;
         if (previousSibling == null) {
-            parent.coreSetFirstChild(sibling);
+            parent.firstChild = sibling;
         } else {
             previousSibling.nextSibling = sibling;
         }
         sibling.previousSibling = previousSibling;
         this.previousSibling = sibling;
     }
+    
+    public final void CoreChildNode.coreDetach(CoreDocument newOwnerDocument) {
+        CoreParentNode parent = coreGetParent();
+        if (parent != null) {
+            // TODO: ugly hack
+            if (this instanceof CoreParentNode) {
+                ((CoreParentNode)this).build();
+            }
+            
+            if (previousSibling == null) {
+                parent.firstChild = nextSibling;
+            } else {
+                previousSibling.nextSibling = nextSibling;
+            }
+            if (nextSibling == null) {
+                parent.lastChild = previousSibling;
+            } else {
+                nextSibling.previousSibling = previousSibling;
+            }
+            previousSibling = null;
+            nextSibling = null;
+            // TODO: what if parent == null? shouldn't we always set the new 
owner document?
+            internalUnsetParent(newOwnerDocument);
+        }
+    }
 }

Modified: 
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java?rev=1611215&r1=1611214&r2=1611215&view=diff
==============================================================================
--- 
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java
 (original)
+++ 
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNode.java
 Wed Jul 16 23:24:00 2014
@@ -33,4 +33,5 @@ public interface CoreParentNode extends 
     int getState();
     void coreSetState(int state);
     boolean isComplete();
+    void build();
 }

Modified: 
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj?rev=1611215&r1=1611214&r2=1611215&view=diff
==============================================================================
--- 
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
 (original)
+++ 
webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/CoreParentNodeSupport.aj
 Wed Jul 16 23:24:00 2014
@@ -27,8 +27,8 @@ import org.apache.axiom.om.impl.builder.
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
 
 public aspect CoreParentNodeSupport {
-    private CoreChildNode CoreParentNode.firstChild;
-    private CoreChildNode CoreParentNode.lastChild;
+    CoreChildNode CoreParentNode.firstChild;
+    CoreChildNode CoreParentNode.lastChild;
     
     /**
      * Get the first child if it is available. The child is available if it is 
complete or
@@ -95,4 +95,25 @@ public aspect CoreParentNodeSupport {
         }
         return firstChild;
     }
+
+    public final void CoreParentNode.coreAppendChild(CoreChildNode child, 
boolean fromBuilder) {
+        CoreParentNode parent = child.coreGetParent();
+        if (!fromBuilder) {
+            build();
+        }
+        if (parent == this && child == lastChild) {
+            // The child is already the last node. 
+            // We don't need to detach and re-add it.
+            return;
+        }
+        child.coreDetach(null);
+        child.internalSetParent(this);
+        if (firstChild == null) {
+            firstChild = child;
+        } else {
+            child.previousSibling = lastChild;
+            lastChild.nextSibling = child;
+        }
+        lastChild = child;
+    }
 }

Modified: 
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerSupport.aj
URL: 
http://svn.apache.org/viewvc/webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerSupport.aj?rev=1611215&r1=1611214&r2=1611215&view=diff
==============================================================================
--- 
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerSupport.aj
 (original)
+++ 
webservices/axiom/trunk/modules/axiom-common-impl/src/main/java/org/apache/axiom/om/impl/common/OMContainerSupport.aj
 Wed Jul 16 23:24:00 2014
@@ -113,9 +113,6 @@ public aspect OMContainerSupport {
             child = (INode)((OMFactoryEx)getOMFactory()).importNode(omNode);
         }
         checkChild(omNode);
-        if (child.getParent() != null) {
-            child.detach();
-        }
         return child;
     }
 
@@ -126,27 +123,10 @@ public aspect OMContainerSupport {
             // the same factory
             child = (INode)omNode;
         } else {
-            if (!isComplete()) {
-                build();
-            }
-            if (omNode.getParent() == this && omNode == 
coreGetLastKnownChild()) {
-                // The child is already the last node. 
-                // We don't need to detach and re-add it.
-                return;
-            }
             child = prepareNewChild(omNode);
         }
         
-        child.internalSetParent(this);
-
-        if (coreGetFirstChildIfAvailable() == null) {
-            coreSetFirstChild(child);
-        } else {
-            CoreChildNode lastChild = coreGetLastKnownChild();
-            child.coreSetPreviousSibling(lastChild);
-            lastChild.coreSetNextSibling(child);
-        }
-        coreSetLastChild(child);
+        coreAppendChild(child, fromBuilder);
 
         // For a normal OMNode, the incomplete status is
         // propogated up the tree.  
@@ -154,6 +134,7 @@ public aspect OMContainerSupport {
         // (it has an independent parser source).
         // So only propogate the incomplete setting if this
         // is a normal OMNode
+        // TODO: this is crap and needs to be reviewed
         if (!fromBuilder && !child.isComplete() && 
             !(child instanceof OMSourcedElement)) {
             setComplete(false);


Reply via email to