jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r202206 - in /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: HierarchyManagerImpl.java ZombieHierarchyManager.java
Date Tue, 28 Jun 2005 14:31:56 GMT
Author: stefan
Date: Tue Jun 28 07:31:55 2005
New Revision: 202206

URL: http://svn.apache.org/viewcvs?rev=202206&view=rev
Log:
fixed ZombieHierarchyManager: 
resolvePath(), getDepth() and getName() did not allow 
for removed/moved items

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java?rev=202206&r1=202205&r2=202206&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/HierarchyManagerImpl.java
Tue Jun 28 07:31:55 2005
@@ -112,6 +112,38 @@
     }
 
     /**
+     *
+     * @param state
+     * @return
+     */
+    protected String getParentUUID(ItemState state) {
+        return state.getParentUUID();
+    }
+
+    /**
+     *
+     * @param parent
+     * @return
+     */
+    protected NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent,
+                                                         String uuid) {
+        return parent.getChildNodeEntry(uuid);
+    }
+
+    /**
+     *
+     * @param parent
+     * @param name
+     * @param index
+     * @return
+     */
+    protected NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent,
+                                                         QName name,
+                                                         int index) {
+        return parent.getChildNodeEntry(name, index);
+    }
+
+    /**
      * Resolve a path into an item id. Recursively invoked method that may be
      * overridden by some subclass to either return cached responses or add
      * response to cache.
@@ -166,7 +198,7 @@
         if (parentState.hasChildNodeEntry(name, index)) {
             // child node
             NodeState.ChildNodeEntry nodeEntry =
-                    parentState.getChildNodeEntry(name, index);
+                    getChildNodeEntry(parentState, name, index);
             childId = new NodeId(nodeEntry.getUUID());
 
         } else if (parentState.hasPropertyName(name)) {
@@ -201,12 +233,20 @@
     protected void buildPath(Path.PathBuilder builder, ItemState state)
             throws ItemStateException, RepositoryException {
 
-        String parentUUID = state.getParentUUID();
-        if (parentUUID == null) {
+        // shortcut
+        if (state.getId().equals(rootNodeId)) {
             builder.addRoot();
             return;
         }
 
+        String parentUUID = getParentUUID(state);
+        if (parentUUID == null) {
+            String msg = "failed to build path of " + state.getId()
+                    + ": orphaned item";
+            log.debug(msg);
+            throw new ItemNotFoundException(msg);
+        }
+
         NodeState parent = (NodeState) getItemState(new NodeId(parentUUID));
         // recursively build path of parent
         buildPath(builder, parent);
@@ -214,7 +254,7 @@
         if (state.isNode()) {
             NodeState nodeState = (NodeState) state;
             String uuid = nodeState.getUUID();
-            NodeState.ChildNodeEntry entry = parent.getChildNodeEntry(uuid);
+            NodeState.ChildNodeEntry entry = getChildNodeEntry(parent, uuid);
             if (entry == null) {
                 String msg = "failed to build path of " + state.getId() + ": "
                         + parent.getUUID() + " has no child entry for "
@@ -301,7 +341,7 @@
             }
             try {
                 NodeState nodeState = (NodeState) getItemState(nodeId);
-                String parentUUID = nodeState.getParentUUID();
+                String parentUUID = getParentUUID(nodeState);
                 if (parentUUID == null) {
                     // this is the root or an orphaned node
                     // FIXME
@@ -315,7 +355,7 @@
             }
 
             NodeState.ChildNodeEntry entry =
-                    parentState.getChildNodeEntry(nodeId.getUUID());
+                    getChildNodeEntry(parentState, nodeId.getUUID());
             if (entry == null) {
                 String msg = "failed to resolve name of " + nodeId;
                 log.debug(msg);
@@ -335,7 +375,7 @@
             throws ItemNotFoundException, RepositoryException {
         try {
             ItemState state = getItemState(id);
-            String parentUUID = state.getParentUUID();
+            String parentUUID = getParentUUID(state);
             if (parentUUID != null) {
                 return getDepth(new NodeId(parentUUID)) + 1;
             }
@@ -358,7 +398,7 @@
             throws ItemNotFoundException, RepositoryException {
         try {
             ItemState state = getItemState(itemId);
-            String parentUUID = state.getParentUUID();
+            String parentUUID = getParentUUID(state);
             if (parentUUID != null) {
                 if (parentUUID.equals(nodeId.getUUID())) {
                     return true;

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java?rev=202206&r1=202205&r2=202206&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/ZombieHierarchyManager.java
Tue Jun 28 07:31:55 2005
@@ -21,18 +21,15 @@
 import org.apache.jackrabbit.core.state.ItemStateManager;
 import org.apache.jackrabbit.core.state.NoSuchItemStateException;
 import org.apache.jackrabbit.core.state.NodeState;
-import org.apache.jackrabbit.core.state.PropertyState;
 import org.apache.log4j.Logger;
 
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.RepositoryException;
 import java.util.Iterator;
 
 /**
  * <code>HierarchyManager</code> implementation that is also able to
  * build/resolve paths of those items that have been moved or removed
  * (i.e. moved to the attic).
- *
+ * <p/>
  * todo make use of path caching
  */
 public class ZombieHierarchyManager extends HierarchyManagerImpl {
@@ -42,17 +39,17 @@
     protected ItemStateManager attic;
 
     public ZombieHierarchyManager(String rootNodeUUID,
-                                 ItemStateManager provider,
-                                 ItemStateManager attic,
-                                 NamespaceResolver nsResolver) {
+                                  ItemStateManager provider,
+                                  ItemStateManager attic,
+                                  NamespaceResolver nsResolver) {
         super(rootNodeUUID, provider, nsResolver);
         this.attic = attic;
     }
 
     /**
      * {@inheritDoc}
-     *
-     * Checks attic first.
+     * <p/>
+     * Delivers state from attic if such exists, otherwise calls base class.
      */
     protected ItemState getItemState(ItemId id)
             throws NoSuchItemStateException, ItemStateException {
@@ -66,8 +63,9 @@
 
     /**
      * {@inheritDoc}
-     *
-     * Checks attic first.
+     * <p/>
+     * Returns <code>true</code>  if there's state on the attic for the
+     * requested item; otherwise delegates to base class.
      */
     protected boolean hasItemState(ItemId id) {
         // always check attic first
@@ -80,72 +78,59 @@
 
     /**
      * {@inheritDoc}
-     *
-     * Also allows for removed/renamed parent-child links.
+     * <p/>
+     * Also allows for removed items.
      */
-    protected void buildPath(Path.PathBuilder builder, ItemState state)
-            throws ItemStateException, RepositoryException {
-
-        // shortcut
-        if (state.getId().equals(rootNodeId)) {
-            builder.addRoot();
-            return;
-        }
-
-        String parentUUID;
+    protected String getParentUUID(ItemState state) {
         if (state.hasOverlayedState()) {
             // use 'old' parent in case item has been removed
-            parentUUID = state.getOverlayedState().getParentUUID();
-        } else {
-            parentUUID = state.getParentUUID();
-        }
-        if (parentUUID == null) {
-            String msg = "failed to build path of " + state.getId() + ": orphaned item";
-            log.debug(msg);
-            throw new ItemNotFoundException(msg);
+            return state.getOverlayedState().getParentUUID();
         }
+        // delegate to base class
+        return super.getParentUUID(state);
+    }
 
-        NodeState parent = (NodeState) getItemState(new NodeId(parentUUID));
-        // recursively build path of parent
-        buildPath(builder, parent);
-
-        if (state.isNode()) {
-            NodeState nodeState = (NodeState) state;
-            String uuid = nodeState.getUUID();
-            NodeState.ChildNodeEntry parentEntry = null;
-            // check removed child node entries first
-            Iterator iter = parent.getRemovedChildNodeEntries().iterator();
-            while (iter.hasNext()) {
-                NodeState.ChildNodeEntry entry =
-                        (NodeState.ChildNodeEntry) iter.next();
-                if (entry.getUUID().equals(uuid)) {
-                    parentEntry = entry;
-                    break;
-                }
-            }
-            if (parentEntry == null) {
-                // no removed child node entry found in parent,
-                // check current child node entries
-                parentEntry = parent.getChildNodeEntry(uuid);
-            }
-            if (parentEntry == null) {
-                String msg = "failed to build path of " + state.getId() + ": "
-                        + parent.getUUID() + " has no child entry for "
-                        + uuid;
-                log.debug(msg);
-                throw new ItemNotFoundException(msg);
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Also allows for removed/renamed child node entries.
+     */
+    protected NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent,
+                                                         QName name,
+                                                         int index) {
+        // check removed child node entries first
+        Iterator iter = parent.getRemovedChildNodeEntries().iterator();
+        while (iter.hasNext()) {
+            NodeState.ChildNodeEntry entry =
+                    (NodeState.ChildNodeEntry) iter.next();
+            if (entry.getName().equals(name)
+                    && entry.getIndex() == index) {
+                return entry;
             }
-            // add to path
-            if (parentEntry.getIndex() == 1) {
-                builder.addLast(parentEntry.getName());
-            } else {
-                builder.addLast(parentEntry.getName(), parentEntry.getIndex());
+        }
+        // no matching removed child node entry found in parent,
+        // delegate to base class
+        return super.getChildNodeEntry(parent, name, index);
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
+     * Also allows for removed child node entries.
+     */
+    protected NodeState.ChildNodeEntry getChildNodeEntry(NodeState parent,
+                                                         String uuid) {
+        // check removed child node entries first
+        Iterator iter = parent.getRemovedChildNodeEntries().iterator();
+        while (iter.hasNext()) {
+            NodeState.ChildNodeEntry entry =
+                    (NodeState.ChildNodeEntry) iter.next();
+            if (entry.getUUID().equals(uuid)) {
+                return entry;
             }
-        } else {
-            PropertyState propState = (PropertyState) state;
-            QName name = propState.getName();
-            // add to path
-            builder.addLast(name);
         }
+        // no matching removed child node entry found in parent,
+        // delegate to base class
+        return super.getChildNodeEntry(parent, uuid);
     }
 }



Mime
View raw message