jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r429652 [2/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
Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractCopy.java Tue Aug  8 06:39:25 2006
@@ -16,9 +16,9 @@
  */
 package org.apache.jackrabbit.jcr2spi.operation;
 
-import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
-import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.spi.NodeId;
@@ -48,15 +48,15 @@
      * @param srcMgrProvider
      */
     AbstractCopy(Path srcPath, Path destPath, String srcWorkspaceName,
-                 ManagerProvider srcMgrProvider, ItemStateValidator validator)
+                 ManagerProvider srcMgrProvider, ManagerProvider destMgrProvider)
         throws RepositoryException {
 
-        ItemId srcItemId = srcMgrProvider.getHierarchyManager().getItemId(srcPath);
-        if (!srcItemId.denotesNode()) {
-            throw new PathNotFoundException("Source path " + validator.safeGetJCRPath(srcItemId) + " is not a valid path.");
+        ItemState srcItemState = srcMgrProvider.getHierarchyManager().getItemState(srcPath);
+        if (!srcItemState.isNode()) {
+            throw new PathNotFoundException("Source path " + LogUtil.safeGetJCRPath(srcPath, srcMgrProvider.getNamespaceResolver()) + " is not a valid path.");
         }
-        this.srcId = (NodeId)srcItemId;
-        this.destParentId = validator.getNodeId(destPath.getAncestor(1));
+        this.srcId = (NodeId)srcItemState.getId();
+        this.destParentId = getNodeId(destPath.getAncestor(1), destMgrProvider.getHierarchyManager(), destMgrProvider.getNamespaceResolver());
         addAffectedItemId(destParentId);
 
         // check for illegal index present in destination path

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractOperation.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractOperation.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractOperation.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/AbstractOperation.java Tue Aug  8 06:39:25 2006
@@ -17,7 +17,15 @@
 package org.apache.jackrabbit.jcr2spi.operation;
 
 import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.jcr2spi.HierarchyManager;
+import org.apache.jackrabbit.jcr2spi.util.LogUtil;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
 
+import javax.jcr.PathNotFoundException;
+import javax.jcr.RepositoryException;
 import java.util.Collection;
 import java.util.ArrayList;
 import java.util.Collections;
@@ -56,5 +64,24 @@
      */
     protected void addAffectedItemId(ItemId affectedId) {
         affectedIds.add(affectedId);
+    }
+
+    // TODO to be removed after ID refactoring completed
+
+    /**
+     * 
+     * @param nodePath
+     * @param hierMgr
+     * @param nsResolver
+     * @return
+     * @throws PathNotFoundException
+     * @throws RepositoryException
+     */
+    protected static NodeId getNodeId(Path nodePath, HierarchyManager hierMgr, NamespaceResolver nsResolver) throws PathNotFoundException, RepositoryException {
+        ItemState itemState = hierMgr.getItemState(nodePath);
+        if (!itemState.isNode()) {
+            throw new PathNotFoundException(LogUtil.safeGetJCRPath(nodePath, nsResolver));
+        }
+        return (NodeId)itemState.getId();
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Clone.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Clone.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Clone.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Clone.java Tue Aug  8 06:39:25 2006
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.jcr2spi.operation;
 
-import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.apache.jackrabbit.name.Path;
 
@@ -38,9 +37,9 @@
 
     private Clone(Path srcPath, Path destPath, String srcWorkspaceName,
                   boolean removeExisting, ManagerProvider srcMgrProvider,
-                  ItemStateValidator validator)
+                  ManagerProvider destMgrProvider)
         throws RepositoryException {
-        super(srcPath, destPath, srcWorkspaceName, srcMgrProvider, validator);
+        super(srcPath, destPath, srcWorkspaceName, srcMgrProvider, destMgrProvider);
         this.removeExisting = removeExisting;
     }
 
@@ -63,11 +62,11 @@
     public static Operation create(Path srcPath, Path destPath,
                                    String srcWorkspaceName, boolean removeExisting,
                                    ManagerProvider srcMgrProvider,
-                                   ItemStateValidator validator)
+                                   ManagerProvider destMgrProvider)
         throws RepositoryException, ConstraintViolationException, AccessDeniedException,
         ItemExistsException, VersionException {
 
-        Clone cl = new Clone(srcPath, destPath, srcWorkspaceName, removeExisting, srcMgrProvider, validator);
+        Clone cl = new Clone(srcPath, destPath, srcWorkspaceName, removeExisting, srcMgrProvider, destMgrProvider);
         return cl;
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Copy.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Copy.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Copy.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Copy.java Tue Aug  8 06:39:25 2006
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.jcr2spi.operation;
 
-import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.apache.jackrabbit.name.Path;
 
@@ -34,8 +33,9 @@
  */
 public class Copy extends AbstractCopy  {
 
-    private Copy(Path srcPath, Path destPath, String srcWorkspaceName, ManagerProvider srcMgrProvider, ItemStateValidator validator) throws RepositoryException {
-        super(srcPath, destPath, srcWorkspaceName, srcMgrProvider, validator);
+    private Copy(Path srcPath, Path destPath, String srcWorkspaceName,
+                 ManagerProvider srcMgrProvider, ManagerProvider destMgrProvider) throws RepositoryException {
+        super(srcPath, destPath, srcWorkspaceName, srcMgrProvider, destMgrProvider);
     }
 
     //----------------------------------------------------------< Operation >---
@@ -50,19 +50,19 @@
     //------------------------------------------------------------< Factory >---
     public static Operation create(Path srcPath, Path destPath,
                                    ManagerProvider mgrProvider,
-                                   ItemStateValidator validator)
+                                   ManagerProvider destMgrProvider)
         throws RepositoryException, ConstraintViolationException, AccessDeniedException,
         ItemExistsException, VersionException {
-        return create(srcPath, destPath, null, mgrProvider, validator);
+        return create(srcPath, destPath, null, mgrProvider, destMgrProvider);
     }
 
     public static Operation create(Path srcPath, Path destPath,
                                    String srcWorkspaceName,
                                    ManagerProvider srcMgrProvider,
-                                   ItemStateValidator validator)
+                                   ManagerProvider destMgrProvider)
         throws RepositoryException, ConstraintViolationException, AccessDeniedException,
         ItemExistsException, VersionException {
-        Copy cp = new Copy(srcPath, destPath, srcWorkspaceName, srcMgrProvider, validator);
+        Copy cp = new Copy(srcPath, destPath, srcWorkspaceName, srcMgrProvider, destMgrProvider);
         return cp;
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Move.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Move.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Move.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/operation/Move.java Tue Aug  8 06:39:25 2006
@@ -16,10 +16,12 @@
  */
 package org.apache.jackrabbit.jcr2spi.operation;
 
-import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
+import org.apache.jackrabbit.jcr2spi.util.LogUtil;
+import org.apache.jackrabbit.jcr2spi.HierarchyManager;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.MalformedPathException;
+import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.spi.NodeId;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -82,16 +84,16 @@
     }
 
     //------------------------------------------------------------< Factory >---
-    public static Operation create(Path srcPath, Path destPath, ItemStateValidator validator) throws RepositoryException , NoSuchNodeTypeException {
+    public static Operation create(Path srcPath, Path destPath, HierarchyManager hierMgr, NamespaceResolver nsResolver) throws RepositoryException , NoSuchNodeTypeException {
         // src must not be ancestor of destination
         try {
             if (srcPath.isAncestorOf(destPath)) {
-                String msg = "Invalid destination path: cannot be descendant of source path (" +validator.safeGetJCRPath(destPath) + "," + validator.safeGetJCRPath(srcPath) + ")";
+                String msg = "Invalid destination path: cannot be descendant of source path (" + LogUtil.safeGetJCRPath(destPath, nsResolver) + "," + LogUtil.safeGetJCRPath(srcPath, nsResolver) + ")";
                 log.debug(msg);
                 throw new RepositoryException(msg);
             }
         } catch (MalformedPathException e) {
-            String msg = "Invalid destination path: cannot be descendant of source path (" +validator.safeGetJCRPath(destPath) + "," + validator.safeGetJCRPath(srcPath) + ")";
+            String msg = "Invalid destination path: cannot be descendant of source path (" +LogUtil.safeGetJCRPath(destPath, nsResolver) + "," + LogUtil.safeGetJCRPath(srcPath, nsResolver) + ")";
             log.debug(msg);
             throw new RepositoryException(msg, e);
         }
@@ -100,7 +102,7 @@
         int index = destElement.getIndex();
         if (index > org.apache.jackrabbit.name.Path.INDEX_UNDEFINED) {
             // subscript in name element
-            String msg = "Invalid destination path: subscript in name element is not allowed (" + validator.safeGetJCRPath(destPath) + ")";
+            String msg = "Invalid destination path: subscript in name element is not allowed (" + LogUtil.safeGetJCRPath(destPath, nsResolver) + ")";
             log.debug(msg);
             throw new RepositoryException(msg);
         }
@@ -111,9 +113,9 @@
             throw new RepositoryException(msg);
         }
 
-        NodeId srcId = validator.getNodeId(srcPath);
-        NodeId srcParentId = validator.getNodeId(srcPath.getAncestor(1));
-        NodeId destParentId = validator.getNodeId(destPath.getAncestor(1));
+        NodeId srcId = getNodeId(srcPath, hierMgr, nsResolver);
+        NodeId srcParentId = getNodeId(srcPath.getAncestor(1), hierMgr, nsResolver);
+        NodeId destParentId = getNodeId(destPath.getAncestor(1), hierMgr, nsResolver);
         Move move = new Move(srcId, srcParentId, destParentId, destElement.getName());
         return move;
     }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/query/NodeIteratorImpl.java Tue Aug  8 06:39:25 2006
@@ -223,6 +223,8 @@
      * method returns, then there are no more valid element in this iterator.
      */
     private void fetchNext() {
+        // TODO
+        /*
         // reset
         next = null;
         while (next == null && ids.hasNext()) {
@@ -251,5 +253,6 @@
             }
         }
         pos++;
+        */
     }
 }

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildPropertyEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildPropertyEntry.java?rev=429652&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildPropertyEntry.java (added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildPropertyEntry.java Tue Aug  8 06:39:25 2006
@@ -0,0 +1,45 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.state;
+
+import org.apache.jackrabbit.spi.PropertyId;
+import org.apache.jackrabbit.name.QName;
+
+/**
+ * <code>ChildPropertyEntry</code>...
+ */
+public interface ChildPropertyEntry {
+
+    /**
+     * @return the <code>NodeId</code> of this child node entry.
+     */
+    public PropertyId getId();
+
+    /**
+     * @return the name of this child node entry.
+     */
+    public QName getName();
+
+    /**
+     * @return the referenced <code>PropertyState</code>.
+     * @throws NoSuchItemStateException if the <code>PropertyState</code> does not
+     * exist anymore.
+     * @throws ItemStateException if an error occurs while retrieving the
+     * <code>PropertyState</code>.
+     */
+    public PropertyState getPropertyState() throws NoSuchItemStateException, ItemStateException;
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildPropertyEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ChildPropertyEntry.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ItemStateValidator.java Tue Aug  8 06:39:25 2006
@@ -22,6 +22,7 @@
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.jcr2spi.ManagerProvider;
 import org.apache.jackrabbit.jcr2spi.HierarchyManager;
+import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.jcr2spi.security.AccessManager;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -39,10 +40,10 @@
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QItemDefinition;
 import org.apache.jackrabbit.spi.NodeId;
-import org.apache.jackrabbit.spi.PropertyId;
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.NamespaceResolver;
 import org.apache.jackrabbit.value.QValue;
 
 import javax.jcr.nodetype.ConstraintViolationException;
@@ -147,7 +148,7 @@
         QName[] requiredPrimaryTypes = def.getRequiredPrimaryTypes();
         for (int i = 0; i < requiredPrimaryTypes.length; i++) {
             if (!entPrimary.includesNodeType(requiredPrimaryTypes[i])) {
-                String msg = safeGetJCRPath(nodeState.getNodeId())
+                String msg = safeGetJCRPath(nodeState)
                         + ": missing required primary type "
                         + requiredPrimaryTypes[i];
                 log.debug(msg);
@@ -159,7 +160,7 @@
         for (int i = 0; i < pda.length; i++) {
             QPropertyDefinition pd = pda[i];
             if (!nodeState.hasPropertyName(pd.getQName())) {
-                String msg = safeGetJCRPath(nodeState.getNodeId())
+                String msg = safeGetJCRPath(nodeState)
                         + ": mandatory property " + pd.getQName()
                         + " does not exist";
                 log.debug(msg);
@@ -171,7 +172,7 @@
         for (int i = 0; i < cnda.length; i++) {
             QNodeDefinition cnd = cnda[i];
             if (!nodeState.hasChildNodeEntry(cnd.getQName())) {
-                String msg = safeGetJCRPath(nodeState.getNodeId())
+                String msg = safeGetJCRPath(nodeState)
                         + ": mandatory child node " + cnd.getQName()
                         + " does not exist";
                 log.debug(msg);
@@ -231,7 +232,7 @@
         try {
             return getEffectiveNodeType(nodeState.getNodeTypeNames());
         } catch (NodeTypeConflictException ntce) {
-            String msg = "Internal error: failed to build effective node type from node types defined with " + safeGetJCRPath(nodeState.getId());
+            String msg = "Internal error: failed to build effective node type from node types defined with " + safeGetJCRPath(nodeState);
             log.debug(msg);
             throw new RepositoryException(msg, ntce);
         }
@@ -253,26 +254,15 @@
     }
 
     /**
-     * Failsafe conversion of internal <code>Path</code> to JCR path for use in
-     * error messages etc.
-     *
-     * @param path path to convert
-     * @return JCR path
-     */
-    public String safeGetJCRPath(Path path) {
-        return mgrProvider.getHierarchyManager().safeGetJCRPath(path);
-    }
-
-    /**
-     * Failsafe translation of internal <code>ItemId</code> to JCR path for use
+     * Failsafe translation of internal <code>ItemState</code> to JCR path for use
      * in error messages etc.
      *
-     * @param id id to translate
+     * @param itemState
      * @return JCR path
-     * @see HierarchyManager#safeGetJCRPath(ItemId)
+     * @see LogUtil#safeGetJCRPath(ItemState, NamespaceResolver, HierarchyManager)
      */
-    public String safeGetJCRPath(ItemId id) {
-        return mgrProvider.getHierarchyManager().safeGetJCRPath(id);
+    private String safeGetJCRPath(ItemState itemState) {
+        return LogUtil.safeGetJCRPath(itemState, mgrProvider.getNamespaceResolver(), mgrProvider.getHierarchyManager());
     }
 
     /**
@@ -365,7 +355,7 @@
         if ((options & CHECK_ACCESS) == CHECK_ACCESS) {
             // make sure current session is granted read access on parent node
             if (!mgrProvider.getAccessManager().canRead(parentState.getNodeId())) {
-                throw new ItemNotFoundException(safeGetJCRPath(parentState.getNodeId()));
+                throw new ItemNotFoundException(safeGetJCRPath(parentState));
             }
         }
 
@@ -471,7 +461,7 @@
             // make sure current session is granted write access on new prop
             Path relPath = Path.create(propertyName, Path.INDEX_UNDEFINED);
             if (!mgrProvider.getAccessManager().isGranted(parentState.getNodeId(), relPath, new String[] {AccessManager.SET_PROPERTY_ACTION})) {
-                throw new AccessDeniedException(safeGetJCRPath(parentState.getId()) + ": not allowed to create property with name " + propertyName);
+                throw new AccessDeniedException(safeGetJCRPath(parentState) + ": not allowed to create property with name " + propertyName);
             }
         }
 
@@ -534,7 +524,7 @@
             // TODO build Id instead 
             Path relPath = Path.create(nodeName, org.apache.jackrabbit.name.Path.INDEX_UNDEFINED);
             if (!mgrProvider.getAccessManager().isGranted(parentState.getNodeId(), relPath, new String[] {AccessManager.ADD_NODE_ACTION})) {
-                throw new AccessDeniedException(safeGetJCRPath(parentState.getNodeId()) + ": not allowed to add child node '" + nodeName +"'");
+                throw new AccessDeniedException(safeGetJCRPath(parentState) + ": not allowed to add child node '" + nodeName +"'");
             }
         }
 
@@ -601,16 +591,16 @@
             try {
                 // make sure current session is granted read access on parent node
                 if (!mgrProvider.getAccessManager().canRead(targetId)) {
-                    throw new PathNotFoundException(safeGetJCRPath(targetId));
+                    throw new PathNotFoundException(safeGetJCRPath(targetState));
                 }
                 // make sure current session is allowed to remove target node
                 if (!mgrProvider.getAccessManager().canRemove(targetId)) {
-                    throw new AccessDeniedException(safeGetJCRPath(targetId)
+                    throw new AccessDeniedException(safeGetJCRPath(targetState)
                             + ": not allowed to remove node");
                 }
             } catch (ItemNotFoundException infe) {
                 String msg = "internal error: failed to check access rights for "
-                        + safeGetJCRPath(targetId);
+                        + safeGetJCRPath(targetState);
                 log.debug(msg);
                 throw new RepositoryException(msg, infe);
             }
@@ -650,7 +640,7 @@
         }
         NodeState nodeState = (itemState.isNode()) ? (NodeState)itemState : itemState.getParent();
         if (!mgrProvider.getVersionManager().isCheckedOut(nodeState.getNodeId())) {
-            throw new VersionException(safeGetJCRPath(nodeState.getNodeId()) + " is checked-in");
+            throw new VersionException(safeGetJCRPath(nodeState) + " is checked-in");
         }
     }
 
@@ -741,14 +731,14 @@
         }
         // check for name collisions with existing properties
         if (parentState.hasPropertyName(propertyName)) {
-            PropertyId errorId = null;
+            PropertyState errorState = null;
             try {
-                errorId = parentState.getPropertyState(propertyName).getPropertyId();
+                errorState = parentState.getPropertyState(propertyName);
             } catch (ItemStateException e) {
                 // should not occur. existance has been asserted before
                 throw new RepositoryException(e);
             }
-            throw new ItemExistsException(safeGetJCRPath(errorId));
+            throw new ItemExistsException(safeGetJCRPath(errorState));
         }
     }
 
@@ -765,7 +755,7 @@
         if (parentState.hasPropertyName(nodeName)) {
             // there's already a property with that name
             throw new ItemExistsException("cannot add child node '"
-                + nodeName.getLocalName() + "' to " + safeGetJCRPath(parentState.getNodeId())
+                + nodeName.getLocalName() + "' to " + safeGetJCRPath(parentState)
                 + ": colliding with same-named existing property");
 
         } else if (parentState.hasChildNodeEntry(nodeName)) {
@@ -780,7 +770,7 @@
                 if (!(conflictDef.allowsSameNameSiblings() && newDef.allowsSameNameSiblings())) {
                     throw new ItemExistsException("Cannot add child node '"
                         + nodeName.getLocalName() + "' to "
-                        + safeGetJCRPath(parentState.getNodeId())
+                        + safeGetJCRPath(parentState)
                         + ": colliding with same-named existing node.");
                 }
             } catch (ItemStateException e) {
@@ -811,52 +801,15 @@
                 try {
                     NodeReferences refs = stateMgr.getNodeReferences(targetId);
                     if (refs.hasReferences()) {
-                        throw new ReferentialIntegrityException(safeGetJCRPath(targetId)
+                        throw new ReferentialIntegrityException(safeGetJCRPath(targetState)
                             + ": cannot remove node with references");
                     }
                 } catch (ItemStateException ise) {
-                    String msg = "internal error: failed to check references on " + safeGetJCRPath(targetId);
+                    String msg = "internal error: failed to check references on " + safeGetJCRPath(targetState);
                     log.error(msg, ise);
                     throw new RepositoryException(msg, ise);
                 }
             }
-        }
-    }
-
-    //--------------------------------------------------------------------------
-
-    public NodeId getNodeId(Path nodePath) throws PathNotFoundException, RepositoryException {
-        try {
-            ItemId id = mgrProvider.getHierarchyManager().getItemId(nodePath);
-            if (!id.denotesNode()) {
-                throw new PathNotFoundException(safeGetJCRPath(nodePath));
-            }
-            return (NodeId)id;
-        } catch (ItemNotFoundException infe) {
-            throw new PathNotFoundException(safeGetJCRPath(nodePath));
-        }
-    }
-
-    /**
-     * Retrieves the state of the item with the specified id using the given
-     * item state manager.
-     * <p/>
-     * Note that access rights are <b><i>not</i></b> enforced!
-     *
-     * @param id
-     * @return
-     * @throws ItemNotFoundException
-     * @throws RepositoryException
-     */
-    public NodeState getNodeState(NodeId id) throws ItemNotFoundException, RepositoryException {
-        try {
-            return (NodeState) mgrProvider.getItemStateManager().getItemState(id);
-        } catch (NoSuchItemStateException nsise) {
-            throw new ItemNotFoundException(safeGetJCRPath(id));
-        } catch (ItemStateException ise) {
-            String msg = "internal error: failed to retrieve state of " + safeGetJCRPath(id);
-            log.debug(msg);
-            throw new RepositoryException(msg, ise);
         }
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/NodeState.java Tue Aug  8 06:39:25 2006
@@ -369,7 +369,7 @@
      * @see #removeChildNodeEntry
      */
     public synchronized List getChildNodeEntries() {
-        return childNodeEntries;
+        return Collections.unmodifiableList(childNodeEntries);
     }
 
     /**
@@ -381,7 +381,7 @@
      * @see #removeChildNodeEntry
      */
     public synchronized List getChildNodeEntries(QName nodeName) {
-        return childNodeEntries.get(nodeName);
+        return Collections.unmodifiableList(childNodeEntries.get(nodeName));
     }
 
     /**
@@ -481,6 +481,17 @@
      */
     public synchronized Set getPropertyNames() {
         return Collections.unmodifiableSet(properties.keySet());
+    }
+
+    /**
+     * Returns the complete collection of {@link ChildPropertyEntry}s.
+     *
+     * @return unmodifiable collection of <code>ChildPropertyEntry</code> objects
+     * @see #addPropertyName
+     * @see #removePropertyName
+     */
+    public synchronized Collection getPropertyEntries() {
+        return Collections.unmodifiableCollection(properties.values());
     }
 
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PropertyReference.java Tue Aug  8 06:39:25 2006
@@ -23,7 +23,7 @@
 /**
  * <code>PropertyReference</code> implements a reference to a property state.
  */
-public class PropertyReference extends ChildItemReference {
+class PropertyReference extends ChildItemReference implements ChildPropertyEntry {
 
     /**
      * IdFactory to create an ItemId based on the parent NodeId
@@ -52,7 +52,28 @@
      */
     protected ItemState doResolve()
             throws NoSuchItemStateException, ItemStateException {
-        PropertyId id = idFactory.createPropertyId(parent.getNodeId(), name);
-        return isf.createPropertyState(id, getParent());
+        return isf.createPropertyState(getId(), getParent());
+    }
+
+    //-------------------------------------------------< ChildPropertyEntry >---
+    /**
+     * @inheritDoc
+     */
+    public PropertyId getId() {
+        return idFactory.createPropertyId(parent.getNodeId(), name);
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public QName getName() {
+        return name;
+    }
+
+    /**
+     * @inheritDoc
+     */
+    public PropertyState getPropertyState() throws NoSuchItemStateException, ItemStateException {
+        return (PropertyState) resolve();
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/SessionItemStateManager.java Tue Aug  8 06:39:25 2006
@@ -17,10 +17,11 @@
 package org.apache.jackrabbit.jcr2spi.state;
 
 import org.apache.commons.collections.iterators.IteratorChain;
-import org.apache.jackrabbit.jcr2spi.CachingHierarchyManager;
 import org.apache.jackrabbit.jcr2spi.HierarchyManager;
 import org.apache.jackrabbit.jcr2spi.ZombieHierarchyManager;
+import org.apache.jackrabbit.jcr2spi.HierarchyManagerImpl;
 import org.apache.jackrabbit.jcr2spi.util.ReferenceChangeTracker;
+import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
 import org.apache.jackrabbit.jcr2spi.operation.Operation;
@@ -98,12 +99,6 @@
     private static Logger log = LoggerFactory.getLogger(SessionItemStateManager.class);
 
     /**
-     * Id of the root node.
-     */
-    // TODO: TO-BE-FIXED. With SPI_ItemId rootId must not be stored separately
-    private final NodeId rootId;
-
-    /**
      * State manager that allows updates
      */
     private final UpdatableItemStateManager workspaceItemStateMgr;
@@ -117,14 +112,17 @@
     /**
      * Hierarchy manager
      */
-    // DIFF JACKRABBIT: private CachingHierarchyManager hierMgr;
-    private final CachingHierarchyManager hierMgr;
+    private final HierarchyManager hierMgr;
     private final NamespaceResolver nsResolver;
 
     private final IdFactory idFactory;
     private final ValueFactory valueFactory;
     private final ItemStateValidator validator;
 
+    // DIFF JR: store root id. since 'CachingItemStateManager' not used any more
+    // TODO: TO-BE-FIXED. With SPI_ItemId rootId must not be stored separately
+    private NodeId rootId;
+
     /**
      * Creates a new <code>SessionItemStateManager</code> instance.
      *
@@ -138,8 +136,6 @@
                                    ValueFactory valueFactory,
                                    ItemStateValidator validator,
                                    NamespaceResolver nsResolver) {
-        // DIFF JACKRABBIT: added rootId
-        this.rootId = rootId;
         this.workspaceItemStateMgr = workspaceItemStateMgr;
         // DIFF JACKRABBIT: this.transientStateMgr = new TransientItemStateManager();
         this.transientStateMgr = new TransientChangeLog(idFactory, workspaceItemStateMgr);
@@ -150,13 +146,16 @@
         // DIFF JR: valueFactory added
         this.valueFactory = valueFactory;
 
-        // create hierarchy manager that uses both transient and persistent state
-        hierMgr = new CachingHierarchyManager(rootId, this, nsResolver);
         this.nsResolver = nsResolver;
+        this.rootId = rootId;
+
+        // create hierarchy manager
+        hierMgr = new HierarchyManagerImpl(rootId, this, nsResolver);
+
     }
 
     /**
-     * 
+     *
      * @return
      */
     public HierarchyManager getHierarchyManager() {
@@ -488,7 +487,7 @@
                 // determine relative depth: > 0 means it's a descendant
                 int depth;
                 try {
-                    depth = hierMgr.getRelativeDepth(parentId, state.getId());
+                    depth = getHierarchyManager().getRelativeDepth(parentId, state.getId());
                 } catch (ItemNotFoundException infe) {
                     /**
                      * one of the parents of the specified item has been
@@ -570,10 +569,10 @@
 
         // use a special attic-aware hierarchy manager
         ZombieHierarchyManager zombieHierMgr =
-                new ZombieHierarchyManager(hierMgr.getRootNodeId(),
+                new ZombieHierarchyManager(rootId,
                         this,
                         transientStateMgr.getAttic(),
-                        hierMgr.getNamespaceResolver());
+                        nsResolver);
 
         // use an array of lists to group the descendants by relative depth;
         // the depth is used as array index
@@ -638,7 +637,7 @@
     private ChangeLog getChangeLog(ItemState itemState) throws StaleItemStateException, ItemStateException {
         ChangeLog changeLog = new TransientChangeLog(idFactory, workspaceItemStateMgr);
         if (rootId.equals(itemState.getId())) {
-            // get all item states
+            // root state -> get all item states
             for (Iterator it = transientStateMgr.addedStates(); it.hasNext(); ) {
                 changeLog.added((ItemState) it.next());
             }
@@ -730,28 +729,28 @@
 
                 case ItemState.STATUS_NEW:
                     {
-                        String msg = hierMgr.safeGetJCRPath(state.getId()) + ": cannot save a new item.";
+                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, getHierarchyManager()) + ": cannot save a new item.";
                         log.debug(msg);
                         throw new ItemStateException(msg);
                     }
 
                 case ItemState.STATUS_STALE_MODIFIED:
                     {
-                        String msg = hierMgr.safeGetJCRPath(state.getId()) + ": the item cannot be saved because it has been modified externally.";
+                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, getHierarchyManager()) + ": the item cannot be saved because it has been modified externally.";
                         log.debug(msg);
                         throw new StaleItemStateException(msg);
                     }
 
                 case ItemState.STATUS_STALE_DESTROYED:
                     {
-                        String msg = hierMgr.safeGetJCRPath(state.getId()) + ": the item cannot be saved because it has been deleted externally.";
+                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, getHierarchyManager()) + ": the item cannot be saved because it has been deleted externally.";
                         log.debug(msg);
                         throw new StaleItemStateException(msg);
                     }
 
                 case ItemState.STATUS_UNDEFINED:
                     {
-                        String msg = hierMgr.safeGetJCRPath(state.getId()) + ": the item cannot be saved; it seems to have been removed externally.";
+                        String msg = LogUtil.safeGetJCRPath(state, nsResolver, getHierarchyManager()) + ": the item cannot be saved; it seems to have been removed externally.";
                         log.debug(msg);
                         throw new StaleItemStateException(msg);
                     }
@@ -884,8 +883,8 @@
                     NodeId id = (NodeId) depIt.next();
                     if (!affectedIds.contains(id)) {
                         // need to save the parent as well
-                        String msg = hierMgr.safeGetJCRPath(id)
-                            + " needs to be saved as well.";
+                        // TODO convert id to human-readable id
+                        String msg = id.toString() + " needs to be saved as well.";
                         log.debug(msg);
                         throw new ItemStateException(msg);
                     }
@@ -902,7 +901,7 @@
         int options = ItemStateValidator.CHECK_LOCK | ItemStateValidator.CHECK_COLLISION
             | ItemStateValidator.CHECK_VERSIONING | ItemStateValidator.CHECK_CONSTRAINTS;
 
-        NodeState parent = validator.getNodeState(operation.getParentId());
+        NodeState parent = getNodeState(operation.getParentId());
         QNodeDefinition def = validator.getApplicableNodeDefinition(operation.getNodeName(), operation.getNodeTypeName(), parent);
         addNodeState(parent, operation.getNodeName(), operation.getNodeTypeName(), operation.getUuid(), def, options);
 
@@ -913,7 +912,7 @@
      * @inheritDoc
      */
     public void visit(AddProperty operation) throws ValueFormatException, LockException, ConstraintViolationException, AccessDeniedException, ItemExistsException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
-        NodeState parent = validator.getNodeState(operation.getParentId());
+        NodeState parent = getNodeState(operation.getParentId());
         QName propertyName = operation.getPropertyName();
         QPropertyDefinition pDef = validator.getApplicablePropertyDefinition(propertyName, operation.getPropertyType(), operation.isMultiValued(), parent);
         int targetType = pDef.getRequiredType();
@@ -952,10 +951,10 @@
     public void visit(Move operation) throws LockException, ConstraintViolationException, AccessDeniedException, ItemExistsException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
 
         // retrieve states and assert they are modifiable
-        NodeState srcState = create(validator.getNodeState(operation.getNodeId()));
-        NodeState srcParent = create(validator.getNodeState(operation.getSourceParentId()));
+        NodeState srcState = create(getNodeState(operation.getNodeId()));
+        NodeState srcParent = create(getNodeState(operation.getSourceParentId()));
 
-        NodeState destParent = create(validator.getNodeState(operation.getDestinationParentId()));
+        NodeState destParent = create(getNodeState(operation.getDestinationParentId()));
 
         // state validation: move-Source can be removed from old/added to new parent
         validator.checkRemoveItem(srcState,
@@ -1038,7 +1037,7 @@
         boolean anyRemoved;
 
         QName[] mixinNames = operation.getMixinNames();
-        NodeState nState = create(validator.getNodeState(operation.getNodeId()));
+        NodeState nState = create(getNodeState(operation.getNodeId()));
 
         // mixin-names to be execute on the nodestate (and corresponding property state)
         if (mixinNames != null && mixinNames.length > 0) {
@@ -1095,10 +1094,11 @@
         if (anyRemoved) {
             EffectiveNodeType ent = validator.getEffectiveNodeType(nState);
             // use temp set to avoid ConcurrentModificationException
-            Iterator childProps = new HashSet(nState.getPropertyNames()).iterator();
+            Iterator childProps = new HashSet(nState.getPropertyEntries()).iterator();
             while (childProps.hasNext()) {
                 try {
-                    PropertyState childState = nState.getPropertyState((QName) childProps.next());
+                    ChildPropertyEntry entry = (ChildPropertyEntry) childProps.next();
+                    PropertyState childState = entry.getPropertyState();
                     QName declNtName = childState.getDefinition().getDeclaringNodeType();
                     // check if property has been defined by mixin type (or one of its supertypes)
                     if (!ent.includesNodeType(declNtName)) {
@@ -1147,9 +1147,11 @@
             setPropertyStateValue(pState, operation.getValues(), operation.getPropertyType());
             transientStateMgr.addOperation(operation);
         } catch (NoSuchItemStateException nsise) {
-            throw new ItemNotFoundException(getHierarchyManager().safeGetJCRPath(operation.getPropertyId()));
+            // TODO convert id to human-readable id
+            throw new ItemNotFoundException(operation.getPropertyId().toString());
         } catch (ItemStateException ise) {
-            String msg = "internal error: failed to retrieve state of " + getHierarchyManager().safeGetJCRPath(operation.getPropertyId());
+            // TODO convert id to human-readable id
+            String msg = "internal error: failed to retrieve state of " + operation.getPropertyId().toString();
             log.debug(msg);
             throw new RepositoryException(msg, ise);
         }
@@ -1160,7 +1162,7 @@
      */
     public void visit(ReorderNodes operation) throws ConstraintViolationException, AccessDeniedException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
         // make sure the parent state is modifiable
-        NodeState parent = create(validator.getNodeState(operation.getParentId()));
+        NodeState parent = create(getNodeState(operation.getParentId()));
 
         NodeId srcId = operation.getInsertNodeId();
         NodeId beforeId = operation.getBeforeNodeId();
@@ -1467,11 +1469,11 @@
         }
 
         // remove properties
-        Iterator tmpIter = new HashSet(targetState.getPropertyNames()).iterator();
+        Iterator tmpIter = new HashSet(targetState.getPropertyEntries()).iterator();
         while (tmpIter.hasNext()) {
-            QName propName = (QName) tmpIter.next();
+            ChildPropertyEntry entry = (PropertyReference) tmpIter.next();
             try {
-                PropertyState child = targetState.getPropertyState(propName);
+                PropertyState child = entry.getPropertyState();
                 removePropertyState(targetState, child);
             } catch (ItemStateException e) {
                 // ignore
@@ -1652,7 +1654,7 @@
      * @return the computed values
      */
     private QValue[] computeSystemGeneratedPropertyValues(NodeState parent,
-                                                                 QPropertyDefinition def)
+                                                          QPropertyDefinition def)
         throws RepositoryException {
         QValue[] genValues = null;
         /**
@@ -1696,5 +1698,29 @@
             }
         }
         return genValues;
+    }
+
+
+    /**
+     * Retrieves the state of the item with the specified id using the given
+     * item state manager.
+     * <p/>
+     * Note that access rights are <b><i>not</i></b> enforced!
+     *
+     * @param id
+     * @return
+     * @throws ItemNotFoundException
+     * @throws RepositoryException
+     */
+    private NodeState getNodeState(NodeId id) throws ItemNotFoundException, RepositoryException {
+        try {
+            return (NodeState) getItemState(id);
+        } catch (NoSuchItemStateException e) {
+            throw new ItemNotFoundException(id.toString());
+        } catch (ItemStateException e) {
+            String msg = "internal error: failed to retrieve state of " + id.toString();
+            log.debug(msg);
+            throw new RepositoryException(msg, e);
+        }
     }
 }

Added: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/LogUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/LogUtil.java?rev=429652&view=auto
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/LogUtil.java (added)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/LogUtil.java Tue Aug  8 06:39:25 2006
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.jcr2spi.util;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.PathFormat;
+import org.apache.jackrabbit.name.NoPrefixDeclaredException;
+import org.apache.jackrabbit.name.NamespaceResolver;
+import org.apache.jackrabbit.jcr2spi.HierarchyManager;
+import org.apache.jackrabbit.jcr2spi.state.ItemState;
+import org.apache.jackrabbit.spi.ItemId;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * <code>LogUtil</code>...
+ */
+public class LogUtil {
+
+    private static Logger log = LoggerFactory.getLogger(LogUtil.class);
+
+    /**
+     * Failsafe conversion of internal <code>Path</code> to JCR path for use in
+     * error messages etc.
+     *
+     * @param qPath path to convert
+     * @param nsResolver
+     * @return JCR path
+     */
+    public static String safeGetJCRPath(Path qPath, NamespaceResolver nsResolver) {
+        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();
+        }
+    }
+
+    /**
+     * Failsafe conversion of an <code>ItemState</code> to JCR path for use in
+     * error messages etc.
+     *
+     * @param itemState
+     * @param nsResolver
+     * @param hierManager
+     * @return JCR path
+     */
+    public static String safeGetJCRPath(ItemState itemState, NamespaceResolver nsResolver,
+                                 HierarchyManager hierManager) {
+        try {
+            return safeGetJCRPath(hierManager.getQPath(itemState), nsResolver);
+        } catch (RepositoryException e) {
+            ItemId id = itemState.getId();
+            log.error("failed to convert " + id + " to JCR path.");
+            return id.toString();
+        }
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/LogUtil.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/util/LogUtil.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision url

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionHistoryImpl.java Tue Aug  8 06:39:25 2006
@@ -30,13 +30,13 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeState;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateException;
 import org.apache.jackrabbit.jcr2spi.state.ChildNodeEntry;
+import org.apache.jackrabbit.jcr2spi.state.PropertyState;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.NameException;
 import org.apache.jackrabbit.name.NoPrefixDeclaredException;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.name.Path;
 import org.apache.jackrabbit.name.NameFormat;
-import org.apache.jackrabbit.spi.PropertyId;
 
 import javax.jcr.version.VersionHistory;
 import javax.jcr.version.Version;
@@ -103,8 +103,12 @@
      * @see VersionHistory#getRootVersion()
      */
     public Version getRootVersion() throws RepositoryException {
-        NodeId vId = vhState.getChildNodeEntry(QName.JCR_ROOTVERSION, Path.INDEX_DEFAULT).getId();
-        return (Version) itemMgr.getItem(vId);
+        try {
+            NodeState vState = vhState.getChildNodeEntry(QName.JCR_ROOTVERSION, Path.INDEX_DEFAULT).getNodeState();
+            return (Version) itemMgr.getItem(vState);
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     /**
@@ -136,8 +140,8 @@
      * @see VersionHistory#getVersion(String)
      */
     public Version getVersion(String versionName) throws VersionException, RepositoryException {
-        NodeId vId = getVersionId(versionName);
-        return (Version) itemMgr.getItem(vId);
+        NodeState vState = getVersionState(versionName);
+        return (Version) itemMgr.getItem(vState);
     }
 
     /**
@@ -148,8 +152,12 @@
      * @see VersionHistory#getVersionByLabel(String)
      */
     public Version getVersionByLabel(String label) throws RepositoryException {
-        NodeId vId = getVersionIdByLabel(label);
-        return (Version) itemMgr.getItem(vId);
+        ChildNodeEntry vEntry = getVersionEntryByLabel(getQLabel(label));
+        try {
+            return (Version) itemMgr.getItem(vEntry.getNodeState());
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     /**
@@ -164,7 +172,8 @@
     public void addVersionLabel(String versionName, String label, boolean moveLabel) throws VersionException, RepositoryException {
         QName qLabel = getQLabel(label);
         // TODO: ev. delegate to versionmanager
-        Operation op = AddLabel.create(vhState.getNodeId(), getVersionId(versionName), qLabel, moveLabel);
+        ChildNodeEntry vEntry = getVersionEntry(versionName);
+        Operation op = AddLabel.create(vhState.getNodeId(), vEntry.getId(), qLabel, moveLabel);
         itemStateMgr.execute(op);
     }
 
@@ -178,7 +187,8 @@
     public void removeVersionLabel(String label) throws VersionException, RepositoryException {
         QName qLabel = getQLabel(label);
         // TODO: ev. delegate to versionmanager
-        Operation op = RemoveLabel.create(vhState.getNodeId(), getVersionIdByLabel(label), qLabel);
+        ChildNodeEntry vEntry = getVersionEntryByLabel(getQLabel(label));
+        Operation op = RemoveLabel.create(vhState.getNodeId(), vEntry.getId(), qLabel);
         itemStateMgr.execute(op);
     }
 
@@ -203,7 +213,7 @@
     /**
      *
      * @param version
-     * @param string
+     * @param label
      * @return
      * @throws VersionException
      * @throws RepositoryException
@@ -217,7 +227,7 @@
         QName[] qLabels = getQLabels();
         for (int i = 0; i < qLabels.length; i++) {
             if (qLabels[i].equals(l)) {
-                NodeId vId = getVersionIdByLabel(qLabels[i]);
+                NodeId vId = getVersionEntryByLabel(qLabels[i]).getId();
                 return vUUID.equals(vId.getUUID());
             }
         }
@@ -260,7 +270,7 @@
         List vlabels = new ArrayList();
         QName[] qLabels = getQLabels();
         for (int i = 0; i < qLabels.length; i++) {
-            NodeId vId = getVersionIdByLabel(qLabels[i]);
+            NodeId vId = getVersionEntryByLabel(qLabels[i]).getId();
             if (vUUID.equals(vId.getUUID())) {
                 try {
                     vlabels.add(NameFormat.format(qLabels[i], session.getNamespaceResolver()));
@@ -284,16 +294,10 @@
      * @see VersionHistory#removeVersion(String)
      */
     public void removeVersion(String versionName) throws ReferentialIntegrityException, AccessDeniedException, UnsupportedRepositoryOperationException, VersionException, RepositoryException {
-        try {
-            NodeId vId = getVersionId(versionName);
-            NodeState vState = (NodeState) itemStateMgr.getItemState(vId);
-
-            // TODO: ev. delegate to versionmanager
-            Operation rm = Remove.create(vState);
-            itemStateMgr.execute(rm);
-        } catch (ItemStateException e) {
-            throw new RepositoryException(e);
-        }
+        NodeState vState = getVersionState(versionName);
+        // TODO: ev. delegate to versionmanager
+        Operation rm = Remove.create(vState);
+        itemStateMgr.execute(rm);
     }
 
     //---------------------------------------------------------------< Item >---
@@ -330,14 +334,14 @@
      * @throws VersionException
      * @throws RepositoryException
      */
-    private NodeId getVersionId(String versionName) throws VersionException, RepositoryException {
+    private ChildNodeEntry getVersionEntry(String versionName) throws VersionException, RepositoryException {
         try {
             QName vQName = NameFormat.parse(versionName, session.getNamespaceResolver());
             ChildNodeEntry vEntry = vhState.getChildNodeEntry(vQName, Path.INDEX_DEFAULT);
             if (vEntry == null) {
                 throw new VersionException("Version '" + versionName + "' does not exist in this version history.");
             } else {
-                return vEntry.getId();
+                return vEntry;
             }
         } catch (NameException e) {
             throw new RepositoryException(e);
@@ -346,14 +350,17 @@
 
     /**
      *
-     * @param label
+     * @param versionName
      * @return
      * @throws VersionException
      * @throws RepositoryException
      */
-    private NodeId getVersionIdByLabel(String label) throws VersionException, RepositoryException {
-        QName qLabel = getQLabel(label);
-        return getVersionIdByLabel(qLabel);
+    private NodeState getVersionState(String versionName) throws VersionException, RepositoryException {
+        try {
+            return getVersionEntry(versionName).getNodeState();
+        } catch (ItemStateException e) {
+            throw new RepositoryException(e);
+        }
     }
 
     /**
@@ -363,13 +370,13 @@
      * @throws VersionException
      * @throws RepositoryException
      */
-    private NodeId getVersionIdByLabel(QName qLabel) throws VersionException, RepositoryException {
+    private ChildNodeEntry getVersionEntryByLabel(QName qLabel) throws VersionException, RepositoryException {
         if (labelNodeState.hasPropertyName(qLabel)) {
             // retrieve reference property value -> and convert it to a NodeId
             try {
-                PropertyId pId = labelNodeState.getPropertyState(qLabel).getPropertyId();
-                Node version = ((Property) itemMgr.getItem(pId)).getNode();
-                return (NodeId) session.getHierarchyManager().getItemId(version);
+                PropertyState pState = labelNodeState.getPropertyState(qLabel);
+                Node version = ((Property) itemMgr.getItem(pState)).getNode();
+                return getVersionEntry(version.getName());
             } catch (ItemStateException e) {
                 // should not occur. existance of property state has been checked
                 throw new RepositoryException(e);

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImporterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImporterImpl.java?rev=429652&r1=429651&r2=429652&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImporterImpl.java (original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/ImporterImpl.java Tue Aug  8 06:39:25 2006
@@ -23,10 +23,12 @@
 import org.apache.jackrabbit.jcr2spi.state.SessionItemStateManager;
 import org.apache.jackrabbit.jcr2spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateException;
+import org.apache.jackrabbit.jcr2spi.state.NoSuchItemStateException;
 import org.apache.jackrabbit.jcr2spi.SessionImpl;
 import org.apache.jackrabbit.jcr2spi.HierarchyManager;
 import org.apache.jackrabbit.jcr2spi.SessionListener;
 import org.apache.jackrabbit.jcr2spi.util.ReferenceChangeTracker;
+import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.jcr2spi.operation.AddNode;
 import org.apache.jackrabbit.jcr2spi.operation.Remove;
@@ -59,7 +61,6 @@
 import org.apache.jackrabbit.name.MalformedPathException;
 import org.apache.jackrabbit.spi.QPropertyDefinition;
 import org.apache.jackrabbit.spi.QNodeDefinition;
-import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.value.QValue;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.apache.jackrabbit.value.ValueFormat;
@@ -136,17 +137,17 @@
 
         // perform preliminary checks
         try {
-            ItemId id = hierMgr.getItemId(parentPath);
-            if (!id.denotesNode()) {
-                throw new PathNotFoundException(hierMgr.safeGetJCRPath(parentPath));
+            ItemState itemState = hierMgr.getItemState(parentPath);
+            if (!itemState.isNode()) {
+                throw new PathNotFoundException(LogUtil.safeGetJCRPath(parentPath, session.getNamespaceResolver()));
             }
-            importTarget = validator.getNodeState((NodeId) id);
+            importTarget = (NodeState) itemState;
 
             refTracker = new ReferenceChangeTracker();
             parents = new Stack();
             parents.push(importTarget);
         } catch (ItemNotFoundException infe) {
-            throw new PathNotFoundException(hierMgr.safeGetJCRPath(parentPath));
+            throw new PathNotFoundException(LogUtil.safeGetJCRPath(parentPath, session.getNamespaceResolver()));
         }
 
 
@@ -202,14 +203,14 @@
                    if (def.isProtected() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
                        // skip protected node
                        parents.push(null); // push null onto stack for skipped node
-                       log.debug("skipping protected node " + hierMgr.safeGetJCRPath(existing.getId()));
+                       log.debug("skipping protected node " + LogUtil.safeGetJCRPath(existing, session.getNamespaceResolver(), hierMgr));
                        return;
                    }
                    if (def.isAutoCreated() && entExisting.includesNodeType(nodeInfo.getNodeTypeName())) {
                        // this node has already been auto-created, no need to create it
                        nodeState = existing;
                    } else {
-                       throw new ItemExistsException(hierMgr.safeGetJCRPath(existing.getId()));
+                       throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getNamespaceResolver(), hierMgr));
                    }
                }
            }
@@ -222,11 +223,15 @@
                } else {
                    // potential uuid conflict
                    try {
-                       NodeState conflicting = validator.getNodeState(nodeInfo.getId());
+                       NodeState conflicting = (NodeState) stateMgr.getItemState(nodeInfo.getId());
                        nodeState = resolveUUIDConflict(parent, conflicting, nodeInfo);
-                   } catch (ItemNotFoundException infe) {
+                   } catch (NoSuchItemStateException e) {
                        // no conflict: create new with given uuid
                        nodeState = importNode(nodeInfo, parent);
+                   } catch (ItemStateException e) {
+                       String msg = "Internal error: failed to retrieve state of " + nodeInfo.getId().toString();
+                       log.debug(msg);
+                       throw new RepositoryException(msg, e);
                    }
                }
            }
@@ -356,8 +361,8 @@
 
             case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING:
                 // make sure conflicting node is not importTarget or an ancestor thereof
-                Path p0 = hierMgr.getQPath(importTarget.getId());
-                Path p1 = hierMgr.getQPath(conflicting.getId());
+                Path p0 = hierMgr.getQPath(importTarget);
+                Path p1 = hierMgr.getQPath(conflicting);
                 try {
                     if (p1.equals(p0) || p1.isAncestorOf(p0)) {
                         msg = "cannot remove ancestor node";
@@ -512,7 +517,7 @@
                 def = existing.getDefinition();
                 if (def.isProtected()) {
                     // skip protected property
-                    log.debug("skipping protected property " + hierMgr.safeGetJCRPath(existing.getPropertyId()));
+                    log.debug("skipping protected property " + LogUtil.safeGetJCRPath(existing, session.getNamespaceResolver(), hierMgr));
                     return;
                 }
                 if (def.isAutoCreated()
@@ -521,7 +526,7 @@
                     // this property has already been auto-created, no need to create it
                     propState = existing;
                 } else {
-                    throw new ItemExistsException(hierMgr.safeGetJCRPath(existing.getPropertyId()));
+                    throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getNamespaceResolver(), hierMgr));
                 }
             } catch (ItemStateException e) {
                 // should not occur. existance has been checked before



Mime
View raw message