Search in sources :

Example 1 with NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.

the class UniqueIdResolver method resolve.

public NodeEntry resolve(NodeId nodeId, NodeEntry rootEntry) throws ItemNotFoundException, RepositoryException {
    NodeEntry entry = lookup(nodeId.getUniqueID());
    if (entry == null) {
        NodeState state = isf.createDeepNodeState(nodeId, rootEntry);
        entry = state.getNodeEntry();
    }
    return entry;
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState)

Example 2 with NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState 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 NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.

the class NodeEntryImpl method addNewNodeEntry.

/**
     * @see NodeEntry#addNewNodeEntry(Name, String, Name, QNodeDefinition)
     */
public NodeEntry addNewNodeEntry(Name nodeName, String uniqueID, Name primaryNodeType, QNodeDefinition definition) throws RepositoryException {
    NodeEntry entry = internalAddNodeEntry(nodeName, uniqueID, Path.INDEX_UNDEFINED);
    NodeState state = getItemStateFactory().createNewNodeState(entry, primaryNodeType, definition);
    entry.setItemState(state);
    return entry;
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState)

Example 4 with NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.

the class Move method create.

//------------------------------------------------------------< Factory >---
public static Operation create(Path srcPath, Path destPath, HierarchyManager hierMgr, PathResolver resolver, boolean sessionMove) throws ItemExistsException, NoSuchNodeTypeException, RepositoryException {
    // src must not be ancestor of destination
    if (srcPath.isAncestorOf(destPath)) {
        String msg = "Invalid destination path: cannot be descendant of source path (" + LogUtil.safeGetJCRPath(destPath, resolver) + "," + LogUtil.safeGetJCRPath(srcPath, resolver) + ")";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    // destination must not contain an index
    int index = destPath.getIndex();
    if (index != Path.INDEX_UNDEFINED) {
        // subscript in name element
        String msg = "Invalid destination path: subscript in name element is not allowed (" + LogUtil.safeGetJCRPath(destPath, resolver) + ")";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    // root node cannot be moved:
    if (srcPath.denotesRoot() || destPath.denotesRoot()) {
        String msg = "Cannot move the root node.";
        log.debug(msg);
        throw new RepositoryException(msg);
    }
    NodeState srcState = getNodeState(srcPath, hierMgr);
    NodeState srcParentState = getNodeState(srcPath.getAncestor(1), hierMgr);
    NodeState destParentState = getNodeState(destPath.getAncestor(1), hierMgr);
    Name destName = destPath.getName();
    if (sessionMove) {
        NodeEntry destEntry = (NodeEntry) destParentState.getHierarchyEntry();
        // force child node entries list to be present before the move is executed
        // on the hierarchy entry.
        assertChildNodeEntries(srcParentState);
        assertChildNodeEntries(destParentState);
        if (destEntry.hasNodeEntry(destName)) {
            NodeEntry existing = destEntry.getNodeEntry(destName, Path.INDEX_DEFAULT);
            if (existing != null && sessionMove) {
                try {
                    if (!existing.getNodeState().getDefinition().allowsSameNameSiblings()) {
                        throw new ItemExistsException("Node existing at move destination does not allow same name siblings.");
                    }
                } catch (ItemNotFoundException e) {
                // existing apparent not valid any more -> probably no conflict
                }
            }
        }
    }
    Move move = new Move(srcState, srcParentState, destParentState, destName, sessionMove);
    return move;
}
Also used : NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) NodeEntry(org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry) ItemExistsException(javax.jcr.ItemExistsException) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 5 with NodeState

use of org.apache.jackrabbit.jcr2spi.state.NodeState in project jackrabbit by apache.

the class SessionImpl method getVersionState.

/**
     * Returns the NodeState of the given Node and asserts that the state is
     * listed in the hierarchy built by this Session. If the version
     * was obtained from a different session, the 'corresponding' version
     * state for this session is retrieved.
     *
     * @param version
     * @return the NodeState associated with the specified version.
     */
NodeState getVersionState(Version version) throws RepositoryException {
    NodeState nodeState;
    if (version.getSession() == this) {
        nodeState = (NodeState) ((NodeImpl) version).getItemState();
    } else {
        Path p = getQPath(version.getPath());
        Path parentPath = p.getAncestor(1);
        HierarchyEntry parentEntry = getHierarchyManager().lookup(parentPath);
        if (parentEntry != null) {
            // make sure the parent entry is up to date
            parentEntry.invalidate(false);
        }
        nodeState = getHierarchyManager().getNodeState(p);
    }
    return nodeState;
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeState(org.apache.jackrabbit.jcr2spi.state.NodeState) HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry)

Aggregations

NodeState (org.apache.jackrabbit.jcr2spi.state.NodeState)31 Name (org.apache.jackrabbit.spi.Name)8 ItemNotFoundException (javax.jcr.ItemNotFoundException)5 RepositoryException (javax.jcr.RepositoryException)5 PropertyState (org.apache.jackrabbit.jcr2spi.state.PropertyState)5 Path (org.apache.jackrabbit.spi.Path)5 NodeEntry (org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry)4 ItemExistsException (javax.jcr.ItemExistsException)3 Operation (org.apache.jackrabbit.jcr2spi.operation.Operation)3 NodeId (org.apache.jackrabbit.spi.NodeId)3 Item (javax.jcr.Item)2 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)2 AccessControlException (javax.jcr.security.AccessControlException)2 Privilege (javax.jcr.security.Privilege)2 Version (javax.jcr.version.Version)2 VersionException (javax.jcr.version.VersionException)2 AddNode (org.apache.jackrabbit.jcr2spi.operation.AddNode)2 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)2 QValue (org.apache.jackrabbit.spi.QValue)2 ArrayList (java.util.ArrayList)1