Search in sources :

Example 1 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class LockManagerImpl method getLockHoldingState.

// ------------------------------------------------------------< private >---
/**
 * Search nearest ancestor that is locked. Returns <code>null</code> if neither
 * the given state nor any of its ancestors is locked.
 * Note, that this methods does NOT check if the given node state would
 * be affected by the lock present on an ancestor state.
 * Note, that in certain cases it might not be possible to detect a lock
 * being present due to the fact that the hierarchy might be incomplete or
 * not even readable completely. For this reason it seem equally reasonable
 * to search for jcr:lockIsDeep property only and omitting all kind of
 * verification regarding nodetypes present.
 *
 * @param nodeState <code>NodeState</code> from which searching starts.
 * Note, that the given state must not have an overlaid state.
 * @return a state holding a lock or <code>null</code> if neither the
 * given state nor any of its ancestors is locked.
 */
private NodeState getLockHoldingState(NodeState nodeState) {
    NodeEntry entry = nodeState.getNodeEntry();
    while (!entry.hasPropertyEntry(NameConstants.JCR_LOCKISDEEP)) {
        NodeEntry parent = entry.getParent();
        if (parent == null) {
            // reached root state without finding a locked node
            return null;
        }
        entry = parent;
    }
    try {
        return entry.getNodeState();
    } catch (RepositoryException e) {
        // may occur if the nodeState is not accessible or some generic
        // error occurred.
        // for this case, assume that no lock exists and delegate final
        // validation to the spi-implementation.
        log.warn("Error while accessing lock holding NodeState: {}", e.getMessage());
        return null;
    }
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) RepositoryException(javax.jcr.RepositoryException)

Example 2 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class LockManagerImpl method buildLockState.

private LockState buildLockState(NodeState nodeState) throws RepositoryException {
    NodeId nId = nodeState.getNodeId();
    NodeState lockHoldingState;
    LockInfo lockInfo = wspManager.getLockInfo(nId);
    if (lockInfo == null) {
        // no lock present
        return null;
    }
    NodeId lockNodeId = lockInfo.getNodeId();
    if (lockNodeId.equals(nId)) {
        lockHoldingState = nodeState;
    } else {
        NodeEntry lockedEntry = wspManager.getHierarchyManager().getNodeEntry(lockNodeId);
        try {
            lockHoldingState = lockedEntry.getNodeState();
        } catch (RepositoryException e) {
            log.warn("Cannot build LockState");
            throw new RepositoryException("Cannot build LockState", e);
        }
    }
    if (lockHoldingState == null) {
        return null;
    } else {
        return new LockState(lockHoldingState, lockInfo);
    }
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) NodeId(org.apache.jackrabbit.spi.NodeId) LockInfo(org.apache.jackrabbit.spi.LockInfo) RepositoryException(javax.jcr.RepositoryException)

Example 3 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class SessionImpl method getNodeById.

/**
 * Retrieve the <code>Node</code> with the given id.
 *
 * @param id
 * @return node with the given <code>NodeId</code>.
 * @throws ItemNotFoundException if no such node exists or if this
 * <code>Session</code> does not have permission to access the node.
 * @throws RepositoryException
 */
private Node getNodeById(NodeId id) throws ItemNotFoundException, RepositoryException {
    // check sanity of this session
    checkIsAlive();
    try {
        NodeEntry nodeEntry = getHierarchyManager().getNodeEntry(id);
        Item item = getItemManager().getItem(nodeEntry);
        if (item.isNode()) {
            return (Node) item;
        } else {
            log.error("NodeId '" + id + " does not point to a Node");
            throw new ItemNotFoundException(LogUtil.saveGetIdString(id, getPathResolver()));
        }
    } catch (AccessDeniedException e) {
        throw new ItemNotFoundException(LogUtil.saveGetIdString(id, getPathResolver()));
    }
}
Also used : Item(javax.jcr.Item) AccessDeniedException(javax.jcr.AccessDeniedException) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) Node(javax.jcr.Node) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 4 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class NodeState method reorderChildNodeEntries.

/**
 * Reorders the child node <code>insertNode</code> before the child node
 * <code>beforeNode</code>.
 *
 * @param insertNode the child node to reorder.
 * @param beforeNode the child node where to insert the node before. If
 * <code>null</code> the child node <code>insertNode</code> is moved to the
 * end of the child node entries.
 * @throws ItemNotFoundException if <code>insertNode</code> or
 * <code>beforeNode</code> is not a child node of this <code>NodeState</code>.
 */
synchronized void reorderChildNodeEntries(NodeState insertNode, NodeState beforeNode) throws ItemNotFoundException, RepositoryException {
    NodeEntry before = (beforeNode == null) ? null : beforeNode.getNodeEntry();
    insertNode.getNodeEntry().orderBefore(before);
    // mark this state as modified
    markModified();
}
Also used : NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)

Example 5 with NodeEntry

use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.

the class SessionItemStateManager method visit.

/**
 * @see OperationVisitor#visit(SetPrimaryType)
 */
public void visit(SetPrimaryType operation) throws ConstraintViolationException, RepositoryException {
    // NOTE: nodestate is only modified upon save of the changes!
    Name primaryName = operation.getPrimaryTypeName();
    NodeState nState = operation.getNodeState();
    NodeEntry nEntry = nState.getNodeEntry();
    // detect obvious node type conflicts
    EffectiveNodeTypeProvider entProvider = mgrProvider.getEffectiveNodeTypeProvider();
    // try to build new effective node type (will throw in case of conflicts)
    Name[] mixins = nState.getMixinTypeNames();
    List<Name> all = new ArrayList<Name>(Arrays.asList(mixins));
    all.add(primaryName);
    // retrieve effective to assert validity of arguments
    entProvider.getEffectiveNodeType(all.toArray(new Name[all.size()]));
    // modify the value of the jcr:primaryType property entry without
    // changing the node state itself
    PropertyEntry pEntry = nEntry.getPropertyEntry(NameConstants.JCR_PRIMARYTYPE);
    PropertyState pState = pEntry.getPropertyState();
    setPropertyStateValue(pState, getQValues(new Name[] { primaryName }, qValueFactory), PropertyType.NAME, operation.getOptions());
    // mark the affected node state modified and remember the operation
    nState.markModified();
    transientStateMgr.addOperation(operation);
}
Also used : EffectiveNodeTypeProvider(org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) PropertyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry) ArrayList(java.util.ArrayList) Name(org.apache.jackrabbit.spi.Name)

Aggregations

NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)40 RepositoryException (javax.jcr.RepositoryException)13 PropertyEntry (org.apache.jackrabbit.jcr2spi.hierarchy.PropertyEntry)10 ItemNotFoundException (javax.jcr.ItemNotFoundException)9 Name (org.apache.jackrabbit.spi.Name)9 Node (javax.jcr.Node)6 ItemExistsException (javax.jcr.ItemExistsException)5 NodeState (org.apache.jackrabbit.jcr2spi.state.NodeState)4 ArrayList (java.util.ArrayList)3 Version (javax.jcr.version.Version)3 NodeId (org.apache.jackrabbit.spi.NodeId)3 Path (org.apache.jackrabbit.spi.Path)3 PathNotFoundException (javax.jcr.PathNotFoundException)2 EffectiveNodeTypeProvider (org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeTypeProvider)2 PropertyState (org.apache.jackrabbit.jcr2spi.state.PropertyState)2 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)2 QValue (org.apache.jackrabbit.spi.QValue)2 NameException (org.apache.jackrabbit.spi.commons.conversion.NameException)2 AccessDeniedException (javax.jcr.AccessDeniedException)1 Item (javax.jcr.Item)1