jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r429652 [1/2] - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ lock/ operation/ query/ state/ util/ version/ xml/
Date Tue, 08 Aug 2006 13:39:27 GMT
Author: angela
Date: Tue Aug  8 06:39:25 2006
New Revision: 429652

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

- HierarchyManager: changes methods to take ItemState instead of ItemId
- HierarchyManager: remove log-utility methods (saveGetJCRPath)
- HierarchyManager: remove CachingHierachyManager. not used
- ItemManager: changes methods to take ItemState instead of ItemId
- ItemStateValidator: remove utility methods not related to validation
- new class LogUtil that provides static saveGetJCRPath methods previously
  present on HierarchyManager, ItemStateValidator
- NodeState: add method 'getPropertyEntries()'
- create interface ChildPropertyEntry
- let PropertyReference implement ChildPropertyEntry

TODO: query/NodeIteratorImpl needs to be fixed. 

Added:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildPropertyEntry.java   (with props)
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/LogUtil.java   (with props)
Removed:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/CachingHierarchyManager.java
Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ZombieHierarchyManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/DefaultLockManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractOperation.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Clone.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Copy.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Move.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.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/PropertyReference.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImporterImpl.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManager.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManager.java Tue Aug  8 06:39:25 2006
@@ -20,11 +20,11 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
 
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
-import javax.jcr.Item;
 
 /**
  * The <code>HierarchyManager</code> interface ...
@@ -32,58 +32,45 @@
 public interface HierarchyManager {
 
     /**
-     * Returns the id of the given <code>Item</code>.
-     *
-     * @param item
-     * @return
-     * @throws PathNotFoundException
-     * @throws RepositoryException
-     */
-    ItemId getItemId(Item item) throws PathNotFoundException, RepositoryException;
-
-    // DIFF JR: renamed from 'resolveQPath'
-    /**
-     * Resolves a path into an item id.
+     * Resolves a path into an item state.
      *
      * @param qPath
      * @return
      * @throws PathNotFoundException
      * @throws RepositoryException
      */
-    ItemId getItemId(Path qPath) throws PathNotFoundException, RepositoryException;
+    ItemState getItemState(Path qPath) throws PathNotFoundException, RepositoryException;
 
     /**
-     * Returns the path to the given item.
+     * Returns the path to the item represented by the given state object.
      *
-     * @param id
+     * @param itemState
      * @return
      * @throws ItemNotFoundException
      * @throws RepositoryException
      */
-    Path getQPath(ItemId id) throws ItemNotFoundException, RepositoryException;
+    Path getQPath(ItemState itemState) throws ItemNotFoundException, RepositoryException;
 
     /**
-     * Returns the name of the specified item.
+     * Returns the qualified name of the specified item state.
      *
-     * @param id id of item whose name should be returned
+     * @param itemState state of item whose name should be returned
      * @return
      * @throws ItemNotFoundException
      * @throws RepositoryException
      */
-    QName getQName(ItemId id) throws ItemNotFoundException, RepositoryException;
+    QName getQName(ItemState itemState) throws ItemNotFoundException, RepositoryException;
 
     /**
      * Returns the depth of the specified item which is equivalent to
      * <code>getQPath(id).getAncestorCount()</code>. The depth reflects the
      * absolute hierarchy level.
      *
-     * @param id item id
+     * @param itemState item state
      * @return the depth of the specified item
-     * @throws ItemNotFoundException if the specified <code>id</code> does not
-     *                               denote an existing item.
-     * @throws RepositoryException   if another error occurs
+     * @throws RepositoryException if another error occurs
      */
-    int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException;
+    int getDepth(ItemState itemState) throws ItemNotFoundException, RepositoryException;
 
     /**
      * Returns the depth of the specified descendant relative to the given
@@ -102,22 +89,4 @@
      */
     int getRelativeDepth(NodeId ancestorId, ItemId descendantId)
             throws ItemNotFoundException, RepositoryException;
-
-     /**
-     * Failsafe conversion of an <code>ItemId</code> to JCR path for use in
-     * error messages etc.
-     *
-     * @param itemId id to convert
-     * @return JCR path
-     */
-    String safeGetJCRPath(ItemId itemId);
-
-     /**
-     * Failsafe conversion of internal <code>Path</code> to JCR path for use in
-     * error messages etc.
-     *
-     * @param qPath path to convert
-     * @return JCR path
-     */
-    String safeGetJCRPath(Path qPath);
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java Tue Aug  8 06:39:25 2006
@@ -23,11 +23,11 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.jcr2spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.MalformedPathException;
@@ -38,7 +38,6 @@
 import javax.jcr.ItemNotFoundException;
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
-import javax.jcr.Item;
 
 /**
  * <code>HierarchyManagerImpl</code> ...
@@ -47,9 +46,7 @@
 
     private static Logger log = LoggerFactory.getLogger(HierarchyManagerImpl.class);
 
-    // DIFF JR: QName.ROOT replaces the EMPTY_NAME QName defined in JR....
-
-    // TODO: TO-BE-FIXED. With SPI_ItemId rootId must not be stored separately    
+    // TODO: TO-BE-FIXED. With SPI_ItemId rootId must not be stored separately
     protected final NodeId rootNodeId;
     protected final ItemStateManager itemStateManager;
     // used for outputting user-friendly paths and names
@@ -67,10 +64,6 @@
         return rootNodeId;
     }
 
-    public NamespaceResolver getNamespaceResolver() {
-        return nsResolver;
-    }
-
     //---------------------------------------------------------< overridables >
     /**
      * Return an item state, given its item id.
@@ -116,6 +109,15 @@
     }
 
     /**
+     *
+     * @param state
+     * @return
+     */
+    protected NodeState getParentState(ItemState state) {
+        return state.getParent();
+    }
+
+    /**
      * Returns the <code>ChildNodeEntry</code> of <code>parent</code> with the
      * specified <code>uuid</code> or <code>null</code> if there's no such entry.
      * <p/>
@@ -155,47 +157,21 @@
     }
 
     /**
-     * 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.
-     *
-     * @param path full path of item to resolve
-     * @param id   intermediate item id
-     * @param next next path element index to resolve
-     * @return the id of the item denoted by <code>path</code>
-     */
-    protected ItemId resolvePath(Path path, ItemId id, int next)
-            throws RepositoryException {
-
-        try {
-            return resolvePath(path, getItemState(id), next);
-        } catch (NoSuchItemStateException e) {
-            String msg = "failed to retrieve state of intermediary node";
-            log.debug(msg);
-            throw new RepositoryException(msg, e);
-        } catch (ItemStateException e) {
-            String msg = "failed to retrieve state of intermediary node";
-            log.debug(msg);
-            throw new RepositoryException(msg, e);
-        }
-    }
-
-    /**
-     * Resolve a path into an item id. Recursively invoked method that may be
+     * Resolve a path into an item state. Recursively invoked method that may be
      * overridden by some subclass to either return cached responses or add
      * response to cache.
      *
      * @param path  full path of item to resolve
      * @param state intermediate state
      * @param next  next path element index to resolve
-     * @return the id of the item denoted by <code>path</code>
+     * @return the state of the item denoted by <code>path</code>
      */
