use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class AbstractImportXmlTest method createReferenceableNode.
/**
* Creates a node with given name below the testRootNode which will be
* referenced by the node nodeName2 and returns the UUID assigned to the
* created node.
*
* @param name
* @return
* @throws RepositoryException
* @throws NotExecutableException if the created node is not referenceable
* and cannot be made referenceable by adding mix:referenceable.
*/
public String createReferenceableNode(String name) throws RepositoryException, NotExecutableException {
// remove a yet existing node at the target
try {
Node node = testRootNode.getNode(name);
node.remove();
session.save();
} catch (PathNotFoundException pnfe) {
// ok
}
// a referenceable node
Node n1 = testRootNode.addNode(name, testNodeType);
if (!n1.isNodeType(mixReferenceable) && !n1.canAddMixin(mixReferenceable)) {
n1.remove();
session.save();
throw new NotExecutableException("node type " + testNodeType + " does not support mix:referenceable");
}
n1.addMixin(mixReferenceable);
// make sure jcr:uuid is available
testRootNode.getSession().save();
return n1.getUUID();
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class QueryImpl method storeAsNode.
/**
* @see Query#storeAsNode(String)
*/
public Node storeAsNode(String absPath) throws ItemExistsException, PathNotFoundException, VersionException, ConstraintViolationException, LockException, UnsupportedRepositoryOperationException, RepositoryException {
NamePathResolver resolver = mgrProvider.getNamePathResolver();
try {
Path p = resolver.getQPath(absPath).getNormalizedPath();
if (!p.isAbsolute()) {
throw new RepositoryException(absPath + " is not an absolute path");
}
String jcrParent = resolver.getJCRPath(p.getAncestor(1));
if (!session.itemExists(jcrParent)) {
throw new PathNotFoundException(jcrParent);
}
String relPath = resolver.getJCRPath(p).substring(1);
String ntName = resolver.getJCRName(NameConstants.NT_QUERY);
Node queryNode = session.getRootNode().addNode(relPath, ntName);
// set properties
queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_LANGUAGE), getLanguage());
queryNode.setProperty(resolver.getJCRName(NameConstants.JCR_STATEMENT), getStatement());
node = queryNode;
return node;
} catch (NameException e) {
throw new RepositoryException(e.getMessage(), e);
}
}
use of javax.jcr.PathNotFoundException in project jackrabbit by apache.
the class WorkspaceItemStateFactory method createPropertyState.
/**
* Creates the PropertyState with information retrieved from the <code>RepositoryService</code>.
*/
public PropertyState createPropertyState(PropertyId propertyId, PropertyEntry entry) throws ItemNotFoundException, RepositoryException {
try {
// Get item info from cache and use it if up to date
Entry<PropertyInfo> cached = cache.getPropertyInfo(propertyId);
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, propertyId);
info = first(infos, cache, entry.getGeneration());
if (info == null || info.denotesNode()) {
throw new ItemNotFoundException("PropertyId: " + propertyId);
}
}
assertMatchingPath(info, entry);
return createPropertyState((PropertyInfo) info, entry);
} catch (PathNotFoundException e) {
throw new ItemNotFoundException(e);
}
}
use of javax.jcr.PathNotFoundException 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);
}
}
use of javax.jcr.PathNotFoundException 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);
}
}
Aggregations