jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r431866 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state: ItemState.java NodeState.java PropertyState.java SessionItemStateManager.java
Date Wed, 16 Aug 2006 09:15:55 GMT
Author: mreutegg
Date: Wed Aug 16 02:15:54 2006
New Revision: 431866

URL: http://svn.apache.org/viewvc?rev=431866&view=rev
Log:
- Implement remove on NodeState and PropertyState.
- Use new remove method in SessionItemStateManager.

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java?rev=431866&r1=431865&r2=431866&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemState.java
Wed Aug 16 02:15:54 2006
@@ -381,6 +381,20 @@
     }
 
     /**
+     * Returns <code>true</code> if this item state is valid, that is its status
+     * is one of:
+     * <ul>
+     * <li>{@link #STATUS_EXISTING}</li>
+     * <li>{@link #STATUS_EXISTING_MODIFIED}</li>
+     * <li>{@link #STATUS_NEW}</li>
+     * </ul>
+     * @return
+     */
+    public boolean isValid() {
+        return status == STATUS_EXISTING || status == STATUS_EXISTING_MODIFIED || status
== STATUS_NEW;
+    }
+
+    /**
      * Returns the parent <code>NodeState</code> or <code>null</code>
      * if either this item state represents the root node or this item state is
      * 'free floating', i.e. not attached to the repository's hierarchy.
@@ -449,6 +463,17 @@
     public ItemState getOverlayedState() {
         return overlayedState;
     }
+
+    /**
+     * Removes this item state. This will change the status of this property
+     * state to either {@link #STATUS_EXISTING_REMOVED} or {@link
+     * #STATUS_REMOVED} depending on the current status.
+     *
+     * @throws ItemStateException if an error occurs while removing this item
+     *                            state. e.g. this item state is not valid
+     *                            anymore.
+     */
+    public abstract void remove() throws ItemStateException;
 
     /**
      * Add an <code>ItemStateListener</code>

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=431866&r1=431865&r2=431866&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
Wed Aug 16 02:15:54 2006
@@ -565,6 +565,36 @@
     }
 
     /**
+     * Notifies this node state that a child node state has been removed.
+     *
+     * @param nodeState the node state that has been removed.
+     * @throws IllegalArgumentException if <code>this</code> is not the parent
+     *                                  of <code>nodeState</code>.
+     */
+    synchronized void childNodeStateRemoved(NodeState nodeState) {
+        if (nodeState.getParent() != this) {
+            throw new IllegalArgumentException("This NodeState is not the parent of nodeState");
+        }
+        // if nodeState does not exist anymore remove its child node entry
+        if (nodeState.getStatus() == STATUS_REMOVED) {
+            List entries = getChildNodeEntries(nodeState.getName());
+            for (Iterator it = entries.iterator(); it.hasNext(); ) {
+                ChildNodeEntry cne = (ChildNodeEntry) it.next();
+                try {
+                    if (cne.getNodeState() == nodeState) {
+                        childNodeEntries.remove(cne);
+                        break;
+                    }
+                } catch (ItemStateException e) {
+                    // does not exist anymore? TODO: better error handling
+                    log.warn("child node entry does not exist anymore", e);
+                }
+            }
+        }
+        markModified();
+    }
+
+    /**
      * Sets the list of <code>ChildNodeEntry</code> objects denoting the
      * child nodes of this node.
      */
@@ -579,6 +609,43 @@
     }
 
     /**
+
+    /**
+     * @inheritDoc
+     * @see ItemState#remove()
+     */
+    public void remove() throws ItemStateException {
+        if (!isValid()) {
+            throw new ItemStateException("cannot remove an invalid NodeState");
+        }
+        // first remove all properties
+        for (Iterator it = properties.values().iterator(); it.hasNext(); ) {
+            PropertyState propState = ((ChildPropertyEntry) it.next()).getPropertyState();
+            if (propState.isValid()) {
+                propState.remove();
+            } else {
+                // already removed
+            }
+        }
+        // then remove child node entries
+        for (Iterator it = childNodeEntries.iterator(); it.hasNext(); ) {
+            NodeState nodeState = ((ChildNodeEntry) it.next()).getNodeState();
+            if (nodeState.isValid()) {
+                nodeState.remove();
+            } else {
+                // already removed
+            }
+        }
+        if (status == STATUS_EXISTING || status == STATUS_EXISTING_MODIFIED) {
+            setStatus(STATUS_EXISTING_REMOVED);
+        } else if (status == STATUS_NEW) {
+            setStatus(STATUS_REMOVED);
+        }
+        // now inform parent
+        parent.childNodeStateRemoved(this);
+    }
+
+    /**
      * Determines if there is a property entry with the specified
      * <code>QName</code>.
      *
@@ -655,6 +722,25 @@
      */
     synchronized boolean removePropertyName(QName propName) {
         return properties.remove(propName) != null;
+    }
+
+    /**
+     * Notifies this node state that a property state has been removed.
+     *
+     * @param propState the property state that has been removed.
+     * @throws IllegalArgumentException if <code>this</code> is not the parent
+     *                                  of <code>propState</code>.
+     */
+    synchronized void propertyStateRemoved(PropertyState propState) {
+        if (propState.getParent() != this) {
+            throw new IllegalArgumentException("This NodeState is not the parent of propState");
+        }
+        // remove property state from map of properties if it does not exist
+        // anymore, otherwise leave the property state in the map
+        if (propState.getStatus() == STATUS_REMOVED) {
+            properties.remove(propState.getQName());
+        }
+        markModified();
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java?rev=431866&r1=431865&r2=431866&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyState.java
Wed Aug 16 02:15:54 2006
@@ -96,6 +96,18 @@
     }
 
     /**
+     * @inheritDoc
+     */
+    public void remove() {
+        if (status == STATUS_NEW) {
+            setStatus(STATUS_REMOVED);
+        } else {
+            setStatus(STATUS_EXISTING_REMOVED);
+        }
+        parent.propertyStateRemoved(this);
+    }
+
+    /**
      * {@inheritDoc}
      */
     protected synchronized void copy(ItemState state) {

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=431866&r1=431865&r2=431866&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
Wed Aug 16 02:15:54 2006
@@ -1339,7 +1339,6 @@
         }
     }
 
