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;
}
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);
}
}
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
}
}
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");
}
}
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);
}
}
Aggregations