Search in sources :

Example 6 with PathNotFoundException

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

the class NodeEntryImpl method getDeepPropertyEntry.

/**
     * @see NodeEntry#getDeepPropertyEntry(Path)
     */
public PropertyEntry getDeepPropertyEntry(Path path) throws PathNotFoundException, RepositoryException {
    NodeEntryImpl entry = this;
    Path.Element[] elems = path.getElements();
    int i = 0;
    for (; i < elems.length - 1; i++) {
        Path.Element elem = elems[i];
        if (elems[i].denotesRoot()) {
            if (entry.getParent() != null) {
                throw new RepositoryException("NodeEntry out of 'hierarchy' " + path.toString());
            }
            continue;
        }
        int index = elem.getNormalizedIndex();
        Name name = elem.getName();
        // first try to resolve to known node or property entry
        NodeEntry cne = entry.getNodeEntry(name, index, false);
        if (cne != null) {
            entry = (NodeEntryImpl) cne;
        } else {
            //    on the persistent layer.
            if (entry.childNodeEntries.isComplete()) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // -> check for moved child entry in node-attic
            // -> check if child points to a removed/moved sns
            List<NodeEntry> siblings = entry.childNodeEntries.get(name);
            if (entry.containsAtticChild(siblings, name, index)) {
                throw new PathNotFoundException(factory.saveGetJCRPath(path));
            }
            // break out of the loop and start deep loading the property
            break;
        }
    }
    int st = entry.getStatus();
    PropertyEntry pe;
    if (i == elems.length - 1 && Status.INVALIDATED != st && Status._UNDEFINED_ != st) {
        // all node entries present in the hierarchy and the direct ancestor
        // has already been resolved and isn't invalidated -> no need to
        // retrieve property entry from SPI
        pe = entry.properties.get(path.getName());
    } else {
        /*
            * Unknown parent entry (not-existing or not yet loaded) or a parent
            * entry that has been invalidated:
            * Skip all intermediate entries and directly try to load the
            * PropertyState (including building the intermediate entries. If that
            * fails ItemNotFoundException is thrown.
            */
        PathBuilder pb = new PathBuilder(getPathFactory());
        for (int j = i; j < elems.length; j++) {
            pb.addLast(elems[j]);
        }
        Path remainingPath = pb.getPath();
        IdFactory idFactory = getIdFactory();
        NodeId parentId = entry.getWorkspaceId();
        if (remainingPath.getLength() != 1) {
            parentId = idFactory.createNodeId(parentId, remainingPath.getAncestor(1));
        }
        PropertyId propId = idFactory.createPropertyId(parentId, remainingPath.getName());
        pe = entry.loadPropertyEntry(propId);
    }
    if (pe == null) {
        throw new PathNotFoundException(factory.saveGetJCRPath(path));
    }
    return pe;
}
Also used : Path(org.apache.jackrabbit.spi.Path) RepositoryException(javax.jcr.RepositoryException) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId) PathBuilder(org.apache.jackrabbit.spi.commons.name.PathBuilder) IdFactory(org.apache.jackrabbit.spi.IdFactory) NodeId(org.apache.jackrabbit.spi.NodeId) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 7 with PathNotFoundException

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

the class CachingHierarchyManagerConsistencyTest method testObservation.

public void testObservation() throws Exception {
    final List<Exception> exceptions = new ArrayList<Exception>();
    Thread writer = new Thread(new Runnable() {

        public void run() {
            try {
                long end = System.currentTimeMillis() + TEST_DURATION * 1000;
                Session s = getHelper().getSuperuserSession();
                try {
                    log.info("Starting to replace nodes");
                    int i = 0;
                    while (System.currentTimeMillis() < end) {
                        replaceNodes(s, i++);
                    }
                } finally {
                    s.logout();
                }
            } catch (RepositoryException e) {
                exceptions.add(e);
            }
        }
    });
    List<EventListener> listeners = new ArrayList<EventListener>();
    for (int i = 0; i < NUM_LISTENERS; i++) {
        final Session session = getHelper().getSuperuserSession();
        listeners.add(new EventListener() {

            public void onEvent(EventIterator events) {
                while (events.hasNext()) {
                    Event event = events.nextEvent();
                    String path = "n/a";
                    try {
                        if (event.getType() == Event.NODE_ADDED || event.getType() == Event.PROPERTY_ADDED) {
                            path = event.getPath();
                            session.getItem(path);
                        }
                    } catch (PathNotFoundException e) {
                    // ignore
                    } catch (RepositoryException e) {
                        log.error(e.toString() + " Unable to get item with path: " + path);
                        exceptions.add(e);
                    }
                }
            }
        });
    }
    for (EventListener listener : listeners) {
        superuser.getWorkspace().getObservationManager().addEventListener(listener, ALL_EVENTS, "/", true, null, null, false);
    }
    writer.start();
    writer.join();
    for (EventListener listener : listeners) {
        superuser.getWorkspace().getObservationManager().removeEventListener(listener);
    }
    log.info("" + exceptions.size() + " exception(s) occurred.");
    if (!exceptions.isEmpty()) {
        throw exceptions.get(0);
    }
}
Also used : ArrayList(java.util.ArrayList) RepositoryException(javax.jcr.RepositoryException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) Event(javax.jcr.observation.Event) EventListener(javax.jcr.observation.EventListener) PathNotFoundException(javax.jcr.PathNotFoundException) EventIterator(javax.jcr.observation.EventIterator) Session(javax.jcr.Session)