-    // TODO: TO-BE-FIXED. removal of same-name-sibling node must include reordering
     private void removeItemState(ItemState itemState, int options) throws RepositoryException
{
         // DIFF JR: check for both, node- and propertyState
         validator.checkRemoveItem(itemState, options);
@@ -1347,13 +1346,10 @@
         // recursively remove the complete tree including the given node state.
         boolean success = false;
         try {
-            NodeState parent = itemState.getParent();
-            if (itemState.isNode()) {
-                removeNodeState(parent, (NodeState)itemState);
-            } else {
-                removePropertyState(parent, (PropertyState)itemState);
-            }
+            itemState.remove();
             success = true;
+        } catch (ItemStateException e) {
+            throw new RepositoryException("Cannot remove item: " + e.getMessage(), e);
         } finally {
             if (!success) {
                 // TODO: undo state modifications
@@ -1362,90 +1358,6 @@
     }
 
     /**
-     * Unlinks the specified node state from its parent and recursively
-     * removes it including its properties and child nodes.
-     * <p/>
-     * Note that no checks (access rights etc.) are performed on the specified
-     * target node state. Those checks have to be performed beforehand by the
-     * caller. However, the (recursive) removal of target node's child nodes are
-     * subject to the following checks: access rights, locking, versioning.
-     *
-     * @param target
-     */
-    private void removeNodeState(NodeState parent, NodeState target) throws ItemNotFoundException,
RepositoryException {
-        // TODO: implement this functionality in NodeState. i.e. target.remove()
-        // remove child node entry from parent
-        parent.removeChildNodeEntry(target.getNodeId());
-        // remove target
-        recursiveRemoveNodeState(target);
-    }
-
-    /**
-     *
-     * @param parent
-     * @param target
-     */
-    private void removePropertyState(NodeState parent, PropertyState target) {
-        // TODO: implement this functionality in PropertyState. i.e. target.remove()
-        // remove property entry
-        parent.removePropertyName(target.getQName());
-        // destroy property state
-        // DIFF JR: notification of transient item state manager is done using ItemStateLifeCycleListener
-        //destroy(target);
-        target.notifyStateDiscarded();
-    }
-
-    /**
-     * Recursively removes the given node state including its child states.
-     * <p/>
-     * The removal of child nodes is subject to the following checks:
-     * access rights, locking & versioning status. Referential integrity
-     * (references) is checked on commit.
-     * <p/>
-     * Note that the child node entry refering to <code>targetState</code> is
-     * <b><i>not</i></b> automatically removed from <code>targetState</code>'s
-     * parent.
-     *
-     * // TODO fix description
-     *
-     * @param targetState
-     */
-    private void recursiveRemoveNodeState(NodeState targetState) throws RepositoryException
 {
-        if (targetState.hasChildNodeEntries()) {
-            // remove child nodes
-            // use temp array to avoid ConcurrentModificationException
-            Iterator tmpIter = new ArrayList(targetState.getChildNodeEntries()).iterator();
-            // remove from tail to avoid problems with same-name siblings
-            while (tmpIter.hasNext()) {
-                ChildNodeEntry entry = (ChildNodeEntry) tmpIter.next();
-                try {
-                    NodeState child = entry.getNodeState();
-                    // remove child node
-                    // DIFF JR: don't recheck permission for child states
-                    // DIFF JR: jr first calls recursive-method then removes c-n-entry
-                    removeNodeState(targetState, child);
-                } catch (ItemStateException e) {
-                    // ignore
-                    // TODO: check if correct
-                }
-            }
-        }
-
-        // remove properties
-        Iterator tmpIter = new HashSet(targetState.getPropertyEntries()).iterator();
-        while (tmpIter.hasNext()) {
-            ChildPropertyEntry entry = (PropertyReference) tmpIter.next();
-            try {
-                PropertyState child = entry.getPropertyState();
-                removePropertyState(targetState, child);
-            } catch (ItemStateException e) {
-                // ignore
-                // TODO: check if correct
-            }
-        }
-    }
-
-    /**
      *
      * @param propState
      * @param iva
@@ -1571,4 +1483,4 @@
             throw new RepositoryException(msg, e);
         }
     }
-}
\ No newline at end of file
+}



Mime
View raw message