You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by an...@apache.org on 2006/10/02 12:13:07 UTC

svn commit: r451945 - /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java

Author: angela
Date: Mon Oct  2 03:13:05 2006
New Revision: 451945

URL: http://svn.apache.org/viewvc?view=rev&rev=451945
Log:
work in progress

- cleanup todos (remove methods marked from deletion)
- reorder methods
- remove public access modf. from methods used by sessionISM only.

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java?view=diff&rev=451945&r1=451944&r2=451945
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/TransientItemStateManager.java Mon Oct  2 03:13:05 2006
@@ -22,7 +22,6 @@
 import org.apache.jackrabbit.spi.IdFactory;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
-import org.apache.commons.collections.iterators.IteratorChain;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -73,76 +72,15 @@
         ((TransientISFactory) getTransientFactory()).setListener(this);
     }
 
-    //-----------------------< ItemStateManager >-------------------------------
-    /**
-     * Return the root node state.
-     *
-     * @return the root node state.
-     * @throws ItemStateException if an error occurs while retrieving the root
-     *                            node state.
-     * @see ItemStateManager#getRootState()
-     */
-    public NodeState getRootState() throws ItemStateException {
-        if (rootNodeState == null) {
-            rootNodeState = getItemStateFactory().createRootState(this);
-            rootNodeState.addListener(this);
-        }
-        return rootNodeState;
-    }
-
-    /**
-     * Return an item state given its id. Please note that this implementation
-     * also returns item states that are in removed state ({@link
-     * ItemState.STATUS_EXISTING_REMOVED} but not yet saved.
-     *
-     * @return item state.
-     * @throws NoSuchItemStateException if there is no item state (not even a
-     *                                  removed item state) with the given id.
-     * @see ItemStateManager#getItemState(ItemId)
-     */
-    public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException {
-        return super.getItemState(id);
-    }
-
-    /**
-     * Return a flag indicating whether a given item state exists.
-     *
-     * @return <code>true</code> if item state exists within this item state
-     *         manager; <code>false</code> otherwise
-     * @see ItemStateManager#hasItemState(ItemId)
-     */
-    public boolean hasItemState(ItemId id) {
-        return super.hasItemState(id);
-    }
-
-    /**
-     * Always throws an {@link UnsupportedOperationException}. A transient item
-     * state manager cannot not maintain node references.
-     *
-     * @param nodeState
-     * @throws UnsupportedOperationException
-     * @see ItemStateManager#getReferingStates(NodeState)
-     */
-    public Collection getReferingStates(NodeState nodeState) {
-        throw new UnsupportedOperationException("getNodeReferences() not implemented");
-    }
 
