ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From veit...@apache.org
Subject svn commit: r1691716 - in /webservices/axiom/trunk: aspects/core-aspects/src/main/java/org/apache/axiom/core/ aspects/dom-aspects/src/main/java/org/apache/axiom/dom/ aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/ implementations/axio...
Date Sat, 18 Jul 2015 11:08:18 GMT
Author: veithen
Date: Sat Jul 18 11:08:17 2015
New Revision: 1691716

URL: http://svn.apache.org/r1691716
Log:
Streamline the coreDetach API.

Added:
    webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java
  (with props)
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/CoreParentNodeSupport.aj
    webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMParentNodeSupport.aj
    webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTextNodeSupport.aj
    webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomChildNodeSupport.aj
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java
    webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java

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=1691716&r1=1691715&r2=1691716&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
Sat Jul 18 11:08:17 2015
@@ -121,8 +121,7 @@ public aspect CoreChildNodeSupport {
         } else if (this == sibling) {
             throw new OMException("Inserting self as the sibling is not allowed");
         }
-        sibling.coreDetach(null);
-        sibling.internalSetParent(parent);
+        sibling.internalDetach(null, parent);
         CoreChildNode nextSibling = coreGetNextSibling();
         sibling.previousSibling = this;
         if (nextSibling == null) {
@@ -142,8 +141,7 @@ public aspect CoreChildNodeSupport {
         } else if (this == sibling) {
             throw new OMException("Inserting self as the sibling is not allowed");
         }
-        sibling.coreDetach(null);
-        sibling.internalSetParent(parent);
+        sibling.internalDetach(null, parent);
         sibling.nextSibling = this;
         if (previousSibling == null) {
             parent.firstChild = sibling;
@@ -180,10 +178,15 @@ public aspect CoreChildNodeSupport {
     
     void CoreChildNode.beforeDetach() {}
     
-    public final void CoreChildNode.coreDetach(CoreDocument newOwnerDocument) {
+    public final void CoreChildNode.coreDetach(DetachPolicy detachPolicy) {
+        internalDetach(detachPolicy, null);
+    }
+    
+    final void CoreChildNode.internalDetach(DetachPolicy detachPolicy, CoreParentNode newParent)
{
         CoreParentNode parent = coreGetParent();
         if (parent != null) {
             beforeDetach();
+            CoreDocument newOwnerDocument = newParent != null ? null : detachPolicy.getNewOwnerDocument(this);
             if (previousSibling == null) {
                 parent.firstChild = nextSibling;
             } else {
@@ -196,8 +199,12 @@ public aspect CoreChildNodeSupport {
             }
             previousSibling = null;
             nextSibling = null;
-            // TODO: what if parent == null? shouldn't we always set the new owner document?
-            internalUnsetParent(newOwnerDocument);
+            if (newParent == null) {
+                internalUnsetParent(newOwnerDocument);
+            }
+        }
+        if (newParent != null) {
+            internalSetParent(newParent);
         }
     }
 }

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=1691716&r1=1691715&r2=1691716&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
Sat Jul 18 11:08:17 2015
@@ -98,8 +98,7 @@ public aspect CoreParentNodeSupport {
             // We don't need to detach and re-add it.
             return;
         }
-        child.coreDetach(null);
-        child.internalSetParent(this);
+        child.internalDetach(null, this);
         if (firstChild == null) {
             firstChild = child;
         } else {

Added: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java?rev=1691716&view=auto
==============================================================================
--- webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java
(added)
+++ webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java
Sat Jul 18 11:08:17 2015
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.core;
+
+/**
+ * Determines how child nodes are detached.
+ */
+public interface DetachPolicy {
+    /**
+     * Get the new owner document for the given child node. This method is called before
the child
+     * node is detached.
+     * 
+     * @param node
+     *            the child node
+     * @return the new owner document or <code>null</code> to (lazily) create
a new owner document
+     *         for the node
+     */
+    CoreDocument getNewOwnerDocument(CoreChildNode node);
+}

Propchange: webservices/axiom/trunk/aspects/core-aspects/src/main/java/org/apache/axiom/core/DetachPolicy.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMParentNodeSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMParentNodeSupport.aj?rev=1691716&r1=1691715&r2=1691716&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMParentNodeSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMParentNodeSupport.aj
Sat Jul 18 11:08:17 2015
@@ -68,7 +68,7 @@ public aspect DOMParentNodeSupport {
 
     public final Node DOMParentNode.removeChild(Node oldChild) throws DOMException {
         if (oldChild.getParentNode() == this) {
-            ((CoreChildNode)oldChild).coreDetach(coreGetOwnerDocument(true));
+            ((CoreChildNode)oldChild).coreDetach(Policies.DETACH_POLICY);
             return oldChild;
         } else {
             throw newDOMException(DOMException.NOT_FOUND_ERR);

Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTextNodeSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTextNodeSupport.aj?rev=1691716&r1=1691715&r2=1691716&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTextNodeSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/DOMTextNodeSupport.aj
Sat Jul 18 11:08:17 2015
@@ -84,12 +84,11 @@ public aspect DOMTextNodeSupport {
             if (newText != null) {
                 first.coreInsertSiblingBefore(newText);
             }
-            CoreDocument document = coreGetOwnerDocument(true);
             DOMTextNode current = first;
             DOMTextNode next;
             do {
                 next = current == last ? null : (DOMTextNode)current.coreGetNextSibling();
-                current.coreDetach(document);
+                current.coreDetach(Policies.DETACH_POLICY);
                 current = next;
             } while (next != null);
         }

Modified: webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java?rev=1691716&r1=1691715&r2=1691716&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java
(original)
+++ webservices/axiom/trunk/aspects/dom-aspects/src/main/java/org/apache/axiom/dom/Policies.java
Sat Jul 18 11:08:17 2015
@@ -20,7 +20,9 @@ package org.apache.axiom.dom;
 
 import org.apache.axiom.core.AttributeMatcher;
 import org.apache.axiom.core.CoreAttribute;
+import org.apache.axiom.core.CoreChildNode;
 import org.apache.axiom.core.CoreDocument;
+import org.apache.axiom.core.DetachPolicy;
 import org.apache.axiom.core.NSAwareAttributeMatcher;
 import org.apache.axiom.core.NodeFactory;
 import org.apache.axiom.core.NodeMigrationPolicy;
@@ -81,4 +83,10 @@ public final class Policies {
             return isForeignDocument ? Action.REJECT : Action.MOVE;
         }
     };
+    
+    public static final DetachPolicy DETACH_POLICY = new DetachPolicy() {
+        public CoreDocument getNewOwnerDocument(CoreChildNode node) {
+            return node.coreGetOwnerDocument(true);
+        }
+    };
 }

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomChildNodeSupport.aj
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomChildNodeSupport.aj?rev=1691716&r1=1691715&r2=1691716&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomChildNodeSupport.aj
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/AxiomChildNodeSupport.aj
Sat Jul 18 11:08:17 2015
@@ -58,7 +58,7 @@ public aspect AxiomChildNodeSupport {
             throw new OMException(
                     "Nodes that don't have a parent can not be detached");
         }
-        coreDetach(null);
+        coreDetach(Policies.DETACH_POLICY);
         return this;
     }
     

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java?rev=1691716&r1=1691715&r2=1691716&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java
(original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/common/Policies.java
Sat Jul 18 11:08:17 2015
@@ -19,6 +19,9 @@
 package org.apache.axiom.om.impl.common;
 
 import org.apache.axiom.core.AttributeMatcher;
+import org.apache.axiom.core.CoreChildNode;
+import org.apache.axiom.core.CoreDocument;
+import org.apache.axiom.core.DetachPolicy;
 import org.apache.axiom.core.NSAwareAttributeMatcher;
 import org.apache.axiom.core.NodeMigrationPolicy;
 
@@ -41,4 +44,10 @@ public final class Policies {
             return isForeignModel ? Action.CLONE : Action.MOVE;
         }
     };
+    
+    public static final DetachPolicy DETACH_POLICY = new DetachPolicy() {
+        public CoreDocument getNewOwnerDocument(CoreChildNode node) {
+            return null;
+        }
+    };
 }

Modified: webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java?rev=1691716&r1=1691715&r2=1691716&view=diff
==============================================================================
--- webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
(original)
+++ webservices/axiom/trunk/implementations/axiom-dom/src/main/java/org/apache/axiom/om/impl/dom/ParentNode.java
Sat Jul 18 11:08:17 2015
@@ -24,6 +24,7 @@ import static org.apache.axiom.dom.DOMEx
 import org.apache.axiom.core.CoreChildNode;
 import org.apache.axiom.core.CoreDocumentFragment;
 import org.apache.axiom.dom.DOMParentNode;
+import org.apache.axiom.dom.Policies;
 import org.apache.axiom.om.OMCloneOptions;
 import org.apache.axiom.om.OMFactory;
 import org.w3c.dom.DOMException;
@@ -114,7 +115,7 @@ public abstract class ParentNode extends
         }
         checkNewChild(newChild, _oldChild);
         CoreChildNode nextSibling = oldChild.coreGetNextSibling();
-        oldChild.coreDetach(coreGetOwnerDocument(true));
+        oldChild.coreDetach(Policies.DETACH_POLICY);
         if (newChild instanceof CoreChildNode) {
             if (nextSibling == null) {
                 coreAppendChild((CoreChildNode)newChild, false);



Mime
View raw message