jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r429269 - in /jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi: ./ state/ version/ xml/
Date Mon, 07 Aug 2006 08:11:36 GMT
Author: angela
Date: Mon Aug  7 01:11:35 2006
New Revision: 429269

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

- remove NodeState.getPropertyId and replace by getPropertyState
- use ChildNodeEntry.getNodeState
- consequently remove utility methods getNodeState, getPropertyState on
  ItemStateValidator, that converted ItemStateExceptions to RepositoryExc.

Modified:
    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/ItemManagerImpl.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/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/PathResolver.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/version/VersionManagerImpl.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/HierarchyManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/HierarchyManagerImpl.java?rev=429269&r1=429268&r2=429269&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
Mon Aug  7 01:11:35 2006
@@ -218,7 +218,7 @@
                 // property is not the last element in the path
                 throw new PathNotFoundException(safeGetJCRPath(path));
             }
-            childId = parentState.getPropertyId(name);
+            childId = parentState.getPropertyState(name).getId();
         } else {
             // no such item
             throw new PathNotFoundException(safeGetJCRPath(path));

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=429269&r1=429268&r2=429269&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
Mon Aug  7 01:11:35 2006
@@ -344,7 +344,7 @@
     /**
      * @inheritDoc
      */
-    public synchronized ItemImpl getItem(org.apache.jackrabbit.name.Path path)
+    public synchronized ItemImpl getItem(Path path)
             throws PathNotFoundException, AccessDeniedException, RepositoryException {
         ItemId id = hierMgr.getItemId(path);
         try {
@@ -455,11 +455,15 @@
 
         while (iter.hasNext()) {
             QName propName = (QName) iter.next();
-
-            PropertyId id = nodeState.getPropertyId(propName);
-            // check read access
-            if (session.getAccessManager().canRead(id)) {
-                return true;
+            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);
             }
         }
 
@@ -486,10 +490,15 @@
 
         while (iter.hasNext()) {
             QName propName = (QName) iter.next();
-            PropertyId id = nodeState.getPropertyId(propName);
-            // check read access
-            if (session.getAccessManager().canRead(id)) {
-                childIds.add(id);
+            try {
+                PropertyId id = nodeState.getPropertyState(propName).getPropertyId();
+                // check read access
+                if (session.getAccessManager().canRead(id)) {
+                    childIds.add(id);
+                }
+            } catch (ItemStateException e) {
+                // should not occur.
+                throw new RepositoryException(e);
             }
         }
 

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=429269&r1=429268&r2=429269&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
Mon Aug  7 01:11:35 2006
@@ -35,6 +35,8 @@
 import org.apache.jackrabbit.jcr2spi.state.NodeReferences;
 import org.apache.jackrabbit.jcr2spi.state.ItemStateValidator;
 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.nodetype.NodeTypeManagerImpl;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
 import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
@@ -1275,7 +1277,7 @@
         Operation an = AddNode.create(getNodeState(), nodeName, nodeTypeName, null);
         itemStateMgr.execute(an);
 
-        // retrieve id of state that has been created during execution of AddNode       

+        // retrieve id of state that has been created during execution of AddNode
         NodeId childId;
         List cne = getNodeState().getChildNodeEntries(nodeName);
         if (definition.allowsSameNameSiblings()) {
@@ -1298,11 +1300,16 @@
     // TODO: protected due to usage within VersionImpl, VersionHistoryImpl (check for alternatives)
     protected Property getProperty(QName qName) throws PathNotFoundException, RepositoryException
{
         checkStatus();
-        PropertyId propId = getNodeState().getPropertyId(qName);
         try {
-            return (Property) itemMgr.getItem(propId);
+            PropertyState pState = getNodeState().getPropertyState(qName);
+            return (Property) itemMgr.getItem(pState.getId());
         } catch (AccessDeniedException ade) {
             throw new ItemNotFoundException(qName.toString());
+        } catch (NoSuchItemStateException e) {
+            throw new PathNotFoundException(qName.toString());
+        } catch (ItemStateException e) {
+            String msg = "Error while accessing property " + qName.toString();
+            throw new RepositoryException(msg, e);
         }
     }
 
@@ -1560,7 +1567,12 @@
                 QName propName = NameFormat.parse(relPath, session.getNamespaceResolver());
                 // check if property entry exists
                 if (getNodeState().hasPropertyName(propName)) {
-                    return getNodeState().getPropertyId(propName);
+                    try {
+                        return getNodeState().getPropertyState(propName).getPropertyId();
+                    } catch (ItemStateException e) {
+                        // should not occur due, since existance has been checked
+                        throw new RepositoryException(e);
+                    }
                 } else {
                     // there's no property with that name
                     return null;

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=429269&r1=429268&r2=429269&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
Mon Aug  7 01:11:35 2006
@@ -468,9 +468,9 @@
 
         // access restriction on prop.
         if ((options & CHECK_ACCESS) == CHECK_ACCESS) {
-            PropertyId pId = parentState.getPropertyId(propertyName);
             // make sure current session is granted write access on new prop
-            if (!mgrProvider.getAccessManager().isGranted(pId, new String[] {AccessManager.SET_PROPERTY_ACTION}))
{
+            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);
             }
         }
@@ -739,7 +739,13 @@
         }
         // check for name collisions with existing properties
         if (parentState.hasPropertyName(propertyName)) {
-            PropertyId errorId = parentState.getPropertyId(propertyName);
+            PropertyId errorId = null;
+            try {
+                errorId = parentState.getPropertyState(propertyName).getPropertyId();
+            } catch (ItemStateException e) {
+                // should not occur. existance has been asserted before
+                throw new RepositoryException(e);
+            }
             throw new ItemExistsException(safeGetJCRPath(errorId));
         }
     }
@@ -762,18 +768,22 @@
 
         } else if (parentState.hasChildNodeEntry(nodeName)) {
             // retrieve the existing node state that ev. conflicts with the new one.
-            ChildNodeEntry entry = parentState.getChildNodeEntry(nodeName, 1);
-            NodeState conflictingState = getNodeState(entry.getId());
-
-            QNodeDefinition conflictDef = conflictingState.getDefinition();
-            QNodeDefinition newDef = getApplicableNodeDefinition(nodeName, nodeTypeName,
parentState);
-
-            // check same-name sibling setting of both target and existing node
-            if (!(conflictDef.allowsSameNameSiblings() && newDef.allowsSameNameSiblings()))
{
-                throw new ItemExistsException("Cannot add child node '"
-                    + nodeName.getLocalName() + "' to "
-                    + safeGetJCRPath(parentState.getNodeId())
-                    + ": colliding with same-named existing node.");
+            try {
+                ChildNodeEntry entry = parentState.getChildNodeEntry(nodeName, 1);
+                NodeState conflictingState = entry.getNodeState();
+                QNodeDefinition conflictDef = conflictingState.getDefinition();
+                QNodeDefinition newDef = getApplicableNodeDefinition(nodeName, nodeTypeName,
parentState);
+
+                // check same-name sibling setting of both target and existing node
+                if (!(conflictDef.allowsSameNameSiblings() && newDef.allowsSameNameSiblings()))
{
+                    throw new ItemExistsException("Cannot add child node '"
+                        + nodeName.getLocalName() + "' to "
+                        + safeGetJCRPath(parentState.getNodeId())
+                        + ": colliding with same-named existing node.");
+                }
+            } catch (ItemStateException e) {
+                // should not occur, since existence has been asserted before
+                throw new RepositoryException(e);
             }
         }
     }
@@ -826,28 +836,6 @@
     }
 
     /**
-     * Retrieves the state of the node at the given path.
-     * <p/>
-     * Note that access rights are <b><i>not</i></b> enforced!
-     *
-     * @param nodePath
-     * @return
-     * @throws PathNotFoundException
-     * @throws RepositoryException
-     */
-    public NodeState getNodeState(Path nodePath) throws PathNotFoundException, RepositoryException
{
-        try {
-            ItemId id = mgrProvider.getHierarchyManager().getItemId(nodePath);
-            if (!id.denotesNode()) {
-                throw new PathNotFoundException(safeGetJCRPath(nodePath));
-            }
-            return getNodeState((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/>
@@ -861,23 +849,6 @@
     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);
-        }
-    }
-
-    public PropertyState getPropertyState(NodeId parentId, QName propertyName) throws ItemNotFoundException,
RepositoryException {
-        NodeState nState = getNodeState(parentId);
-        return getPropertyState(nState.getPropertyId(propertyName));
-    }
-
-    public PropertyState getPropertyState(PropertyId id) throws ItemNotFoundException, RepositoryException
{
-        try {
-            return (PropertyState) mgrProvider.getItemStateManager().getItemState(id);
         } catch (NoSuchItemStateException nsise) {
             throw new ItemNotFoundException(safeGetJCRPath(id));
         } catch (ItemStateException 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=429269&r1=429268&r2=429269&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
Mon Aug  7 01:11:35 2006
@@ -26,7 +26,6 @@
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.spi.NodeId;
 import org.apache.jackrabbit.spi.ItemId;
-import org.apache.jackrabbit.spi.PropertyId;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
 
@@ -359,21 +358,6 @@
     }
 
     /**
-     * Return the id of the Property with the specified name or <code>null</code>
-     * if no property exists with the given name.
-     * 
-     * @param propName
-     * @return
-     */
-    public synchronized PropertyId getPropertyId(QName propName) {
-        if (hasPropertyName(propName)) {
-            return idFactory.createPropertyId(id, propName);
-        } else {
-            return null;
-        }
-    }
-
-    /**
      * Returns the <code>ChildNodeEntry</code> with the specified name and index
      * or <code>null</code> if there's no matching entry.
      *
@@ -459,8 +443,7 @@
         }
         ChildNodeEntry oldEntry = childNodeEntries.remove(oldName, index);
         if (oldEntry != null) {
-            ChildNodeEntry newEntry =
-                    childNodeEntries.add(newName, oldEntry.getId());
+            ChildNodeEntry newEntry = childNodeEntries.add(newName, oldEntry.getId());
             notifyNodeAdded(newEntry);
             notifyNodeRemoved(oldEntry);
             return true;

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathResolver.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathResolver.java?rev=429269&r1=429268&r2=429269&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathResolver.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/PathResolver.java
Mon Aug  7 01:11:35 2006
@@ -145,8 +145,7 @@
             Path.PathElement elem = relPath.getElement(i);
             // first try to resolve node
             if (state.hasChildNodeEntry(elem.getName(), elem.getNormalizedIndex())) {
-                ChildNodeEntry cne = state.getChildNodeEntry(elem.getName(),
-                        elem.getNormalizedIndex());
+                ChildNodeEntry cne = state.getChildNodeEntry(elem.getName(), elem.getNormalizedIndex());
                 if (cne.isAvailable()) {
                     state = cne.getNodeState();
                 } else {

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=429269&r1=429268&r2=429269&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
Mon Aug  7 01:11:35 2006
@@ -1052,8 +1052,13 @@
             // update/create corresponding property state
             if (nState.hasPropertyName(QName.JCR_MIXINTYPES)) {
                 // execute value of existing property
-                PropertyState pState = validator.getPropertyState(nState.getNodeId(), QName.JCR_MIXINTYPES);
-                setPropertyStateValue(pState, QValue.create(mixinNames), PropertyType.NAME);
+                try {
+                    PropertyState pState = nState.getPropertyState(QName.JCR_MIXINTYPES);
+                    setPropertyStateValue(pState, QValue.create(mixinNames), PropertyType.NAME);
+                } catch (ItemStateException e) {
+                    // should not occur, since existance has been asserted before
+                    throw new RepositoryException(e);
+                }
             } else {
                 // create new jcr:mixinTypes property
                 EffectiveNodeType ent = validator.getEffectiveNodeType(nState);
@@ -1069,9 +1074,14 @@
 
             // remove the jcr:mixinTypes property state if already present
             if (nState.hasPropertyName(QName.JCR_MIXINTYPES)) {
-                PropertyState pState = validator.getPropertyState(nState.getNodeId(), QName.JCR_MIXINTYPES);
-                int options = 0; // no checks required
-                removeItemState(pState, options);
+                try {
+                    PropertyState pState = nState.getPropertyState(QName.JCR_MIXINTYPES);
+                    int options = 0; // no checks required
+                    removeItemState(pState, options);
+                } catch (ItemStateException e) {
+                    // should not occur, since existance has been asserted before
+                    throw new RepositoryException(e);
+                }
             } else {
                 // alternative: make sure changes on nodeState are reflected in state manager.
                 store(nState);
@@ -1086,30 +1096,40 @@
             // use temp set to avoid ConcurrentModificationException
             Iterator childProps = new HashSet(nState.getPropertyNames()).iterator();
             while (childProps.hasNext()) {
-                PropertyState childState = validator.getPropertyState(nState.getNodeId(),
(QName) childProps.next());
-                QName declNtName = childState.getDefinition().getDeclaringNodeType();
-                // check if property has been defined by mixin type (or one of its supertypes)
-                if (!ent.includesNodeType(declNtName)) {
-                    // the remaining effective node type doesn't include the
-                    // node type that declared this property, it is thus safe
-                    // to remove it
-                    int options = 0; // no checks required
-                    removeItemState(childState, options);
+                try {
+                    PropertyState childState = nState.getPropertyState((QName) childProps.next());
+                    QName declNtName = childState.getDefinition().getDeclaringNodeType();
+                    // check if property has been defined by mixin type (or one of its supertypes)
+                    if (!ent.includesNodeType(declNtName)) {
+                        // the remaining effective node type doesn't include the
+                        // node type that declared this property, it is thus safe
+                        // to remove it
+                        int options = 0; // no checks required
+                        removeItemState(childState, options);
+                    }
+                } catch (ItemStateException e) {
+                    // ignore. cleanup will occure upon save anyway
+                    log.error("Error while removing child node defined by removed mixin:
{0}", e.getMessage());
                 }
             }
             // use temp array to avoid ConcurrentModificationException
             Iterator childNodes = new ArrayList(nState.getChildNodeEntries()).iterator();
             while (childNodes.hasNext()) {
-                ChildNodeEntry entry = (ChildNodeEntry) childNodes.next();
-                NodeState childState = validator.getNodeState(entry.getId());
-                // check if node has been defined by mixin type (or one of its supertypes)
-                QName declNtName = childState.getDefinition().getDeclaringNodeType();
-                if (!ent.includesNodeType(declNtName)) {
-                    // the remaining effective node type doesn't include the
-                    // node type that declared this child node, it is thus safe
-                    // to remove it.
-                    int options = 0; // NOTE: referencial intergrity checked upon save.
-                    removeItemState(childState, options);
+                try {
+                    ChildNodeEntry entry = (ChildNodeEntry) childNodes.next();
+                    NodeState childState = entry.getNodeState();
+                    // check if node has been defined by mixin type (or one of its supertypes)
+                    QName declNtName = childState.getDefinition().getDeclaringNodeType();
+                    if (!ent.includesNodeType(declNtName)) {
+                        // the remaining effective node type doesn't include the
+                        // node type that declared this child node, it is thus safe
+                        // to remove it.
+                        int options = 0; // NOTE: referencial intergrity checked upon save.
+                        removeItemState(childState, options);
+                    }
+                } catch (ItemStateException e) {
+                    // ignore. cleanup will occure upon save anyway
+                    log.error("Error while removing child property defined by removed mixin:
{0}", e.getMessage());
                 }
             }
         }
@@ -1121,9 +1141,17 @@
      * @inheritDoc
      */
     public void visit(SetPropertyValue operation) throws ValueFormatException, LockException,
ConstraintViolationException, AccessDeniedException, ItemExistsException, UnsupportedRepositoryOperationException,
VersionException, RepositoryException {
-        PropertyState pState = validator.getPropertyState(operation.getPropertyId());
-        setPropertyStateValue(pState, operation.getValues(), operation.getPropertyType());
-        transientStateMgr.addOperation(operation);
+        try {
+            PropertyState pState = (PropertyState) getItemState(operation.getPropertyId());
+            setPropertyStateValue(pState, operation.getValues(), operation.getPropertyType());
+            transientStateMgr.addOperation(operation);
+        } catch (NoSuchItemStateException nsise) {
+            throw new ItemNotFoundException(getHierarchyManager().safeGetJCRPath(operation.getPropertyId()));
+        } catch (ItemStateException ise) {
+            String msg = "internal error: failed to retrieve state of " + getHierarchyManager().safeGetJCRPath(operation.getPropertyId());
+            log.debug(msg);
+            throw new RepositoryException(msg, ise);
+        }
     }
 
     /**
@@ -1425,12 +1453,12 @@
             while (tmpIter.hasNext()) {
                 ChildNodeEntry entry = (ChildNodeEntry) tmpIter.next();
                 try {
-                    NodeState child = validator.getNodeState(entry.getId());
+                    NodeState child = entry.getNodeState();
                     // remove child node
                     // DIFF JR: don't recheck permission for child states
                     // DIFF JR: jr first calls recursive-method then removes c-n-entry
                     removeNodeState(targetState, child);
-                } catch (ItemNotFoundException e) {
+                } catch (ItemStateException e) {
                     // ignore
                     // TODO: check if correct
                 }
@@ -1442,9 +1470,9 @@
         while (tmpIter.hasNext()) {
             QName propName = (QName) tmpIter.next();
             try {
-                PropertyState child = validator.getPropertyState(targetState.getNodeId(),
propName);
+                PropertyState child = targetState.getPropertyState(propName);
                 removePropertyState(targetState, child);
-            } catch (ItemNotFoundException e) {
+            } catch (ItemStateException e) {
                 // ignore
                 // TODO: check if correct
             }

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=429269&r1=429268&r2=429269&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
Mon Aug  7 01:11:35 2006
@@ -76,7 +76,7 @@
         if (vhState.hasChildNodeEntry(QName.JCR_VERSIONLABELS)) {
             ChildNodeEntry lnEntry = vhState.getChildNodeEntry(QName.JCR_VERSIONLABELS, Path.INDEX_DEFAULT);
             try {
-                labelNodeState = (NodeState) itemStateMgr.getItemState(lnEntry.getId());
+                labelNodeState = lnEntry.getNodeState();
             } catch (ItemStateException e) {
                 throw new VersionException("nt:versionHistory requires a mandatory, autocreated
child node jcr:versionLabels.");
             }
@@ -366,9 +366,14 @@
     private NodeId getVersionIdByLabel(QName qLabel) throws VersionException, RepositoryException
{
         if (labelNodeState.hasPropertyName(qLabel)) {
             // retrieve reference property value -> and convert it to a NodeId
-            PropertyId pId = labelNodeState.getPropertyId(qLabel);
-            Node version = ((Property) itemMgr.getItem(pId)).getNode();
-            return (NodeId) session.getHierarchyManager().getItemId(version);
+            try {
+                PropertyId pId = labelNodeState.getPropertyState(qLabel).getPropertyId();
+                Node version = ((Property) itemMgr.getItem(pId)).getNode();
+                return (NodeId) session.getHierarchyManager().getItemId(version);
+            } catch (ItemStateException e) {
+                // should not occur. existance of property state has been checked
+                throw new RepositoryException(e);
+            }
         } else {
             throw new VersionException("Version with label '" + qLabel + "' does not exist.");
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java?rev=429269&r1=429268&r2=429269&view=diff
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/version/VersionManagerImpl.java
Mon Aug  7 01:11:35 2006
@@ -80,7 +80,7 @@
                 }
                 nodeState = (NodeState) stateManager.getItemState(nodeState.getParentId());
             }
-            PropertyId propId = nodeState.getPropertyId(QName.JCR_ISCHECKEDOUT);
+            PropertyId propId = nodeState.getPropertyState(QName.JCR_ISCHECKEDOUT).getPropertyId();
             PropertyState propState = (PropertyState) stateManager.getItemState(propId);
 
             Boolean b = Boolean.valueOf(propState.getValue().getString());

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=429269&r1=429268&r2=429269&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
Mon Aug  7 01:11:35 2006
@@ -22,6 +22,7 @@
 import org.apache.jackrabbit.jcr2spi.state.ItemState;
 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.SessionImpl;
 import org.apache.jackrabbit.jcr2spi.HierarchyManager;
 import org.apache.jackrabbit.jcr2spi.SessionListener;
@@ -58,6 +59,7 @@
 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;
@@ -129,17 +131,28 @@
         this.hierMgr = hierManager;
         this.stateMgr = stateManager;
         this.idFactory = idFactory;
+        this.uuidBehavior = uuidBehavior;
+        this.isWspImport = isWspImport;
 
         // perform preliminary checks
-        importTarget = validator.getNodeState(parentPath);
+        try {
+            ItemId id = hierMgr.getItemId(parentPath);
+            if (!id.denotesNode()) {
+                throw new PathNotFoundException(hierMgr.safeGetJCRPath(parentPath));
+            }
+            importTarget = validator.getNodeState((NodeId) id);
+
+            refTracker = new ReferenceChangeTracker();
+            parents = new Stack();
+            parents.push(importTarget);
+        } catch (ItemNotFoundException infe) {
+            throw new PathNotFoundException(hierMgr.safeGetJCRPath(parentPath));
+        }
+
+
         // DIFF JR: remove check for overall writability on target-node.
 
-        this.uuidBehavior = uuidBehavior;
-        this.isWspImport = isWspImport;
 
-        refTracker = new ReferenceChangeTracker();
-        parents = new Stack();
-        parents.push(importTarget);
     }
 
     //-----------------------------------------------------------< Importer >---
@@ -175,7 +188,13 @@
            if (parent.hasChildNodeEntry(nodeInfo.getName())) {
                // a node with that name already exists...
                ChildNodeEntry entry = parent.getChildNodeEntry(nodeInfo.getName(), 1);
-               NodeState existing = validator.getNodeState(entry.getId());
+               NodeState existing = null;
+               try {
+                   existing = entry.getNodeState();
+               } catch (ItemStateException e) {
+                   // should not occur. existance has been checked before
+                   throw new RepositoryException(e);
+               }
                QNodeDefinition def = existing.getDefinition();
                if (!def.allowsSameNameSiblings()) {
                    // existing doesn't allow same-name siblings, check for conflicts
@@ -408,36 +427,41 @@
              *
              * see http://issues.apache.org/jira/browse/JCR-61
              */
-            PropertyState conflicting = validator.getPropertyState(parent.getNodeId(), nodeInfo.getName());
-            if (conflicting.getStatus() == ItemState.STATUS_NEW) {
-                // assume this property has been imported as well;
-                // rename conflicting property
-                // @todo use better reversible escaping scheme to create unique name
-                QName newName = new QName(nodeInfo.getName().getNamespaceURI(), nodeInfo.getName().getLocalName()
+ "_");
-                if (parent.hasPropertyName(newName)) {
-                    newName = new QName(newName.getNamespaceURI(), newName.getLocalName()
+ "_");
-                }
-                // since name changes, need to find new applicable definition
-                QPropertyDefinition propDef;
-                if (conflicting.getValues().length == 1) {
-                    // could be single- or multi-valued (n == 1)
-                    try {
-                        // try single-valued
-                        propDef = validator.getApplicablePropertyDefinition(newName, conflicting.getType(),
false, parent);
-                    } catch (ConstraintViolationException cve) {
-                        // try multi-valued
+            try {
+                PropertyState conflicting = parent.getPropertyState(nodeInfo.getName());
+                if (conflicting.getStatus() == ItemState.STATUS_NEW) {
+                    // assume this property has been imported as well;
+                    // rename conflicting property
+                    // @todo use better reversible escaping scheme to create unique name
+                    QName newName = new QName(nodeInfo.getName().getNamespaceURI(), nodeInfo.getName().getLocalName()
+ "_");
+                    if (parent.hasPropertyName(newName)) {
+                        newName = new QName(newName.getNamespaceURI(), newName.getLocalName()
+ "_");
+                    }
+                    // since name changes, need to find new applicable definition
+                    QPropertyDefinition propDef;
+                    if (conflicting.getValues().length == 1) {
+                        // could be single- or multi-valued (n == 1)
+                        try {
+                            // try single-valued
+                            propDef = validator.getApplicablePropertyDefinition(newName,
conflicting.getType(), false, parent);
+                        } catch (ConstraintViolationException cve) {
+                            // try multi-valued
+                            propDef = validator.getApplicablePropertyDefinition(newName,
conflicting.getType(), true, parent);
+                        }
+                    } else {
+                        // can only be multi-valued (n == 0 || n > 1)
                         propDef = validator.getApplicablePropertyDefinition(newName, conflicting.getType(),
true, parent);
                     }
-                } else {
-                    // can only be multi-valued (n == 0 || n > 1)
-                    propDef = validator.getApplicablePropertyDefinition(newName, conflicting.getType(),
true, parent);
-                }
 
-                PropertyId newPId = idFactory.createPropertyId(parent.getNodeId(), newName);
-                Operation ap = AddProperty.create(newPId, conflicting.getType(), propDef,
conflicting.getValues());
-                stateMgr.execute(ap);
-                Operation rm = Remove.create(conflicting);
-                stateMgr.execute(rm);
+                    PropertyId newPId = idFactory.createPropertyId(parent.getNodeId(), newName);
+                    Operation ap = AddProperty.create(newPId, conflicting.getType(), propDef,
conflicting.getValues());
+                    stateMgr.execute(ap);
+                    Operation rm = Remove.create(conflicting);
+                    stateMgr.execute(rm);
+                }
+            } catch (ItemStateException e) {
+                // should not occur. existance has been checked before
+                throw new RepositoryException(e);
             }
         }
 
@@ -450,21 +474,25 @@
             Operation an = AddNode.create(parent, nodeInfo.getName(), nodeInfo.getNodeTypeName(),
nodeInfo.getId());
             stateMgr.execute(an);
             // retrieve id of state that has been created during execution of AddNode
-            NodeId childId;
-            List cne = parent.getChildNodeEntries(nodeInfo.getName());
-            if (def.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 = parent.getChildNodeEntries(nodeInfo.getName());
+                if (def.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, since nodestate is retrieved from cne-list
+                throw new RepositoryException(e);
             }
-            NodeState nodeState = validator.getNodeState(childId);
-            
+
             // and set mixin types
-            PropertyId mixinPId = idFactory.createPropertyId(childId, QName.JCR_MIXINTYPES);
+            PropertyId mixinPId = idFactory.createPropertyId(childState.getNodeId(), QName.JCR_MIXINTYPES);
             Operation sm = SetMixin.create(mixinPId, nodeInfo.getMixinNames());
             stateMgr.execute(sm);
-            return nodeState;
+            return childState;
         }
     }
 
@@ -481,25 +509,30 @@
         TextValue[] tva = pi.getValues();
         int infoType = pi.getType();
 
-        PropertyState prop = null;
+        PropertyState propState = null;
         QPropertyDefinition def;
 
         if (nodeState.hasPropertyName(propName)) {
             // a property with that name already exists...
-            PropertyState existing = validator.getPropertyState(nodeState.getNodeId(), propName);
-            def = existing.getDefinition();
-            if (def.isProtected()) {
-                // skip protected property
-                log.debug("skipping protected property " + hierMgr.safeGetJCRPath(existing.getPropertyId()));
-                return;
-            }
-            if (def.isAutoCreated()
-                && (existing.getType() == infoType || infoType == PropertyType.UNDEFINED)
-                && def.isMultiple() == existing.isMultiValued()) {
-                // this property has already been auto-created, no need to create it
-                prop = existing;
-            } else {
-                throw new ItemExistsException(hierMgr.safeGetJCRPath(existing.getPropertyId()));
+            try {
+                PropertyState existing = nodeState.getPropertyState(propName);
+                def = existing.getDefinition();
+                if (def.isProtected()) {
+                    // skip protected property
+                    log.debug("skipping protected property " + hierMgr.safeGetJCRPath(existing.getPropertyId()));
+                    return;
+                }
+                if (def.isAutoCreated()
+                    && (existing.getType() == infoType || infoType == PropertyType.UNDEFINED)
+                    && def.isMultiple() == existing.isMultiValued()) {
+                    // this property has already been auto-created, no need to create it
+                    propState = existing;
+                } else {
+                    throw new ItemExistsException(hierMgr.safeGetJCRPath(existing.getPropertyId()));
+                }
+            } catch (ItemStateException e) {
+                // should not occur. existance has been checked before
+                throw new RepositoryException(e);
             }
         } else {
             // there's no property with that name, find applicable definition
@@ -530,21 +563,26 @@
         }
 
         QValue[] values = getPropertyValues(pi, targetType, def.isMultiple(), nsResolver);
-        if (prop == null) {
+        if (propState == null) {
             // create new property
             PropertyId newPId = idFactory.createPropertyId(nodeState.getNodeId(), propName);
             Operation ap = AddProperty.create(newPId, targetType, def, values);
             stateMgr.execute(ap);
-            prop = validator.getPropertyState(nodeState.getNodeId(), propName);
+            try {
+                propState = nodeState.getPropertyState(propName);
+            } catch (ItemStateException e) {
+                // should not occur since prop-state has been created before
+                throw new RepositoryException(e);
+            }
         } else {
             // modify value of existing property
-            Operation sp = SetPropertyValue.create(prop, values, targetType);
+            Operation sp = SetPropertyValue.create(propState, values, targetType);
             stateMgr.execute(sp);
         }
 
         // store reference for later resolution
-        if (prop != null && prop.getType() == PropertyType.REFERENCE) {
-            refTracker.processedReference(prop);
+        if (propState != null && propState.getType() == PropertyType.REFERENCE) {
+            refTracker.processedReference(propState);
         }
     }
 



Mime
View raw message