Search in sources :

Example 61 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class WorkspaceItemStateFactory method createNodeState.

/**
     * Creates the node with information retrieved from the <code>RepositoryService</code>.
     */
public NodeState createNodeState(NodeId nodeId, NodeEntry entry) throws ItemNotFoundException, RepositoryException {
    try {
        Entry<NodeInfo> cached = cache.getNodeInfo(nodeId);
        ItemInfo info;
        if (isUpToDate(cached, entry)) {
            info = cached.info;
        } else {
            // otherwise retrieve item info from service and cache the whole batch
            Iterator<? extends ItemInfo> infos = service.getItemInfos(sessionInfo, nodeId);
            info = first(infos, cache, entry.getGeneration());
            if (info == null || !info.denotesNode()) {
                throw new ItemNotFoundException("NodeId: " + nodeId);
            }
        }
        assertMatchingPath(info, entry);
        return createNodeState((NodeInfo) info, entry);
    } catch (PathNotFoundException e) {
        throw new ItemNotFoundException(e);
    }
}
Also used : ItemInfo(org.apache.jackrabbit.spi.ItemInfo) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) PathNotFoundException(javax.jcr.PathNotFoundException) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 62 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class WorkspaceItemStateFactory method createDeepNodeState.

/**
     * Creates the node with information retrieved from the <code>RepositoryService</code>.
     * Intermediate entries are created as needed.
     */
public NodeState createDeepNodeState(NodeId nodeId, NodeEntry anyParent) throws ItemNotFoundException, RepositoryException {
    try {
        // Get item info from cache
        Iterator<? extends ItemInfo> infos = null;
        Entry<NodeInfo> cached = cache.getNodeInfo(nodeId);
        ItemInfo info;
        if (cached == null) {
            // or from service if not in cache
            infos = service.getItemInfos(sessionInfo, nodeId);
            info = first(infos, null, 0);
            if (info == null || !info.denotesNode()) {
                throw new ItemNotFoundException("NodeId: " + nodeId);
            }
        } else {
            info = cached.info;
        }
        // Build the hierarchy entry for the item info
        HierarchyEntry entry = createHierarchyEntries(info, anyParent);
        if (entry == null || !entry.denotesNode()) {
            throw new ItemNotFoundException("HierarchyEntry does not belong to any existing ItemInfo. No ItemState was created.");
        } else {
            // Now we can check whether the item info from the cache is up to date
            long generation = entry.getGeneration();
            if (isOutdated(cached, entry)) {
                // if not, retrieve the item info from the service and put the whole batch into the cache
                infos = service.getItemInfos(sessionInfo, nodeId);
                info = first(infos, cache, generation);
            } else if (infos != null) {
                // Otherwise put the whole batch retrieved from the service earlier into the cache
                cache.put(info, generation);
                first(infos, cache, generation);
            }
            assertMatchingPath(info, entry);
            return createNodeState((NodeInfo) info, (NodeEntry) entry);
        }
    } catch (PathNotFoundException e) {
        throw new ItemNotFoundException(e);
    }
}
Also used : ItemInfo(org.apache.jackrabbit.spi.ItemInfo) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) PathNotFoundException(javax.jcr.PathNotFoundException) HierarchyEntry(org.apache.jackrabbit.jcr2spi.hierarchy.HierarchyEntry) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 63 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class ReadTest method testReadNonExistingNode2.

public void testReadNonExistingNode2() throws RepositoryException {
    NodeId nid = getNodeId(testPath + "/non-existing");
    try {
        rs.getNodeInfo(si, nid);
        fail();
    } catch (ItemNotFoundException e) {
    // ok
    }
}
Also used : NodeId(org.apache.jackrabbit.spi.NodeId) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 64 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class LockManagerImpl method getLock.

/**
     * {@inheritDoc}
     */
public Lock getLock(NodeImpl node) throws LockException, RepositoryException {
    acquire();
    try {
        SessionImpl session = (SessionImpl) node.getSession();
        Path path = getPath(session, node.getId());
        PathMap.Element<LockInfo> element = lockMap.map(path, false);
        LockInfo info = element.get();
        if (info != null && (element.hasPath(path) || info.isDeep())) {
            NodeImpl lockHolder = (NodeImpl) session.getItemManager().getItem(info.getId());
            return new LockImpl(info, lockHolder);
        } else {
            throw new LockException("Node not locked: " + node);
        }
    } catch (ItemNotFoundException e) {
        throw new LockException("Node not locked: " + node);
    } finally {
        release();
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) NodeImpl(org.apache.jackrabbit.core.NodeImpl) LockException(javax.jcr.lock.LockException) SessionImpl(org.apache.jackrabbit.core.SessionImpl) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Example 65 with ItemNotFoundException

use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.

the class LockManagerImpl method holdsLock.

/**
     * {@inheritDoc}
     */
public boolean holdsLock(NodeImpl node) throws RepositoryException {
    acquire();
    try {
        SessionImpl session = (SessionImpl) node.getSession();
        PathMap.Element<LockInfo> element = lockMap.map(getPath(session, node.getId()), true);
        if (element == null) {
            return false;
        }
        return element.get() != null;
    } catch (ItemNotFoundException e) {
        return false;
    } finally {
        release();
    }
}
Also used : SessionImpl(org.apache.jackrabbit.core.SessionImpl) PathMap(org.apache.jackrabbit.spi.commons.name.PathMap) ItemNotFoundException(javax.jcr.ItemNotFoundException)

Aggregations

ItemNotFoundException (javax.jcr.ItemNotFoundException)139 RepositoryException (javax.jcr.RepositoryException)61 Node (javax.jcr.Node)44 Path (org.apache.jackrabbit.spi.Path)25 PathNotFoundException (javax.jcr.PathNotFoundException)23 NodeId (org.apache.jackrabbit.core.id.NodeId)22 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)16 IOException (java.io.IOException)14 InvalidItemStateException (javax.jcr.InvalidItemStateException)14 NodeState (org.apache.jackrabbit.core.state.NodeState)14 Name (org.apache.jackrabbit.spi.Name)14 AccessDeniedException (javax.jcr.AccessDeniedException)13 HttpResponse (org.apache.http.HttpResponse)13 DavException (org.apache.jackrabbit.webdav.DavException)13 ItemExistsException (javax.jcr.ItemExistsException)12 Session (javax.jcr.Session)12 NoSuchItemStateException (org.apache.jackrabbit.core.state.NoSuchItemStateException)12 ChildNodeEntry (org.apache.jackrabbit.core.state.ChildNodeEntry)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 MultiStatusResponse (org.apache.jackrabbit.webdav.MultiStatusResponse)10