use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class NodeImpl method getNode.
/**
* @see Node#getNode(String)
*/
public Node getNode(String relPath) throws PathNotFoundException, RepositoryException {
checkStatus();
NodeEntry nodeEntry = resolveRelativeNodePath(relPath);
if (nodeEntry == null) {
throw new PathNotFoundException(relPath);
}
try {
return (Node) getItemManager().getItem(nodeEntry);
} catch (ItemNotFoundException e) {
throw new PathNotFoundException(relPath, e);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class HierarchyEntryImpl method reload.
/**
* {@inheritDoc}
* @see HierarchyEntry#reload(boolean)
*/
public void reload(boolean recursive) {
int status = getStatus();
if (status == Status._UNDEFINED_) {
// unresolved: entry will be loaded and validated upon resolution.
return;
}
if (Status.isTransient(status) || Status.isStale(status) || Status.isTerminal(status)) {
// transient || stale: avoid reloading
// new || terminal: cannot be reloaded from persistent layer anyway.
log.debug("Skip reload for item with status " + Status.getName(status) + ".");
return;
}
/**
* Retrieved a fresh ItemState from the persistent layer. Which will
* then be merged into the current state.
*/
try {
ItemStateFactory isf = getItemStateFactory();
if (denotesNode()) {
NodeEntry ne = (NodeEntry) this;
isf.createNodeState(ne.getWorkspaceId(), ne);
} else {
PropertyEntry pe = (PropertyEntry) this;
isf.createPropertyState(pe.getWorkspaceId(), pe);
}
} catch (ItemNotFoundException e) {
// remove hierarchyEntry including all children
log.debug("Item '" + getName() + "' cannot be found on the persistent layer -> remove.");
remove();
} catch (RepositoryException e) {
// TODO: rather throw?
log.error("Exception while reloading item: " + e);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class PropertyImpl method getNode.
/**
* @see Property#getNode()
*/
public Node getNode() throws ValueFormatException, RepositoryException {
Value value = getValue();
switch(value.getType()) {
case PropertyType.REFERENCE:
case PropertyType.WEAKREFERENCE:
return session.getNodeByIdentifier(value.getString());
case PropertyType.PATH:
case PropertyType.NAME:
String path = value.getString();
Path p = session.getPathResolver().getQPath(path);
try {
return (p.isAbsolute()) ? session.getNode(path) : getParent().getNode(path);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(path);
}
case PropertyType.STRING:
try {
Value refValue = ValueHelper.convert(value, PropertyType.REFERENCE, session.getValueFactory());
return session.getNodeByIdentifier(refValue.getString());
} catch (ItemNotFoundException e) {
throw e;
} catch (RepositoryException e) {
// try if STRING value can be interpreted as PATH value
Value pathValue = ValueHelper.convert(value, PropertyType.PATH, session.getValueFactory());
p = session.getPathResolver().getQPath(pathValue.getString());
try {
return (p.isAbsolute()) ? session.getNode(pathValue.getString()) : getParent().getNode(pathValue.getString());
} catch (PathNotFoundException e1) {
throw new ItemNotFoundException(pathValue.getString());
}
}
default:
throw new ValueFormatException("Property value cannot be converted to a PATH, REFERENCE or WEAKREFERENCE");
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class NodeImpl method getCorrespondingNodePath.
/**
* @see Node#getCorrespondingNodePath(String)
*/
public String getCorrespondingNodePath(String workspaceName) throws ItemNotFoundException, NoSuchWorkspaceException, AccessDeniedException, RepositoryException {
checkStatus();
SessionImpl srcSession = null;
try {
// create session on other workspace for current subject
// (may throw NoSuchWorkspaceException and AccessDeniedException)
srcSession = session.switchWorkspace(workspaceName);
// search nearest ancestor that is referenceable
NodeImpl referenceableNode = this;
while (referenceableNode.getDepth() != Path.ROOT_DEPTH && !referenceableNode.isNodeType(NameConstants.MIX_REFERENCEABLE)) {
referenceableNode = (NodeImpl) referenceableNode.getParent();
}
// if root is common ancestor, corresponding path is same as ours
// otherwise access referenceable ancestor and calculate correspond. path.
String correspondingPath;
if (referenceableNode.getDepth() == Path.ROOT_DEPTH) {
if (!srcSession.getItemManager().nodeExists(getQPath())) {
throw new ItemNotFoundException("No corresponding path found in workspace " + workspaceName + "(" + safeGetJCRPath() + ")");
} else {
correspondingPath = getPath();
}
} else {
// get corresponding ancestor
Node correspNode = srcSession.getNodeByUUID(referenceableNode.getUUID());
// path of m2 found, if m1 == n1
if (referenceableNode == this) {
correspondingPath = correspNode.getPath();
} else {
Path p = referenceableNode.getQPath().computeRelativePath(getQPath());
// use prefix mappings of srcSession
String relPath = session.getPathResolver().getJCRPath(p);
if (!correspNode.hasNode(relPath)) {
throw new ItemNotFoundException("No corresponding path found in workspace " + workspaceName + "(" + safeGetJCRPath() + ")");
} else {
correspondingPath = correspNode.getNode(relPath).getPath();
}
}
}
return correspondingPath;
} finally {
if (srcSession != null) {
// we don't need the other session anymore, logout
srcSession.logout();
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class NodeImpl method getPrimaryItem.
/**
* @see Node#getPrimaryItem()
*/
public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException {
checkStatus();
String name = getPrimaryNodeType().getPrimaryItemName();
if (name == null) {
throw new ItemNotFoundException("No primary item present on Node " + safeGetJCRPath());
}
if (hasProperty(name)) {
return getProperty(name);
} else if (hasNode(name)) {
return getNode(name);
} else {
throw new ItemNotFoundException("Primary item " + name + " does not exist on Node " + safeGetJCRPath());
}
}
Aggregations