Search in sources :

Example 6 with ItemState

use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.

the class HierarchyManagerImpl method getRelativeDepth.

/**
 * {@inheritDoc}
 */
public int getRelativeDepth(NodeId ancestorId, ItemId descendantId) throws ItemNotFoundException, RepositoryException {
    if (ancestorId.equals(descendantId)) {
        return 0;
    }
    int depth = 1;
    try {
        ItemState state = getItemState(descendantId);
        NodeId parentId = getParentId(state);
        while (parentId != null) {
            if (parentId.equals(ancestorId)) {
                return depth;
            }
            depth++;
            state = getItemState(parentId);
            parentId = getParentId(state);
        }
        // not an ancestor
        return -1;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 7 with ItemState

use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.

the class HierarchyManagerImpl method isShareAncestor.

/**
 * {@inheritDoc}
 */
public boolean isShareAncestor(NodeId ancestor, NodeId descendant) throws ItemNotFoundException, RepositoryException {
    if (ancestor.equals(descendant)) {
        // can't be ancestor of self
        return false;
    }
    try {
        ItemState state = getItemState(descendant);
        Set<NodeId> parentIds = getParentIds(state, false);
        while (parentIds.size() > 0) {
            if (parentIds.contains(ancestor)) {
                return true;
            }
            Set<NodeId> grandparentIds = new LinkedHashSet<NodeId>();
            for (NodeId parentId : parentIds) {
                grandparentIds.addAll(getParentIds(getItemState(parentId), false));
            }
            parentIds = grandparentIds;
        }
        // not an ancestor
        return false;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 8 with ItemState

use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.

the class HierarchyManagerImpl method getDepth.

/**
 * {@inheritDoc}
 */
public int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException {
    // shortcut
    if (id.equals(rootNodeId)) {
        return 0;
    }
    try {
        ItemState state = getItemState(id);
        NodeId parentId = getParentId(state);
        int depth = 0;
        while (parentId != null) {
            depth++;
            state = getItemState(parentId);
            parentId = getParentId(state);
        }
        return depth;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine depth of " + id;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine depth of " + id;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 9 with ItemState

use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.

the class HierarchyManagerImpl method isAncestor.

/**
 * {@inheritDoc}
 */
public boolean isAncestor(NodeId nodeId, ItemId itemId) throws ItemNotFoundException, RepositoryException {
    if (nodeId.equals(itemId)) {
        // can't be ancestor of self
        return false;
    }
    try {
        ItemState state = getItemState(itemId);
        NodeId parentId = getParentId(state);
        while (parentId != null) {
            if (parentId.equals(nodeId)) {
                return true;
            }
            state = getItemState(parentId);
            parentId = getParentId(state);
        }
        // not an ancestor
        return false;
    } catch (NoSuchItemStateException nsise) {
        String msg = "failed to determine degree of relationship of " + nodeId + " and " + itemId;
        log.debug(msg);
        throw new ItemNotFoundException(msg, nsise);
    } catch (ItemStateException ise) {
        String msg = "failed to determine degree of relationship of " + nodeId + " and " + itemId;
        log.debug(msg);
        throw new RepositoryException(msg, ise);
    }
}
Also used : NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) ItemState(org.apache.jackrabbit.core.state.ItemState) NodeId(org.apache.jackrabbit.core.id.NodeId) RepositoryException(javax.jcr.RepositoryException) ItemNotFoundException(javax.jcr.ItemNotFoundException) NoSuchItemStateException(org.apache.jackrabbit.core.state.NoSuchItemStateException) InvalidItemStateException(javax.jcr.InvalidItemStateException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException)

Example 10 with ItemState

use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.

the class ItemImpl method setRemoved.

/**
 * Marks this instance as 'removed' and notifies its listeners.
 * The resulting state is either 'temporarily invalidated' or
 * 'permanently invalidated', depending on the initial state.
 *
 * @throws RepositoryException if an error occurs
 */
protected void setRemoved() throws RepositoryException {
    final int status = data.getStatus();
    if (status == STATUS_INVALIDATED || status == STATUS_DESTROYED) {
        // this instance is already 'invalid', get outta here
        return;
    }
    ItemState transientState = getOrCreateTransientItemState();
    if (transientState.getStatus() == ItemState.STATUS_NEW) {
        // this is a 'new' item, simply dispose the transient state
        // (it is no longer used); this will indirectly (through
        // stateDiscarded listener method) invalidate this instance permanently
        stateMgr.disposeTransientItemState(transientState);
    } else {
        // this is an 'existing' item (i.e. it is backed by persistent
        // state), mark it as 'removed'
        transientState.setStatus(ItemState.STATUS_EXISTING_REMOVED);
        // transfer the transient state to the attic
        stateMgr.moveTransientItemStateToAttic(transientState);
        // set state of this instance to 'invalid'
        data.setStatus(STATUS_INVALIDATED);
        // notify the manager that this instance has been
        // temporarily invalidated
        itemMgr.itemInvalidated(id, data);
    }
}
Also used : ItemState(org.apache.jackrabbit.core.state.ItemState)

Aggregations

ItemState (org.apache.jackrabbit.core.state.ItemState)26 RepositoryException (javax.jcr.RepositoryException)15 NodeId (org.apache.jackrabbit.core.id.NodeId)12 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)12 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)11 InvalidItemStateException (javax.jcr.InvalidItemStateException)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)8 NodeState (org.apache.jackrabbit.core.state.NodeState)7 ItemId (org.apache.jackrabbit.core.id.ItemId)5 SessionItemStateManager (org.apache.jackrabbit.core.state.SessionItemStateManager)5 HashSet (java.util.HashSet)4 EffectiveNodeType (org.apache.jackrabbit.core.nodetype.EffectiveNodeType)4 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)3 PropertyId (org.apache.jackrabbit.core.id.PropertyId)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashSet (java.util.LinkedHashSet)2 AccessDeniedException (javax.jcr.AccessDeniedException)2 NodeTypeImpl (org.apache.jackrabbit.core.nodetype.NodeTypeImpl)2