-    protected ItemId resolvePath(Path path, ItemState state, int next)
-            throws PathNotFoundException, ItemStateException {
+    protected ItemState resolvePath(Path path, ItemState state, int next)
+        throws PathNotFoundException, RepositoryException {
 
         Path.PathElement[] elements = path.getElements();
         if (elements.length == next) {
-            return state.getId();
+            return state;
         }
         Path.PathElement elem = elements[next];
 
@@ -203,27 +179,37 @@
         int index = elem.getNormalizedIndex();
 
         NodeState parentState = (NodeState) state;
-        ItemId childId;
+        ItemState childState;
 
         if (parentState.hasChildNodeEntry(name, index)) {
             // child node
             ChildNodeEntry nodeEntry = getChildNodeEntry(parentState, name, index);
-            childId = nodeEntry.getId();
+            try {
+                childState = nodeEntry.getNodeState();
+            } catch (ItemStateException e) {
+                // should never occur
+                throw new RepositoryException(e);
+            }
         } else if (parentState.hasPropertyName(name)) {
             // property
-            if (index > org.apache.jackrabbit.name.Path.INDEX_DEFAULT) {
+            if (index > Path.INDEX_DEFAULT) {
                 // properties can't have same name siblings
-                throw new PathNotFoundException(safeGetJCRPath(path));
+                throw new PathNotFoundException(LogUtil.safeGetJCRPath(path, nsResolver));
             } else if (next < elements.length - 1) {
                 // property is not the last element in the path
-                throw new PathNotFoundException(safeGetJCRPath(path));
+                throw new PathNotFoundException(LogUtil.safeGetJCRPath(path, nsResolver));
+            }
+            try {
+                childState = parentState.getPropertyState(name);
+            } catch (ItemStateException e) {
+                // should never occur
+                throw new RepositoryException(e);
             }
-            childId = parentState.getPropertyState(name).getId();
         } else {
             // no such item
-            throw new PathNotFoundException(safeGetJCRPath(path));
+            throw new PathNotFoundException(LogUtil.safeGetJCRPath(path, nsResolver));
         }
-        return resolvePath(path, getItemState(childId), next + 1);
+        return resolvePath(path, childState, next + 1);
     }
 
     /**
@@ -280,99 +266,68 @@
         }
     }
 
-    //-----------------------------------------------------< HierarchyManager >
+    //---------------------------------------------------< HierarchyManager >---
     /**
-     * {@inheritDoc}
+     * @see HierarchyManager#getItemState(Path)
      */
-    public ItemId getItemId(Item item) throws PathNotFoundException, RepositoryException {
-        if (item instanceof ItemImpl) {
-            return ((ItemImpl)item).getId();
-        } else {
-            try {
-                return getItemId(PathFormat.parse(item.getPath(), nsResolver));
-            } catch (MalformedPathException e) {
-                // should not occur.
-                throw new RepositoryException(e);
+    public ItemState getItemState(Path qPath) throws PathNotFoundException, RepositoryException {
+        try {
+            ItemState rootState = itemStateManager.getItemState(rootNodeId);
+            // shortcut
+            if (qPath.denotesRoot()) {
+                return rootState;
             }
-        }
-    }
 
-    /**
-     * {@inheritDoc}
-     */
-    public ItemId getItemId(Path qPath)
-            throws PathNotFoundException, RepositoryException {
-        // shortcut
-        if (qPath.denotesRoot()) {
-            return rootNodeId;
-        }
+            if (!qPath.isCanonical()) {
+                String msg = "path is not canonical";
+                log.debug(msg);
+                throw new RepositoryException(msg);
+            }
 
-        if (!qPath.isCanonical()) {
-            String msg = "path is not canonical";
-            log.debug(msg);
-            throw new RepositoryException(msg);
+            return resolvePath(qPath, rootState, 1);
+        } catch (ItemStateException e) {
+            // should never occur
+            throw new RepositoryException(e);
         }
-
-        return resolvePath(qPath, rootNodeId, 1);
     }
 
     /**
-     * {@inheritDoc}
+     * @see HierarchyManager#getQPath(ItemState)
      */
-    public Path getQPath(ItemId id)
-            throws ItemNotFoundException, RepositoryException {
-        // shortcut
-        if (id.equals(rootNodeId)) {
-            return Path.ROOT;
-        }
+    public Path getQPath(ItemState itemState) throws ItemNotFoundException, RepositoryException {
 
         Path.PathBuilder builder = new Path.PathBuilder();
-
         try {
-            buildPath(builder, getItemState(id));
+            buildPath(builder, itemState);
             return builder.getPath();
-        } catch (NoSuchItemStateException nsise) {
-            String msg = "failed to build path of " + id;
+        } catch (NoSuchItemStateException e) {
+            String msg = "failed to build path of " + itemState.getId();
             log.debug(msg);
-            throw new ItemNotFoundException(msg, nsise);
-        } catch (ItemStateException ise) {
-            String msg = "failed to build path of " + id;
+            throw new ItemNotFoundException(msg, e);
+        } catch (ItemStateException e) {
+            String msg = "failed to build path of " + itemState.getId();
             log.debug(msg);
-            throw new RepositoryException(msg, ise);
+            throw new RepositoryException(msg, e);
         } catch (MalformedPathException e) {
-            String msg = "failed to build path of " + id;
+            String msg = "failed to build path of " + itemState.getId();
             throw new RepositoryException(msg, e);
         }
     }
 
     /**
-     * {@inheritDoc}
+     * @see HierarchyManager#getQName(ItemState)
      */
-    public QName getQName(ItemId itemId)
+    public QName getQName(ItemState itemState)
             throws ItemNotFoundException, RepositoryException {
-        if (itemId.denotesNode()) {
-            NodeId nodeId = (NodeId) itemId;
-            NodeState parentState;
-            try {
-                NodeState nodeState = (NodeState) getItemState(nodeId);
-                NodeId parentId= getParentId(nodeState);
-                if (parentId == null) {
-                    // this is the root or an orphaned node
-                    return QName.ROOT;
-                }
-                parentState = (NodeState) getItemState(parentId);
-            } catch (NoSuchItemStateException nsis) {
-                String msg = "failed to resolve name of " + nodeId;
-                log.debug(msg);
-                throw new ItemNotFoundException(nodeId.toString());
-            } catch (ItemStateException ise) {
-                String msg = "failed to resolve name of " + nodeId;
-                log.debug(msg);
-                throw new RepositoryException(msg, ise);
+        if (itemState.isNode()) {
+            NodeState parentState = itemState.getParent();
+            if (parentState == null) {
+                // shortcut. the given state represents the root or an orphaned node
+                return QName.ROOT;
             }
 
-            ChildNodeEntry entry =
-                    getChildNodeEntry(parentState, nodeId);
+            NodeId nodeId = ((NodeState)itemState).getNodeId();
+            ChildNodeEntry entry = getChildNodeEntry(parentState, nodeId);
             if (entry == null) {
                 String msg = "failed to resolve name of " + nodeId;
                 log.debug(msg);
@@ -380,38 +335,22 @@
             }
             return entry.getName();
         } else {
-            return ((PropertyId) itemId).getQName();
+            return ((PropertyState)itemState).getQName();
         }
     }
 
     /**
-     * {@inheritDoc}
+     * @see HierarchyManager#getDepth(ItemState)
      */
-    public int getDepth(ItemId id)
-            throws ItemNotFoundException, RepositoryException {
-        int depth = org.apache.jackrabbit.name.Path.ROOT_DEPTH;
-        // shortcut
-        if (id.equals(rootNodeId)) {
-            return depth;
-        }
-        try {
-            ItemState state = getItemState(id);
-            NodeId parentId = getParentId(state);
-            while (parentId != null) {
-                depth++;
-                state = getItemState(parentId);
-                parentId = getParentId(state);
-            }
-            return depth;
-        } catch (NoSuchItemStateException nsise) {
-            String msg = "failed to determine depth of " + id;
-            log.debug(msg);
-            throw new ItemNotFoundException(msg, nsise);
-        } catch (ItemStateException ise) {
-            String msg = "failed to determine depth of " + id;
-            log.debug(msg);
-            throw new RepositoryException(msg, ise);
+    public int getDepth(ItemState itemState) throws ItemNotFoundException, RepositoryException {
+        int depth = Path.ROOT_DEPTH;
+        NodeState parentState = getParentState(itemState);
+        while (parentState != null) {
+            depth++;
+            itemState = parentState;
+            parentState = getParentState(itemState);
         }
+        return depth;
     }
 
     /**
@@ -446,31 +385,6 @@
                     + " relative to " + ancestorId;
             log.debug(msg);
             throw new RepositoryException(msg, ise);
-        }
-    }
-
-    /**
-     * @see HierarchyManager#safeGetJCRPath(ItemId)
-     */
-    public String safeGetJCRPath(ItemId itemId) {
-        try {
-            return safeGetJCRPath(getQPath(itemId));
-        } catch (RepositoryException e) {
-            log.error("failed to convert " + itemId + " to JCR path.");
-            return itemId.toString();
-        }
-    }
-
-    /**
-     * @see HierarchyManager#safeGetJCRPath(Path)
-     */
-    public String safeGetJCRPath(Path qPath) {
-        try {
-            return PathFormat.format(qPath, nsResolver);
-        } catch (NoPrefixDeclaredException npde) {
-            log.error("failed to convert " + qPath + " to JCR path.");
-            // return string representation of internal path as a fallback
-            return qPath.toString();
         }
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemImpl.java Tue Aug  8 06:39:25 2006
@@ -27,6 +27,7 @@
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.jcr2spi.operation.Remove;
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
+import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
@@ -162,7 +163,7 @@
             // shortcut
             return Path.ROOT_DEPTH;
         }
-        return session.getHierarchyManager().getDepth(state.getParent().getId());
+        return session.getHierarchyManager().getDepth(state);
     }
 
     /**
@@ -602,7 +603,7 @@
      * @return the primary path to this <code>Item</code>
      */
     Path getQPath() throws RepositoryException {
-        return session.getHierarchyManager().getQPath(id);
+        return session.getHierarchyManager().getQPath(state);
     }
 
     /**
@@ -631,6 +632,6 @@
      * @return JCR path
      */
     String safeGetJCRPath() {
-        return session.getHierarchyManager().safeGetJCRPath(getId());
+        return LogUtil.safeGetJCRPath(getItemState(), session.getNamespaceResolver(), session.getHierarchyManager());
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManager.java Tue Aug  8 06:39:25 2006
@@ -18,7 +18,8 @@
 
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
+import org.apache.jackrabbit.jcr2spi.state.NodeState;
 
 import javax.jcr.PathNotFoundException;
 import javax.jcr.AccessDeniedException;
@@ -50,10 +51,11 @@
     /**
      * Checks if the item with the given id exists.
      *
-     * @param id id of the item to be checked
+     * @param itemState state of the item to be checked
      * @return true if the specified item exists
      */
-    public boolean itemExists(ItemId id);
+    public boolean itemExists(ItemState itemState);
+
 
     /**
      * @param path
@@ -63,57 +65,60 @@
      * @throws javax.jcr.RepositoryException
      */
     public ItemImpl getItem(Path path)
-            throws PathNotFoundException, AccessDeniedException, RepositoryException;
+        throws PathNotFoundException, AccessDeniedException, RepositoryException;
 
     /**
-     * @param id
+     *
+     * @param itemState
      * @return
-     * @throws javax.jcr.RepositoryException
+     * @throws ItemNotFoundException
+     * @throws AccessDeniedException
+     * @throws RepositoryException
      */
-    public ItemImpl getItem(ItemId id)
-            throws ItemNotFoundException, AccessDeniedException, RepositoryException;
+    public ItemImpl getItem(ItemState itemState)
+        throws ItemNotFoundException, AccessDeniedException, RepositoryException;
 
     /**
      *
-     * @param parentId
+     * @param parentState
      * @return
      * @throws ItemNotFoundException
      * @throws AccessDeniedException
      * @throws RepositoryException
      */
-    public boolean hasChildNodes(NodeId parentId) throws ItemNotFoundException,
-        AccessDeniedException, RepositoryException;
+    public boolean hasChildNodes(NodeState parentState)
+        throws ItemNotFoundException, AccessDeniedException, RepositoryException;
 
     /**
      *
-     * @param parentId
+     * @param parentState
      * @return
      * @throws ItemNotFoundException
      * @throws AccessDeniedException
      * @throws RepositoryException
      */
-    public NodeIterator getChildNodes(NodeId parentId)
-            throws ItemNotFoundException, AccessDeniedException, RepositoryException;
+    public NodeIterator getChildNodes(NodeState parentState)
+        throws ItemNotFoundException, AccessDeniedException, RepositoryException;
 
     /**
      *
-     * @param parentId
+     * @param parentState
      * @return
      * @throws ItemNotFoundException
      * @throws AccessDeniedException
      * @throws RepositoryException
      */
-    public boolean hasChildProperties(NodeId parentId)
+    public boolean hasChildProperties(NodeState parentState)
             throws ItemNotFoundException, AccessDeniedException, RepositoryException;
 
     /**
      *
-     * @param parentId
+     * @param parentState
      * @return
      * @throws ItemNotFoundException
      * @throws AccessDeniedException
      * @throws RepositoryException
      */
-    public PropertyIterator getChildProperties(NodeId parentId)
+    public PropertyIterator getChildProperties(NodeState parentState)
             throws ItemNotFoundException, AccessDeniedException, RepositoryException;
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ItemManagerImpl.java Tue Aug  8 06:39:25 2006
@@ -17,13 +17,12 @@
 package org.apache.jackrabbit.jcr2spi;
 
 import org.apache.jackrabbit.jcr2spi.state.ItemState;
-import org.apache.jackrabbit.jcr2spi.state.ItemStateException;
-import org.apache.jackrabbit.jcr2spi.state.ItemStateManager;
-import org.apache.jackrabbit.jcr2spi.state.NoSuchItemStateException;
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.jcr2spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.jcr2spi.state.ChildPropertyEntry;
 import org.apache.jackrabbit.jcr2spi.util.Dumpable;
+import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.jcr2spi.version.VersionHistoryImpl;
 import org.apache.jackrabbit.jcr2spi.version.VersionImpl;
 import org.apache.jackrabbit.name.QName;
@@ -43,7 +42,6 @@
 import javax.jcr.nodetype.NodeDefinition;
 import javax.jcr.nodetype.PropertyDefinition;
 import java.io.PrintStream;
-import java.util.ArrayList;
 import java.util.Iterator;
 
 /**
@@ -75,7 +73,7 @@
 
     private final SessionImpl session;
 
-    private final ItemStateManager itemStateMgr;
+    //private final ItemStateManager itemStateMgr;
     private final HierarchyManager hierMgr;
 
     /**
@@ -87,185 +85,16 @@
     /**
      * Creates a new per-session instance <code>ItemManagerImpl</code> instance.
      *
-     * @param itemStateMgr the item state itemStateManager associated with
-     * the new instance
+     * @param hierMgr HierarchyManager associated with the new instance
      * @param session the session associated with the new instance
      */
-    ItemManagerImpl(ItemStateManager itemStateMgr, HierarchyManager hierMgr,
-                    SessionImpl session) {
-        this.itemStateMgr = itemStateMgr;
+    ItemManagerImpl(HierarchyManager hierMgr, SessionImpl session) {
         this.hierMgr = hierMgr;
         this.session = session;
         // setup item cache with weak references to items
         itemCache = new DefaultIdKeyMap(); // TODO, JR: new ReferenceMap(ReferenceMap.HARD, ReferenceMap.WEAK);
     }
 
-    private NodeDefinition getDefinition(NodeState state)
-            throws RepositoryException {
-        NodeState parentState = state.getParent();
-        NodeDefinition def = session.getItemDefinitionManager().getNodeDefinition(state, parentState);
-        return def;
-    }
-
-    private PropertyDefinition getDefinition(PropertyState state)
-        throws RepositoryException {
-        // fallback: try finding applicable definition
-        NodeState parentState = state.getParent();
-        PropertyDefinition def = session.getItemDefinitionManager().getPropertyDefinition(state, parentState);
-        return def;
-    }
-
-    /**
-     * Retrieves state of item with given <code>id</code>. If the specified item
-     * doesn't exist an <code>ItemNotFoundException</code> will be thrown.
-     * If the item exists but the current session is not granted read access an
-     * <code>AccessDeniedException</code> will be thrown.
-     *
-     * @param id id of item to be retrieved
-     * @return state state of said item
-     * @throws ItemNotFoundException if no item with given <code>id</code> exists
-     * @throws AccessDeniedException if the current session is not allowed to
-     *                               read the said item
-     * @throws RepositoryException   if another error occurs
-     */
-    private ItemState getItemState(ItemId id)
-            throws ItemNotFoundException, AccessDeniedException,
-            RepositoryException {
-        // check privileges
-        if (!session.getAccessManager().canRead(id)) {
-            // clear cache
-            ItemImpl item = retrieveItem(id);
-            if (item != null) {
-                evictItem(id);
-            }
-            throw new AccessDeniedException("cannot read item " + id);
-        }
-
-        try {
-            return itemStateMgr.getItemState(id);
-        } catch (NoSuchItemStateException nsise) {
-            String msg = "no such item: " + id;
-            log.debug(msg);
-            throw new ItemNotFoundException(msg);
-        } catch (ItemStateException ise) {
-            String msg = "failed to retrieve item state of " + id;
-            log.error(msg);
-            throw new RepositoryException(msg, ise);
-        }
-    }
-
-    //-------------------------------------------------< item factory methods >
-    private ItemImpl createItemInstance(ItemId id)
-            throws ItemNotFoundException, RepositoryException {
-        // create instance of item using its state object
-        ItemImpl item;
-        ItemState state;
-        try {
-            state = itemStateMgr.getItemState(id);
-        } catch (NoSuchItemStateException nsise) {
-            throw new ItemNotFoundException(id.toString());
-        } catch (ItemStateException ise) {
-            String msg = "failed to retrieve item state of item " + id;
-            log.error(msg, ise);
-            throw new RepositoryException(msg, ise);
-        }
-
-        if (state.isNode()) {
-            item = createNodeInstance((NodeState) state);
-        } else {
-            item = createPropertyInstance((PropertyState) state);
-        }
-        return item;
-    }
-
-    private NodeImpl createNodeInstance(NodeState state, NodeDefinition def)
-            throws RepositoryException {
-        // DIFF JR: no need to build NodeId from state
-        // we want to be informed on life cycle changes of the new node object
-        // in order to maintain item cache consistency
-        ItemLifeCycleListener[] listeners = new ItemLifeCycleListener[]{this};
-
-        // check special nodes
-        if (state.getNodeTypeName().equals(QName.NT_VERSION)) {
-            // version
-            return new VersionImpl(this, session, state, def, listeners);
-        } else if (state.getNodeTypeName().equals(QName.NT_VERSIONHISTORY)) {
-            // version-history
-            return new VersionHistoryImpl(this, session, state, def, listeners);
-        } else {
-            // create common node object
-            return new NodeImpl(this, session, state, def, listeners);
-        }
-
-    }
-
-    private NodeImpl createNodeInstance(NodeState state) throws RepositoryException {
-        // 1. get definition of the specified node
-        NodeDefinition def = getDefinition(state);
-        // 2. create instance
-        return createNodeInstance(state, def);
-    }
-
-    private PropertyImpl createPropertyInstance(PropertyState state,
-                                                PropertyDefinition def) {
-        // we want to be informed on life cycle changes of the new property object
-        // in order to maintain item cache consistency
-        ItemLifeCycleListener[] listeners = new ItemLifeCycleListener[]{this};
-        // create property object
-        PropertyImpl prop = new PropertyImpl(this, session, state, def, listeners);
-        return prop;
-    }
-
-    private PropertyImpl createPropertyInstance(PropertyState state)
-            throws RepositoryException {
-        // 1. get definition for the specified property
-        PropertyDefinition def = getDefinition(state);
-        // 2. create instance
-        return createPropertyInstance(state, def);
-    }
-
-    //---------------------------------------------------< item cache methods >
-
-    /**
-     * Returns an item reference from the cache.
-     *
-     * @param id id of the item that should be retrieved.
-     * @return the item reference stored in the corresponding cache entry
-     *         or <code>null</code> if there's no corresponding cache entry.
-     */
-    private ItemImpl retrieveItem(ItemId id) {
-        return (ItemImpl) itemCache.get(id);
-    }
-
-    /**
-     * Puts the reference of an item in the cache with
-     * the item's path as the key.
-     *
-     * @param item the item to cache
-     */
-    private void cacheItem(ItemImpl item) {
-        ItemId id = item.getId();
-        if (itemCache.containsKey(id)) {
-            log.warn("overwriting cached item " + id);
-        }
-        if (log.isDebugEnabled()) {
-            log.debug("caching item " + id);
-        }
-        itemCache.put(id, item);
-    }
-
-    /**
-     * Removes a cache entry for a specific item.
-     *
-     * @param id id of the item to remove from the cache
-     */
-    private void evictItem(ItemId id) {
-        if (log.isDebugEnabled()) {
-            log.debug("removing item " + id + " from cache");
-        }
-        itemCache.remove(id);
-    }
-
     //--------------------------------------------------------< ItemManager >---
     /**
      * @inheritDoc
@@ -281,22 +110,10 @@
         try {
             // check sanity of session
             session.checkIsAlive();
+            // permissions are checked upon itemExists(ItemState)
 
-            ItemId id = hierMgr.getItemId(path);
-
-            // check if state exists for the given item
-            if (!itemStateMgr.hasItemState(id)) {
-                return false;
-            }
-
-            // check privileges
-            if (!session.getAccessManager().canRead(id)) {
-                // clear cache
-                evictItem(id);
-                // item exists but the session has not been granted read access
-                return false;
-            }
-            return true;
+            ItemState itemState = hierMgr.getItemState(path);
+            return itemExists(itemState);
         } catch (PathNotFoundException pnfe) {
             return false;
         } catch (ItemNotFoundException infe) {
@@ -309,23 +126,15 @@
     /**
      * @inheritDoc
      */
-    public boolean itemExists(ItemId id) {
+    public boolean itemExists(ItemState itemState) {
         try {
             // check sanity of session
             session.checkIsAlive();
-
-            // check if state exists for the given item
-            if (!itemStateMgr.hasItemState(id)) {
-                return false;
-            }
-
             // check privileges
-            if (!session.getAccessManager().canRead(id)) {
-                // clear cache
-                evictItem(id);
-                // item exists but the session has not been granted read access
-                return false;
-            }
+            checkAccess(itemState, true);
+
+            // always return true if access rights are granted, existence
+            // of the state has been asserted before
             return true;
         } catch (ItemNotFoundException infe) {
             return false;
@@ -339,32 +148,31 @@
      */
     public synchronized ItemImpl getItem(Path path)
             throws PathNotFoundException, AccessDeniedException, RepositoryException {
-        ItemId id = hierMgr.getItemId(path);
+        ItemState itemState = hierMgr.getItemState(path);
         try {
-            return getItem(id);
+            return getItem(itemState);
         } catch (ItemNotFoundException infe) {
-            throw new PathNotFoundException(hierMgr.safeGetJCRPath(path));
+            throw new PathNotFoundException(LogUtil.safeGetJCRPath(path, session.getNamespaceResolver()));
         }
     }
 
     /**
      * @inheritDoc
      */
-    public synchronized ItemImpl getItem(ItemId id)
-            throws ItemNotFoundException, AccessDeniedException, RepositoryException {
-        // check sanity of session
-        session.checkIsAlive();
-
-        // check cache
+    public ItemImpl getItem(ItemState itemState) throws ItemNotFoundException, AccessDeniedException, RepositoryException {
+        ItemId id = itemState.getId();
+        // first try to access item from cache
         ItemImpl item = retrieveItem(id);
+        // not yet in cache, need to create instance
         if (item == null) {
-            // not yet in cache, need to create instance:
             // check privileges
-            if (!session.getAccessManager().canRead(id)) {
-                throw new AccessDeniedException("cannot read item " + id);
-            }
+            checkAccess(itemState, false);
             // create instance of item
-            item = createItemInstance(id);
+            if (itemState.isNode()) {
+                item = createNodeInstance((NodeState) itemState);
+            } else {
+                item = createPropertyInstance((PropertyState) itemState);
+            }
         }
         return item;
     }
@@ -372,20 +180,13 @@
     /**
      * @inheritDoc
      */
-    public synchronized boolean hasChildNodes(NodeId parentId)
+    public synchronized boolean hasChildNodes(NodeState parentState)
             throws ItemNotFoundException, AccessDeniedException, RepositoryException {
         // check sanity of session
         session.checkIsAlive();
+        checkAccess(parentState, true);
 
-        ItemState state = getItemState(parentId);
-        if (!state.isNode()) {
-            String msg = "can't list child nodes of property " + parentId;
-            log.debug(msg);
-            throw new RepositoryException(msg);
-        }
-        NodeState nodeState = (NodeState) state;
-        Iterator iter = nodeState.getChildNodeEntries().iterator();
-
+        Iterator iter = parentState.getChildNodeEntries().iterator();
         while (iter.hasNext()) {
             ChildNodeEntry entry = (ChildNodeEntry) iter.next();
             NodeId id = entry.getId();
@@ -400,20 +201,16 @@
     /**
      * @inheritDoc
      */
-    public synchronized NodeIterator getChildNodes(NodeId parentId)
+    public synchronized NodeIterator getChildNodes(NodeState parentState)
             throws ItemNotFoundException, AccessDeniedException, RepositoryException {
         // check sanity of session
         session.checkIsAlive();
+        checkAccess(parentState, true);
 
-        ItemState state = getItemState(parentId);
-        if (!state.isNode()) {
-            String msg = "can't list child nodes of property " + parentId;
-            log.debug(msg);
-            throw new RepositoryException(msg);
-        }
-        NodeState nodeState = (NodeState) state;
+        /*
+        // REMOVED. left check for access to Iterator (getSize() returns -1)
         ArrayList childIds = new ArrayList();
-        Iterator iter = nodeState.getChildNodeEntries().iterator();
+        Iterator iter = parentState.getChildNodeEntries().iterator();
 
         while (iter.hasNext()) {
             ChildNodeEntry entry = (ChildNodeEntry) iter.next();
@@ -423,38 +220,26 @@
                 childIds.add(id);
             }
         }
-
-        return new LazyItemIterator(this, childIds);
+        */
+        return new LazyItemIterator(this, parentState.getChildNodeEntries());
     }
 
     /**
      * @inheritDoc
      */
-    public synchronized boolean hasChildProperties(NodeId parentId)
+    public synchronized boolean hasChildProperties(NodeState parentState)
             throws ItemNotFoundException, AccessDeniedException, RepositoryException {
         // check sanity of session
         session.checkIsAlive();
+        checkAccess(parentState, true);
 
-        ItemState state = getItemState(parentId);
-        if (!state.isNode()) {
-            String msg = "can't list child properties of property " + parentId;
-            log.debug(msg);
-            throw new RepositoryException(msg);
-        }
-        NodeState nodeState = (NodeState) state;
-        Iterator iter = nodeState.getPropertyNames().iterator();
-
+        Iterator iter = parentState.getPropertyEntries().iterator();
         while (iter.hasNext()) {
-            QName propName = (QName) iter.next();
-            try {
-                PropertyId id = nodeState.getPropertyState(propName).getPropertyId();
-                // check read access
-                if (session.getAccessManager().canRead(id)) {
-                    return true;
-                }
-            } catch (ItemStateException e) {
-                // should not occur.
-                throw new RepositoryException(e);
+            ChildPropertyEntry entry = (ChildPropertyEntry) iter.next();
+            PropertyId id = entry.getId();
+            // check read access
+            if (session.getAccessManager().canRead(id)) {
+                return true;
             }
         }
 
@@ -464,25 +249,21 @@
     /**
      * @inheritDoc
      */
-    public synchronized PropertyIterator getChildProperties(NodeId parentId)
+    public synchronized PropertyIterator getChildProperties(NodeState parentState)
             throws ItemNotFoundException, AccessDeniedException, RepositoryException {
         // check sanity of session
         session.checkIsAlive();
+        checkAccess(parentState, true);
 
-        ItemState state = getItemState(parentId);
-        if (!state.isNode()) {
-            String msg = "can't list child properties of property " + parentId;
-            log.debug(msg);
-            throw new RepositoryException(msg);
-        }
-        NodeState nodeState = (NodeState) state;
+        /*
+        // REMOVED. left check for access to Iterator (getSize() returns -1)
         ArrayList childIds = new ArrayList();
-        Iterator iter = nodeState.getPropertyNames().iterator();
+        Iterator iter = parentState.getPropertyNames().iterator();
 
         while (iter.hasNext()) {
             QName propName = (QName) iter.next();
             try {
-                PropertyId id = nodeState.getPropertyState(propName).getPropertyId();
+                PropertyId id = parentState.getPropertyState(propName).getPropertyId();
                 // check read access
                 if (session.getAccessManager().canRead(id)) {
                     childIds.add(id);
@@ -492,11 +273,11 @@
                 throw new RepositoryException(e);
             }
         }
-
-        return new LazyItemIterator(this, childIds);
+        */
+        return new LazyItemIterator(this, parentState.getPropertyEntries());
     }
 
-    //------------------------------------------------< ItemLifeCycleListener >
+    //----------------------------------------------< ItemLifeCycleListener >---
     /**
      * {@inheritDoc}
      */
@@ -532,7 +313,7 @@
         evictItem(id);
     }
 
-    //-------------------------------------------------------------< Dumpable >
+    //-----------------------------------------------------------< Dumpable >---
     /**
      * {@inheritDoc}
      */
@@ -555,7 +336,113 @@
             } else {
                 ps.print("          ");
             }
-            ps.println(id + "\t" + hierMgr.safeGetJCRPath(id) + " (" + item + ")");
+            ps.println(id + "\t" + LogUtil.safeGetJCRPath(item.getItemState(), session.getNamespaceResolver(), hierMgr) + " (" + item + ")");
+        }
+    }
+
+    //----------------------------------------------------< private methods >---
+    private void checkAccess(ItemState state, boolean removeFromCache) throws RepositoryException {
+        // check privileges
+        ItemId id = state.getId();
+        if (!session.getAccessManager().canRead(id)) {
+            if (removeFromCache) {
+                // clear cache
+                ItemImpl item = retrieveItem(id);
+                if (item != null) {
+                    evictItem(id);
+                }
+            }
+            throw new AccessDeniedException("cannot read item " + id);
+        }
+    }
+
+    private NodeImpl createNodeInstance(NodeState state, NodeDefinition def)
+            throws RepositoryException {
+        // we want to be informed on life cycle changes of the new node object
+        // in order to maintain item cache consistency
+        ItemLifeCycleListener[] listeners = new ItemLifeCycleListener[]{this};
+
+        // check special nodes
+        if (state.getNodeTypeName().equals(QName.NT_VERSION)) {
+            // version
+            return new VersionImpl(this, session, state, def, listeners);
+        } else if (state.getNodeTypeName().equals(QName.NT_VERSIONHISTORY)) {
+            // version-history
+            return new VersionHistoryImpl(this, session, state, def, listeners);
+        } else {
+            // create common node object
+            return new NodeImpl(this, session, state, def, listeners);
+        }
+
+    }
+
+    private NodeImpl createNodeInstance(NodeState state) throws RepositoryException {
+        // 1. get definition of the specified node
+        NodeState parentState = state.getParent();
+        NodeDefinition def = session.getItemDefinitionManager().getNodeDefinition(state, parentState);
+        // 2. create instance
+        return createNodeInstance(state, def);
+    }
+
+    private PropertyImpl createPropertyInstance(PropertyState state,
+                                                PropertyDefinition def) {
+        // we want to be informed on life cycle changes of the new property object
+        // in order to maintain item cache consistency
+        ItemLifeCycleListener[] listeners = new ItemLifeCycleListener[]{this};
+        // create property object
+        PropertyImpl prop = new PropertyImpl(this, session, state, def, listeners);
+        return prop;
+    }
+
+    private PropertyImpl createPropertyInstance(PropertyState state)
+            throws RepositoryException {
+        // 1. get definition for the specified property
+        NodeState parentState = state.getParent();
+        PropertyDefinition def = session.getItemDefinitionManager().getPropertyDefinition(state, parentState);
+
+        // 2. create instance
+        return createPropertyInstance(state, def);
+    }
+
+    //---------------------------------------------------< item cache methods >
+
+    /**
+     * Returns an item reference from the cache.
+     *
+     * @param id id of the item that should be retrieved.
+     * @return the item reference stored in the corresponding cache entry
+     *         or <code>null</code> if there's no corresponding cache entry.
+     */
+    private ItemImpl retrieveItem(ItemId id) {
+        return (ItemImpl) itemCache.get(id);
+    }
+
+    /**
+     * Puts the reference of an item in the cache with
+     * the item's path as the key.
+     *
+     * @param item the item to cache
+     */
+    private void cacheItem(ItemImpl item) {
+        ItemId id = item.getId();
+        if (itemCache.containsKey(id)) {
+            log.warn("overwriting cached item " + id);
         }
+        if (log.isDebugEnabled()) {
+            log.debug("caching item " + id);
+        }
+        itemCache.put(id, item);
+    }
+
+    /**
+     * Removes a cache entry for a specific item.
+     *
+     * @param id id of the item to remove from the cache
+     */
+    private void evictItem(ItemId id) {
+        if (log.isDebugEnabled()) {
+            log.debug("removing item " + id + " from cache");
+        }
+        itemCache.remove(id);
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/LazyItemIterator.java Tue Aug  8 06:39:25 2006
@@ -16,7 +16,7 @@
  */
 package org.apache.jackrabbit.jcr2spi;
 
-import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -42,22 +42,20 @@
  * for some reason (e.g. because of insufficient access rights or because they
  * have been removed since the iterator has been retrieved) are silently
  * skipped. As a result the size of the iterator as reported by
- * {@link #getSize()} might appear to be shrinking while iterating over the
- * items.
- * todo should getSize() better always return -1?
- *
- * @see #getSize()
+ * {@link #getSize()} always returns -1.
  */
 public class LazyItemIterator implements NodeIterator, PropertyIterator, VersionIterator {
 
     /** Logger instance for this class */
     private static Logger log = LoggerFactory.getLogger(LazyItemIterator.class);
 
+    private static final long UNDEFINED_SIZE = -1;
+
     /** the item manager that is used to lazily fetch the items */
     private final ItemManager itemMgr;
 
-    /** the list of item ids */
-    private final List idList;
+    /** the list of item states */
+    private final List stateList;
 
     /** the position of the next item */
     private int pos;
@@ -69,11 +67,11 @@
      * Creates a new <code>LazyItemIterator</code> instance.
      *
      * @param itemMgr item manager
-     * @param ids Collection of item id's
+     * @param stateList Collection of item states
      */
-    public LazyItemIterator(ItemManager itemMgr, Collection ids) {
+    public LazyItemIterator(ItemManager itemMgr, Collection stateList) {
         this.itemMgr = itemMgr;
-        this.idList = new ArrayList(ids);
+        this.stateList = new ArrayList(stateList);
         // prefetch first item
         pos = 0;
         prefetchNext();
@@ -88,19 +86,19 @@
     private void prefetchNext() {
         // reset
         next = null;
-        while (next == null && pos < idList.size()) {
-            ItemId id = (ItemId) idList.get(pos);
+        while (next == null && pos < stateList.size()) {
+            ItemState state = (ItemState) stateList.get(pos);
             try {
-                next = itemMgr.getItem(id);
+                next = itemMgr.getItem(state);
             } catch (ItemNotFoundException e) {
-                log.debug("ignoring nonexistent item " + id);
+                log.debug("ignoring nonexistent item " + state);
                 // remove invalid id
-                idList.remove(pos);
+                stateList.remove(pos);
                 // try next
             } catch (RepositoryException e) {
-                log.error("failed to fetch item " + id + ", skipping...", e);
+                log.error("failed to fetch item " + state + ", skipping...", e);
                 // remove invalid id
-                idList.remove(pos);
+                stateList.remove(pos);
                 // try next
             }
         }
@@ -141,15 +139,12 @@
     /**
      * {@inheritDoc}
      * <p/>
-     * Note that the size of the iterator as reported by {@link #getSize()}
-     * might appear to be shrinking while iterating because items that for
-     * some reason cannot be retrieved through this iterator are silently
-     * skipped, thus reducing the size of this iterator.
-     *
-     * todo better to always return -1?
+     * Always returns -1
      */
     public long getSize() {
-        return idList.size();
+        // DIFF JR always return -1, since original list may contains items that
+        // are not accessible due to access constraints
+        return UNDEFINED_SIZE;
     }
 
     /**
@@ -171,21 +166,21 @@
         // skip the first (skipNum - 1) items without actually retrieving them
         while (--skipNum > 0) {
             pos++;
-            if (pos >= idList.size()) {
+            if (pos >= stateList.size()) {
                 // skipped past last item
                 throw new NoSuchElementException();
             }
-            ItemId id = (ItemId) idList.get(pos);
+            ItemState state = (ItemState) stateList.get(pos);
             // eliminate invalid items from this iterator
-            while (!itemMgr.itemExists(id)) {
-                log.debug("ignoring nonexistent item " + id);
+            while (!itemMgr.itemExists(state)) {
+                log.debug("ignoring nonexistent item " + state);
                 // remove invalid id
-                idList.remove(pos);
-                if (pos >= idList.size()) {
+                stateList.remove(pos);
+                if (pos >= stateList.size()) {
                     // skipped past last item
                     throw new NoSuchElementException();
                 }
-                id = (ItemId) idList.get(pos);
+                state = (ItemState) stateList.get(pos);
                 // try next
                 continue;
             }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/NodeImpl.java Tue Aug  8 06:39:25 2006
@@ -37,6 +37,7 @@
 import org.apache.jackrabbit.jcr2spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.jcr2spi.state.NoSuchItemStateException;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
@@ -48,11 +49,11 @@
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
 import org.apache.jackrabbit.jcr2spi.operation.Update;
 import org.apache.jackrabbit.jcr2spi.lock.LockManager;
+import org.apache.jackrabbit.jcr2spi.version.VersionImpl;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.PropertyId;
-import org.apache.jackrabbit.spi.ItemId;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -151,7 +152,7 @@
             throw new ItemNotFoundException(msg);
         }
 
-        return (Node) itemMgr.getItem(parentState.getNodeId());
+        return (Node) itemMgr.getItem(parentState);
     }
 
     /**
@@ -419,11 +420,11 @@
      */
     public Node getNode(String relPath) throws PathNotFoundException, RepositoryException {
         checkStatus();
-        NodeId id = resolveRelativeNodePath(relPath);
-        if (id == null) {
+        NodeState state = resolveRelativeNodePath(relPath);
+        if (state == null) {
             throw new PathNotFoundException(relPath);
         }
-        return (Node) itemMgr.getItem(id);
+        return (Node) itemMgr.getItem(state);
     }
 
     /**
@@ -439,7 +440,7 @@
          * recursion!
          */
         try {
-            return itemMgr.getChildNodes(getNodeId());
+            return itemMgr.getChildNodes(getNodeState());
         } catch (ItemNotFoundException infe) {
             String msg = "failed to list the child nodes of " + safeGetJCRPath();
             log.debug(msg);
@@ -467,11 +468,11 @@
      */
     public Property getProperty(String relPath) throws PathNotFoundException, RepositoryException {
         checkStatus();
-        PropertyId id = resolveRelativePropertyPath(relPath);
-        if (id == null) {
+        PropertyState state = resolveRelativePropertyPath(relPath);
+        if (state == null) {
             throw new PathNotFoundException(relPath);
         }
-        return (Property) itemMgr.getItem(id);
+        return (Property) itemMgr.getItem(state);
     }
 
     /**
@@ -480,7 +481,7 @@
     public PropertyIterator getProperties() throws RepositoryException {
         checkStatus();
         try {
-            return itemMgr.getChildProperties(getNodeId());
+            return itemMgr.getChildProperties(getNodeState());
         } catch (ItemNotFoundException infe) {
             String msg = "Failed to list the child properties of " + getPath();
             log.debug(msg);
@@ -574,8 +575,8 @@
      */
     public boolean hasNode(String relPath) throws RepositoryException {
         checkStatus();
-        NodeId id = resolveRelativeNodePath(relPath);
-        return (id != null) ? itemMgr.itemExists(id) : false;
+        NodeState childState = resolveRelativeNodePath(relPath);
+        return (childState != null) ? itemMgr.itemExists(childState) : false;
     }
 
     /**
@@ -583,8 +584,8 @@
      */
     public boolean hasProperty(String relPath) throws RepositoryException {
         checkStatus();
-        PropertyId pId = resolveRelativePropertyPath(relPath);
-        return (pId != null) ? itemMgr.itemExists(pId) : false;
+        PropertyState childState = resolveRelativePropertyPath(relPath);
+        return (childState != null) ? itemMgr.itemExists(childState) : false;
     }
 
     /**
@@ -603,7 +604,7 @@
      */
     public boolean hasNodes() throws RepositoryException {
         checkStatus();
-        return itemMgr.hasChildNodes(getNodeId());
+        return itemMgr.hasChildNodes(getNodeState());
     }
 
     /**
@@ -611,7 +612,7 @@
      */
     public boolean hasProperties() throws RepositoryException {
         checkStatus();
-        return itemMgr.hasChildProperties(getNodeId());
+        return itemMgr.hasChildProperties(getNodeState());
     }
 
     /**
@@ -825,9 +826,8 @@
             throw new VersionException(msg);
         }
 
-        ItemId versionId = session.getHierarchyManager().getItemId(version);
-        if (versionId.denotesNode()) {
-            session.getVersionManager().resolveMergeConflict(getNodeId(), (NodeId) versionId, done);
+        if (version instanceof VersionImpl) {
+            session.getVersionManager().resolveMergeConflict(getNodeId(), (NodeId) ((VersionImpl)version).getId(), done);
         } else {
             throw new RepositoryException("Unexpected error: Failed to retrieve a valid ID for version " + version.getPath());
         }
@@ -1026,9 +1026,8 @@
      * @throws RepositoryException
      */
     private void restore(NodeId nodeId, Version version, boolean removeExisting) throws PathNotFoundException, ItemExistsException, VersionException, ConstraintViolationException, UnsupportedRepositoryOperationException, LockException, InvalidItemStateException, RepositoryException {
-        ItemId versionId = session.getHierarchyManager().getItemId(version);
-        if (versionId.denotesNode()) {
-            session.getVersionManager().restore(nodeId, (NodeId) versionId, removeExisting);
+        if (version instanceof VersionImpl) {
+            session.getVersionManager().restore(nodeId, (NodeId) ((VersionImpl)version).getId(), removeExisting);
         } else {
             throw new RepositoryException("Unexpected error: Failed to retrieve a valid ID for the given version " + version.getPath());
         }
@@ -1071,7 +1070,7 @@
         checkIsLockable();
         checkHasPendingChanges();
 
-        return session.getLockManager().lock(getNodeId(), isDeep, isSessionScoped);
+        return session.getLockManager().lock(getNodeId(), this, isDeep, isSessionScoped);
     }
 
     /**
@@ -1154,7 +1153,7 @@
      * @see ItemImpl#getQName()
      */
     QName getQName() throws RepositoryException {
-        return session.getHierarchyManager().getQName(getId());
+        return session.getHierarchyManager().getQName(getNodeState());
     }
 
 
@@ -1270,16 +1269,21 @@
         itemStateMgr.execute(an);
 
         // retrieve id of state that has been created during execution of AddNode
-        NodeId childId;
-        List cne = getNodeState().getChildNodeEntries(nodeName);
-        if (definition.allowsSameNameSiblings()) {
-            // TODO: find proper solution. problem with same-name-siblings
-            childId = ((ChildNodeEntry)cne.get(cne.size()-1)).getId();
-        } else {
-            childId = ((ChildNodeEntry)cne.get(0)).getId();
+        NodeState childState;
+        try {
+            List cne = getNodeState().getChildNodeEntries(nodeName);
+            if (definition.allowsSameNameSiblings()) {
+                // TODO: find proper solution. problem with same-name-siblings
+                childState = ((ChildNodeEntry)cne.get(cne.size()-1)).getNodeState();
+            } else {
+                childState = ((ChildNodeEntry)cne.get(0)).getNodeState();
+            }
+        } catch (ItemStateException e) {
+            // should not occur
+            throw new RepositoryException(e);
         }
         // finally retrieve the new node
-        return (Node) itemMgr.getItem(childId);
+        return (Node) itemMgr.getItem(childState);
     }
 
     /**
@@ -1294,7 +1298,7 @@
         checkStatus();
         try {
             PropertyState pState = getNodeState().getPropertyState(qName);
-            return (Property) itemMgr.getItem(pState.getId());
+            return (Property) itemMgr.getItem(pState);
         } catch (AccessDeniedException ade) {
             throw new ItemNotFoundException(qName.toString());
         } catch (NoSuchItemStateException e) {
@@ -1500,13 +1504,13 @@
      * Note that access rights are not checked.
      *
      * @param relPath relative path of a (possible) node.
-     * @return the id of the node at <code>relPath</code> or <code>null</code>
+     * @return the state of the node at <code>relPath</code> or <code>null</code>
      * if no node exists at <code>relPath</code>.
      * @throws RepositoryException if <code>relPath</code> is not a valid
      * relative path.
      */
-    private NodeId resolveRelativeNodePath(String relPath) throws RepositoryException {
-        NodeId targetId = null;
+    private NodeState resolveRelativeNodePath(String relPath) throws RepositoryException {
+        NodeState targetState = null;
         try {
             Path p = getQPath(relPath);
             // if relative path is just the last path element -> simply retrieve
@@ -1518,13 +1522,13 @@
                     int index = pe.getNormalizedIndex();
                     ChildNodeEntry cne = getNodeState().getChildNodeEntry(pe.getName(), index);
                     if (cne != null) {
-                        targetId = cne.getId();
+                        targetState = cne.getNodeState();
                     } // else: there's no child node with that name
                 }
             } else {
-                ItemId id = session.getHierarchyManager().getItemId(p.getCanonicalPath());
-                if (id.denotesNode()) {
-                    targetId = (NodeId) id;
+                ItemState itemState = session.getHierarchyManager().getItemState(p.getCanonicalPath());
+                if (itemState.isNode()) {
+                    targetState = (NodeState) itemState;
                 } // else:  not a node
             }
         } catch (PathNotFoundException e) {
@@ -1533,8 +1537,13 @@
             String msg = "Invalid relative path: " + relPath;
             log.debug(msg);
             throw new RepositoryException(msg, e);
+        } catch (ItemStateException e) {
+            // should not occure
+            String msg = "Invalid relative path: " + relPath;
+            log.debug(msg);
+            throw new RepositoryException(msg, e);
         }
-        return targetId;
+        return targetState;
     }
 
     /**
@@ -1544,12 +1553,12 @@
      * Note that access rights are not checked.
      *
      * @param relPath relative path of a (possible) property
-     * @return the id of the property at <code>relPath</code> or
+     * @return the state of the property at <code>relPath</code> or
      *         <code>null</code> if no property exists at <code>relPath</code>
      * @throws RepositoryException if <code>relPath</code> is not a valid
      *                             relative path
      */
-    private PropertyId resolveRelativePropertyPath(String relPath) throws RepositoryException {
+    private PropertyState resolveRelativePropertyPath(String relPath) throws RepositoryException {
         try {
             /**
              * first check if relPath is just a name (in which case we don't
@@ -1560,7 +1569,7 @@
                 // check if property entry exists
                 if (getNodeState().hasPropertyName(propName)) {
                     try {
-                        return getNodeState().getPropertyState(propName).getPropertyId();
+                        return getNodeState().getPropertyState(propName);
                     } catch (ItemStateException e) {
                         // should not occur due, since existance has been checked
                         throw new RepositoryException(e);
@@ -1575,9 +1584,9 @@
              */
             Path p = getQPath(relPath).getCanonicalPath();
             try {
-                ItemId id = session.getHierarchyManager().getItemId(p);
-                if (!id.denotesNode()) {
-                    return (PropertyId) id;
+                ItemState itemState = session.getHierarchyManager().getItemState(p);
+                if (!itemState.isNode()) {
+                    return (PropertyState) itemState;
                 } else {
                     // not a property
                     return null;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/PropertyImpl.java Tue Aug  8 06:39:25 2006
@@ -86,7 +86,7 @@
      */
     public Node getParent() throws ItemNotFoundException, AccessDeniedException, RepositoryException {
         checkStatus();
-        return (Node) itemMgr.getItem(getItemState().getParent().getId());
+        return (Node) itemMgr.getItem(getItemState().getParent());
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/SessionImpl.java Tue Aug  8 06:39:25 2006
@@ -24,6 +24,9 @@
 import org.apache.jackrabbit.jcr2spi.state.ItemStateManager;
 import org.apache.jackrabbit.jcr2spi.state.UpdatableItemStateManager;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
+import org.apache.jackrabbit.jcr2spi.state.NoSuchItemStateException;
+import org.apache.jackrabbit.jcr2spi.state.ItemStateException;
 import org.apache.jackrabbit.jcr2spi.xml.DocViewSAXEventGenerator;
 import org.apache.jackrabbit.jcr2spi.xml.SysViewSAXEventGenerator;
 import org.apache.jackrabbit.jcr2spi.xml.ImportHandler;
@@ -161,7 +164,7 @@
         itemStateManager = createSessionItemStateManager(workspace.getRootNodeId(), workspace.getUpdatableItemStateManager(), nsMappings);
 
         // DIFF JACKRABBIT: itemManager = createItemManager(itemStateMgr, hierMgr);
-        itemManager = createItemManager(itemStateManager, getHierarchyManager());
+        itemManager = createItemManager(getHierarchyManager());
     }
 
     //--------------------------------------------------< Session interface >---
@@ -236,7 +239,16 @@
      */
     public Node getRootNode() throws RepositoryException {
         checkIsAlive();
-        return (Node) itemManager.getItem(workspace.getRootNodeId());
+        try {
+            ItemState state = getItemStateManager().getItemState(workspace.getRootNodeId());
+            return (Node) itemManager.getItem(state);
+        } catch (NoSuchItemStateException e) {
+            throw new ItemNotFoundException();
+        } catch (ItemStateException e) {
+            String msg = "Failed to retrieve root node.";
+            log.error(msg, e);
+            throw new RepositoryException(msg, e);
+        }
     }
 
     /**
@@ -266,9 +278,16 @@
         // check sanity of this session
         checkIsAlive();
         try {
-            return (NodeImpl) getItemManager().getItem(id);
+            ItemState state = getItemStateManager().getItemState(id);
+            return (NodeImpl) getItemManager().getItem(state);
         } catch (AccessDeniedException ade) {
             throw new ItemNotFoundException(id.toString());
+        } catch (NoSuchItemStateException e) {
+            throw new ItemNotFoundException(id.toString());
+        } catch (ItemStateException e) {
+            String msg = "failed to retrieve item state of item " + id;
+            log.error(msg, e);
+            throw new RepositoryException(msg, e);
         }
     }
 
@@ -312,7 +331,7 @@
         Path destPath = getQPath(destAbsPath);
 
         // all validation is performed by Move Operation and state-manager
-        Operation op = Move.create(srcPath, destPath, validator);
+        Operation op = Move.create(srcPath, destPath, getHierarchyManager(), getNamespaceResolver());
         itemStateManager.execute(op);
     }
 
@@ -363,8 +382,8 @@
         Path targetPath = getQPath(absPath);
         boolean isGranted;
         if (itemExists(absPath)) {
-            ItemId id = getHierarchyManager().getItemId(targetPath);
-            isGranted = getAccessManager().isGranted(id, actionsArr);
+            ItemState itemState = getHierarchyManager().getItemState(targetPath);
+            isGranted = getAccessManager().isGranted(itemState.getId(), actionsArr);
         } else {
             // TODO: if spi-ids are used, its possible to build an id for a non-existing item (see also Node.restore)
             // The given abs-path may point to a non-existing item
@@ -373,7 +392,7 @@
             while (parentId == null) {
                 parentPath = parentPath.getAncestor(1);
                 if (itemManager.itemExists(parentPath)) {
-                    ItemId id = getHierarchyManager().getItemId(parentPath);
+                    ItemId id = getHierarchyManager().getItemState(parentPath).getId();
                     if (id.denotesNode()) {
                         parentId = (NodeId) id;
                     }
@@ -673,8 +692,8 @@
         return new SessionItemStateManager(rootId, workspaceStateManager, getIdFactory(), valueFactory, getValidator(), nsResolver);
     }
 
-    protected ItemManager createItemManager(ItemStateManager itemStateMgr, HierarchyManager hierarchyMgr) {
-        return new ItemManagerImpl(itemStateMgr, hierarchyMgr, this);
+    protected ItemManager createItemManager(HierarchyManager hierarchyMgr) {
+        return new ItemManagerImpl(hierarchyMgr, this);
     }
 
     //---------------------------------------------------< ManagerProvider > ---

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceImpl.java Tue Aug  8 06:39:25 2006
@@ -20,6 +20,7 @@
 import org.apache.jackrabbit.jcr2spi.state.UpdatableItemStateManager;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateManager;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeRegistry;
 import org.apache.jackrabbit.jcr2spi.query.QueryManagerImpl;
 import org.apache.jackrabbit.jcr2spi.operation.Move;
@@ -33,6 +34,7 @@
 import org.apache.jackrabbit.jcr2spi.version.VersionManager;
 import org.apache.jackrabbit.jcr2spi.version.VersionManagerImpl;
 import org.apache.jackrabbit.jcr2spi.version.DefaultVersionManager;
+import org.apache.jackrabbit.jcr2spi.version.VersionImpl;
 import org.apache.jackrabbit.jcr2spi.name.NamespaceRegistryImpl;
 import org.apache.jackrabbit.jcr2spi.observation.ObservationManagerImpl;
 import org.apache.jackrabbit.jcr2spi.xml.WorkspaceContentHandler;
@@ -41,7 +43,6 @@
 import org.apache.jackrabbit.spi.SessionInfo;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.ItemId;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 import org.xml.sax.ContentHandler;
@@ -128,7 +129,7 @@
         Path srcPath = session.getQPath(srcAbsPath);
         Path destPath = session.getQPath(destAbsPath);
 
-        Operation op = Copy.create(srcPath, destPath, this, validator);
+        Operation op = Copy.create(srcPath, destPath, this, this);
         getUpdatableItemStateManager().execute(op);
     }
 
@@ -164,7 +165,7 @@
             WorkspaceImpl srcWsp = (WorkspaceImpl) srcSession.getWorkspace();
 
             // do cross-workspace copy
-            Operation op = Copy.create(srcPath, destPath, srcWsp.getName(), srcWsp, validator);
+            Operation op = Copy.create(srcPath, destPath, srcWsp.getName(), srcWsp, this);
             getUpdatableItemStateManager().execute(op);
         } finally {
             if (srcSession != null) {
@@ -207,7 +208,7 @@
             WorkspaceImpl srcWsp = (WorkspaceImpl) srcSession.getWorkspace();
 
             // do clone
-            Operation op = Clone.create(srcPath, destPath, srcWsp.getName(), removeExisting, srcWsp, validator);
+            Operation op = Clone.create(srcPath, destPath, srcWsp.getName(), removeExisting, srcWsp, this);
             getUpdatableItemStateManager().execute(op);
         } finally {
             if (srcSession != null) {
@@ -227,7 +228,7 @@
         Path srcPath = session.getQPath(srcAbsPath);
         Path destPath = session.getQPath(destAbsPath);
 
-        Operation op = Move.create(srcPath, destPath, validator);
+        Operation op = Move.create(srcPath, destPath, getHierarchyManager(), getNamespaceResolver());
         getUpdatableItemStateManager().execute(op);
     }
 
@@ -240,9 +241,8 @@
 
         NodeId[] versionIds = new NodeId[versions.length];
         for (int i = 0; i < versions.length; i++) {
-            ItemId versionId = session.getHierarchyManager().getItemId(versions[i]);
-            if (versionId.denotesNode()) {
-                versionIds[i] = (NodeId) versionId;
+            if (versions[i] instanceof VersionImpl) {
+                versionIds[i] = (NodeId) ((VersionImpl)versions[i]).getId();
             } else {
                 throw new RepositoryException("Unexpected error: Failed to retrieve a valid ID for the given version " + versions[i].getPath());
             }
@@ -307,8 +307,8 @@
         session.checkIsAlive();
 
         Path parentPath = session.getQPath(parentAbsPath);
-        ItemId parentId = getHierarchyManager().getItemId(parentPath);
-        if (parentId.denotesNode()) {
+        ItemState parentState = getHierarchyManager().getItemState(parentPath);
+        if (parentState.isNode()) {
             return new WorkspaceContentHandler(this, parentAbsPath, uuidBehavior);
         } else {
             throw new PathNotFoundException("No node at path " + parentAbsPath);
@@ -325,9 +325,9 @@
         LockException, RepositoryException {
 
         Path parentPath = session.getQPath(parentAbsPath);
-        ItemId parentId = getHierarchyManager().getItemId(parentPath);
-        if (parentId.denotesNode()) {
-            wspManager.importXml((NodeId) parentId, in, uuidBehavior);
+        ItemState parentState = getHierarchyManager().getItemState(parentPath);
+        if (parentState.isNode()) {
+            wspManager.importXml((NodeId) parentState.getId(), in, uuidBehavior);
         } else {
             throw new PathNotFoundException("No node at path " + parentAbsPath);
         }
@@ -346,7 +346,7 @@
      */
     public HierarchyManager getHierarchyManager() {
         if (hierManager == null) {
-            hierManager = new CachingHierarchyManager(getRootNodeId(),
+            hierManager = new HierarchyManagerImpl(getRootNodeId(),
                 getItemStateManager(), getNamespaceResolver());
         }
         return hierManager;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ZombieHierarchyManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ZombieHierarchyManager.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ZombieHierarchyManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ZombieHierarchyManager.java Tue Aug  8 06:39:25 2006
@@ -96,6 +96,20 @@
     /**
      * {@inheritDoc}
      * <p/>
+     * Also allows for removed items.
+     */
+    protected NodeState getParentState(ItemState state) {
+        if (state.hasOverlayedState()) {
+            // use 'old' parent in case item has been removed
+            return state.getOverlayedState().getParent();
+        }
+        // delegate to base class
+        return super.getParentState(state);
+    }
+
+    /**
+     * {@inheritDoc}
+     * <p/>
      * Also allows for removed/renamed child node entries.
      */
     protected ChildNodeEntry getChildNodeEntry(NodeState parent,

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/DefaultLockManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/DefaultLockManager.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/DefaultLockManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/DefaultLockManager.java Tue Aug  8 06:39:25 2006
@@ -24,6 +24,7 @@
 import javax.jcr.lock.LockException;
 import javax.jcr.RepositoryException;
 import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.Node;
 
 /**
  * <code>DefaultLockManager</code>...
@@ -32,7 +33,7 @@
 
     private static Logger log = LoggerFactory.getLogger(DefaultLockManager.class);
 
-    public Lock lock(NodeId nodeId, boolean isDeep, boolean isSessionScoped) throws LockException, RepositoryException {
+    public Lock lock(NodeId nodeId, Node node, boolean isDeep, boolean isSessionScoped) throws LockException, RepositoryException {
         throw new UnsupportedRepositoryOperationException("Locking ist not supported by this repository.");
     }
 

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManager.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManager.java Tue Aug  8 06:39:25 2006
@@ -17,6 +17,8 @@
 package org.apache.jackrabbit.jcr2spi.lock;
 
 import javax.jcr.RepositoryException;
+import javax.jcr.Node;
+
 import org.apache.jackrabbit.spi.NodeId;
 import javax.jcr.lock.Lock;
 import javax.jcr.lock.LockException;
@@ -25,12 +27,15 @@
  * Defines the functionality needed for locking and unlocking nodes.
  */
 public interface LockManager {
-    
+
+    // TODO Review usage of NodeId
+
     /**
      * Lock a node. Checks whether the node is not locked and then
      * returns a lock object for this node.
      *
      * @param nodeId node id.
+     * @param node
      * @param isDeep whether the lock applies to this node only
      * @param isSessionScoped whether the lock is session scoped
      * @return lock object
@@ -38,7 +43,8 @@
      *         node is locked and <code>isDeep</code> is <code>true</code>
      * @see javax.jcr.Node#lock
      */
-    Lock lock(NodeId nodeId, boolean isDeep, boolean isSessionScoped)
+    // TODO review params
+    Lock lock(NodeId nodeId, Node node, boolean isDeep, boolean isSessionScoped)
         throws LockException, RepositoryException;
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/lock/LockManagerImpl.java Tue Aug  8 06:39:25 2006
@@ -57,7 +57,8 @@
     private final ItemManager itemManager;
 
     /**
-     * Internal map holding all locks that where created by {@link #lock(NodeId, boolean, boolean)}
+     * Internal map holding all locks that where created by
+     * {@link #lock(NodeId, Node, boolean, boolean)}
      * or accessed by {@link #getLock(NodeId)} until they end their life by
      * an unlock (be it by the current Session or external reported by means
      * of events).
@@ -71,11 +72,9 @@
     }
 
     /**
-     * @see LockManager#lock(NodeId, boolean, boolean)
+     * @see LockManager#lock(NodeId, Node, boolean, boolean)
      */
-    public Lock lock(NodeId nodeId, boolean isDeep, boolean isSessionScoped) throws LockException, RepositoryException {
-        // make sure the node is accessible before trying to create a lock.
-        Node node = (Node) itemManager.getItem(nodeId);
+    public Lock lock(NodeId nodeId, Node node, boolean isDeep, boolean isSessionScoped) throws LockException, RepositoryException {
         // execute the operation
         Operation op = LockOperation.create(nodeId, isDeep, isSessionScoped);
         wspManager.execute(op);
@@ -112,7 +111,7 @@
 
             // retrieve lock holding node. not that this may fail if the session
             // does not have permission to see this node.
-            Item lockHoldingNode = itemManager.getItem(lhNodeId);
+            Item lockHoldingNode = itemManager.getItem(lockHoldingState);
             // TODO: we don;t know if lock is session scoped -> set flag to false
             // TODO: ev. add 'isSessionScoped' to RepositoryService lock-call.
             Lock l = new LockImpl(lhNodeId, (Node)lockHoldingNode, false);



Mime
View raw message