Example 8 with PathNotFoundException

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

the class NodeTest method testAddNodePathNotFoundException.

/**
     * Tries to add a node using {@link javax.jcr.Node#addNode(String)} to a non
     * existing destination node.
     * <p>
     * This should throw an {@link javax.jcr.PathNotFoundException}.
     */
public void testAddNodePathNotFoundException() throws RepositoryException {
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    try {
        // use invalid parent path
        defaultRootNode.addNode(nodeName1 + "/" + nodeName2);
        fail("Creating a node at a non existent destination should throw PathNotFoundException");
    } catch (PathNotFoundException e) {
    // ok, works as expected
    }
}
Also used : Node(javax.jcr.Node) PathNotFoundException(javax.jcr.PathNotFoundException)

Example 9 with PathNotFoundException

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

the class NodeReadMethodsTest method testGetProperty.

/**
     * Test if getProperty(String relPath) returns the correct node and if a
     * PathNotFoundException is thrown when property at relPath does not exist
     */
public void testGetProperty() throws NotExecutableException, RepositoryException {
    StringBuffer notExistingPath = new StringBuffer("X");
    PropertyIterator properties = testRootNode.getProperties();
    while (properties.hasNext()) {
        // build a path that for sure is not existing
        // (":" of namespace prefix will be replaced later on)
        notExistingPath.append(properties.nextProperty().getName());
    }
    try {
        testRootNode.getProperty(notExistingPath.toString().replaceAll(":", ""));
        fail("getProperty(String relPath) must throw a " + "PathNotFoundException if no node exists at relPath");
    } catch (PathNotFoundException e) {
    // success
    }
    try {
        PropertyIterator properties2 = testRootNode.getProperties();
        Property property = properties2.nextProperty();
        assertTrue("Property returned by getProperties() is not the same as returned by getProperty(String).", testRootNode.getProperty(property.getName()).isSame(property));
    } catch (NoSuchElementException e) {
        fail("Root node must always have at least one property: jcr:primaryType");
    }
}
Also used : PropertyIterator(javax.jcr.PropertyIterator) PathNotFoundException(javax.jcr.PathNotFoundException) Property(javax.jcr.Property) NoSuchElementException(java.util.NoSuchElementException)

Example 10 with PathNotFoundException

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

the class SessionImpl method getNode.

/**
     * @see Session#getNode(String)
     */
@Override
public Node getNode(String absPath) throws RepositoryException {
    checkIsAlive();
    try {
        Path qPath = getQPath(absPath).getNormalizedPath();
        ItemManager itemMgr = getItemManager();
        return itemMgr.getNode(qPath);
    } catch (AccessDeniedException ade) {
        throw new PathNotFoundException(absPath);
    }
}
Also used : Path(org.apache.jackrabbit.spi.Path) AccessDeniedException(javax.jcr.AccessDeniedException) PathNotFoundException(javax.jcr.PathNotFoundException)

Aggregations

PathNotFoundException (javax.jcr.PathNotFoundException)136 Node (javax.jcr.Node)58 RepositoryException (javax.jcr.RepositoryException)46 ItemNotFoundException (javax.jcr.ItemNotFoundException)24 Session (javax.jcr.Session)23 Path (org.apache.jackrabbit.spi.Path)22 AccessDeniedException (javax.jcr.AccessDeniedException)14 Property (javax.jcr.Property)14 Test (org.junit.Test)14 Item (javax.jcr.Item)11 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)10 NodeIterator (javax.jcr.NodeIterator)9 Value (javax.jcr.Value)9 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)9 Name (org.apache.jackrabbit.spi.Name)8 PropertyIterator (javax.jcr.PropertyIterator)7 NodeDelegate (org.apache.jackrabbit.oak.jcr.delegate.NodeDelegate)7 HashSet (java.util.HashSet)6 ItemExistsException (javax.jcr.ItemExistsException)6 ValueFormatException (javax.jcr.ValueFormatException)6