-    /**
-     * Always throws an {@link UnsupportedOperationException}. A transient item
-     * state manager cannot not maintain node references.
-     *
-     * @param nodeState
-     * @throws UnsupportedOperationException
-     * @see ItemStateManager#hasReferingStates(NodeState)
-     */
-    public boolean hasReferingStates(NodeState nodeState) {
-        throw new UnsupportedOperationException("hasNodeReferences() not implemented");
+    private TransientItemStateFactory getTransientFactory() {
+        return (TransientItemStateFactory) getItemStateFactory();
     }
 
     /**
      * @return the operations that have been recorded until now.
      */
-    public Iterator getOperations() {
+    Iterator getOperations() {
         return changeLog.getOperations();
     }
 
@@ -168,35 +106,11 @@
     /**
      * @return <code>true</code> if this transient ISM has pending changes.
      */
-    public boolean hasPendingChanges() {
+    boolean hasPendingChanges() {
         return !changeLog.isEmpty();
     }
 
     /**
-     * @return <code>true</code> if there are any deleted item states.
-     */
-    public boolean hasDeletedItemStates() {
-        return !changeLog.deletedStates.isEmpty();
-    }
-
-    /**
-     * @return an iterator over all modified or added item states.
-     */
-    public Iterator getModifiedOrAddedItemStates() {
-        IteratorChain it = new IteratorChain();
-        it.addIterator(changeLog.modifiedStates());
-        it.addIterator(changeLog.addedStates());
-        return it;
-    }
-
-    /**
-     * @return an iterator over all deleted item states.
-     */
-    public Iterator getDeletedItemStates() {
-        return changeLog.deletedStates();
-    }
-
-    /**
      * TODO: throw ItemExistsException? how to check?
      * Creates a new transient {@link NodeState} that does not overlay any other
      * {@link NodeState}.
@@ -245,7 +159,7 @@
      * Disposes this transient item state manager. Clears all references to
      * transiently modified item states.
      */
-    public void dispose() {
+    void dispose() {
         changeLog.reset();
     }
 
@@ -254,45 +168,80 @@
      *
      * @param operations the operations.
      */
-    public void disposeOperations(Iterator operations) {
+    void disposeOperations(Iterator operations) {
         while (operations.hasNext()) {
             changeLog.removeOperation((Operation) operations.next());
         }
     }
 
+    //---------------------------------------------------< ItemStateManager >---
     /**
-     * TODO: remove this method when not used anymore
-     * Return an iterator over all added states.
+     * Return the root node state.
      *
-     * @return iterator over all added states.
+     * @return the root node state.
+     * @throws ItemStateException if an error occurs while retrieving the root
+     *                            node state.
+     * @see ItemStateManager#getRootState()
      */
-    public Iterator addedStates() {
-        return changeLog.addedStates();
+    public NodeState getRootState() throws ItemStateException {
+        if (rootNodeState == null) {
+            rootNodeState = getItemStateFactory().createRootState(this);
+            rootNodeState.addListener(this);
+        }
+        return rootNodeState;
     }
 
     /**
-     * TODO: remove this method when not used anymore
-     * Return an iterator over all modified states.
+     * Return an item state given its id. Please note that this implementation
+     * also returns item states that are in removed state ({@link
+     * ItemState.STATUS_EXISTING_REMOVED} but not yet saved.
      *
-     * @return iterator over all modified states.
+     * @return item state.
+     * @throws NoSuchItemStateException if there is no item state (not even a
+     *                                  removed item state) with the given id.
+     * @see ItemStateManager#getItemState(ItemId)
      */
-    public Iterator modifiedStates() {
-        return changeLog.modifiedStates();
+    public ItemState getItemState(ItemId id) throws NoSuchItemStateException, ItemStateException {
+        return super.getItemState(id);
     }
 
     /**
-     * TODO: remove this method when not used anymore
-     * Return an iterator over all deleted states.
+     * Return a flag indicating whether a given item state exists.
      *
-     * @return iterator over all deleted states.
+     * @return <code>true</code> if item state exists within this item state
+     *         manager; <code>false</code> otherwise
+     * @see ItemStateManager#hasItemState(ItemId)
      */
-    public Iterator deletedStates() {
-        return changeLog.deletedStates();
+    public boolean hasItemState(ItemId id) {
+        return super.hasItemState(id);
     }
 
-    //-----------------------< ItemStateLifeCycleListener >---------------------
+    /**
+     * Always throws an {@link UnsupportedOperationException}. A transient item
+     * state manager cannot not maintain node references.
+     *
+     * @param nodeState
+     * @throws UnsupportedOperationException
+     * @see ItemStateManager#getReferingStates(NodeState)
+     */
+    public Collection getReferingStates(NodeState nodeState) {
+        throw new UnsupportedOperationException("getNodeReferences() not implemented");
+    }
 
     /**
+     * Always throws an {@link UnsupportedOperationException}. A transient item
+     * state manager cannot not maintain node references.
+     *
+     * @param nodeState
+     * @throws UnsupportedOperationException
+     * @see ItemStateManager#hasReferingStates(NodeState)
+     */
+    public boolean hasReferingStates(NodeState nodeState) {
+        throw new UnsupportedOperationException("hasNodeReferences() not implemented");
+    }
+
+    //-----------------------------------------< ItemStateLifeCycleListener >---
+    /**
      * @inheritDoc
      * @see ItemStateListener#stateCreated(ItemState)
      */
@@ -326,26 +275,31 @@
         // go into the modified set of the change log, etc.
         switch (state.getStatus()) {
             case ItemState.STATUS_EXISTING:
-                if (previousStatus == ItemState.STATUS_EXISTING_MODIFIED) {
-                    // was modified and is now refreshed
-                    changeLog.modifiedStates.remove(state);
-                } else if (previousStatus == ItemState.STATUS_EXISTING_REMOVED) {
-                    // was removed and is now refreshed
-                    changeLog.deletedStates.remove(state);
-                } else if (previousStatus == ItemState.STATUS_STALE_MODIFIED) {
-                    // was modified and state and is now refreshed
-                    changeLog.modifiedStates.remove(state);
-                } else if (previousStatus == ItemState.STATUS_NEW) {
-                    // was new and has been saved now
-                    changeLog.addedStates.remove(state);
-                    // state needs to be connected to the overlayed-state now
-                    try {
-                        ItemState overlayedState = parent.getItemState(state.getId());
-                        state.connect(overlayedState);
-                    } catch (ItemStateException e) {
-                        // TODO, handle property
-                        log.error(e.getMessage());
-                    }
+                switch (previousStatus) {
+                    case ItemState.STATUS_EXISTING_MODIFIED:
+                        // was modified and is now refreshed
+                        changeLog.modifiedStates.remove(state);
+                        break;
+                    case ItemState.STATUS_EXISTING_REMOVED:
+                        // was removed and is now refreshed
+                        changeLog.deletedStates.remove(state);
+                        break;
+                    case ItemState.STATUS_STALE_MODIFIED:
+                        // was modified and state and is now refreshed
+                        changeLog.modifiedStates.remove(state);
+                        break;
+                    case ItemState.STATUS_NEW:
+                        // was new and has been saved now
+                        changeLog.addedStates.remove(state);
+                        // state needs to be connected to the overlayed-state now
+                        try {
+                            ItemState overlayedState = parent.getItemState(state.getId());
+                            state.connect(overlayedState);
+                        } catch (ItemStateException e) {
+                            // TODO, handle property
+                            log.error(e.getMessage());
+                        }
+                        break;
                 }
                 break;
             case ItemState.STATUS_EXISTING_MODIFIED:
@@ -381,9 +335,5 @@
             default:
                 log.warn("ItemState has invalid status: " + state.getStatus());
         }
-    }
-
-    private TransientItemStateFactory getTransientFactory() {
-        return (TransientItemStateFactory) getItemStateFactory();
     }
 }