use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class HierarchyManagerImpl method getName.
/**
* {@inheritDoc}
*/
public Name getName(NodeId id, NodeId parentId) throws ItemNotFoundException, RepositoryException {
NodeState parentState;
try {
parentState = (NodeState) getItemState(parentId);
} catch (NoSuchItemStateException nsis) {
String msg = "failed to resolve name of " + id;
log.debug(msg);
throw new ItemNotFoundException(id.toString());
} catch (ItemStateException ise) {
String msg = "failed to resolve name of " + id;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
ChildNodeEntry entry = getChildNodeEntry(parentState, id);
if (entry == null) {
String msg = "failed to resolve name of " + id;
log.debug(msg);
throw new ItemNotFoundException(msg);
}
return entry.getName();
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class HierarchyManagerImpl method getName.
/**
* {@inheritDoc}
*/
public Name getName(ItemId itemId) throws ItemNotFoundException, RepositoryException {
if (itemId.denotesNode()) {
NodeId nodeId = (NodeId) itemId;
try {
NodeState nodeState = (NodeState) getItemState(nodeId);
NodeId parentId = getParentId(nodeState);
if (parentId == null) {
// FIXME
return EMPTY_NAME;
}
return getName(nodeId, parentId);
} catch (NoSuchItemStateException nsis) {
String msg = "failed to resolve name of " + nodeId;
log.debug(msg);
throw new ItemNotFoundException(nodeId.toString());
} catch (ItemStateException ise) {
String msg = "failed to resolve name of " + nodeId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
} else {
return ((PropertyId) itemId).getName();
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ItemSaveOperation method restoreTransientItems.
/**
* walk through list of transient states and re-apply transient changes
*/
private void restoreTransientItems(SessionContext context, Iterable<ItemState> items) {
ItemManager itemMgr = context.getItemManager();
SessionItemStateManager stateMgr = context.getItemStateManager();
for (ItemState itemState : items) {
ItemId id = itemState.getId();
ItemImpl item;
try {
if (stateMgr.isItemStateInAttic(id)) {
// If an item has been removed and then again created, the
// item is lost after persistTransientItems() and the
// TransientItemStateManager will bark because of a deleted
// state in its attic. We therefore have to forge a new item
// instance ourself.
item = itemMgr.createItemInstance(itemState);
itemState.setStatus(ItemState.STATUS_NEW);
} else {
try {
item = itemMgr.getItem(id, false);
} catch (ItemNotFoundException infe) {
// itemState probably represents a 'new' item and the
// ItemImpl instance wrapping it has already been gc'ed;
// we have to re-create the ItemImpl instance
item = itemMgr.createItemInstance(itemState);
itemState.setStatus(ItemState.STATUS_NEW);
}
}
// for persistent nodes undo effect of item.makePersistent()
if (item.isNode()) {
NodeImpl node = (NodeImpl) item;
node.restoreTransient((NodeState) itemState);
} else {
PropertyImpl prop = (PropertyImpl) item;
prop.restoreTransient((PropertyState) itemState);
}
} catch (RepositoryException re) {
// something went wrong, log exception and carry on
String msg = itemMgr.safeGetJCRPath(id) + ": failed to restore transient state";
if (log.isDebugEnabled()) {
log.warn(msg, re);
} else {
log.warn(msg);
}
}
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class ItemManager method getDefinition.
NodeDefinitionImpl getDefinition(NodeState state) throws RepositoryException {
if (state.getId().equals(sessionContext.getRootNodeId())) {
// special handling required for root node
return rootNodeDef;
}
NodeId parentId = state.getParentId();
if (parentId == null) {
// removed state has parentId set to null
// get from overlayed state
ItemState overlaid = state.getOverlayedState();
if (overlaid != null) {
parentId = overlaid.getParentId();
} else {
throw new InvalidItemStateException("Could not find parent of node " + state.getNodeId());
}
}
NodeState parentState = null;
try {
// access the parent state circumventing permission check, since
// read permission on the parent isn't required in order to retrieve
// a node's definition. see also JCR-2418
ItemData parentData = getItemData(parentId, null, false);
parentState = (NodeState) parentData.getState();
if (state.getParentId() == null) {
// that used to be the actual parent
if (parentState.getStatus() == ItemState.STATUS_NEW) {
// force getting parent from attic
parentState = null;
} else {
parentState = (NodeState) parentState.getOverlayedState();
}
}
} catch (ItemNotFoundException e) {
// parent probably removed, get it from attic. see below
}
if (parentState == null) {
try {
// use overlayed state if available
parentState = (NodeState) sism.getAttic().getItemState(parentId).getOverlayedState();
} catch (ItemStateException ex) {
throw new RepositoryException(ex);
}
}
// get child node entry
ChildNodeEntry cne = parentState.getChildNodeEntry(state.getNodeId());
if (cne == null) {
throw new InvalidItemStateException("Could not find child " + state.getNodeId() + " of node " + parentState.getNodeId());
}
NodeTypeRegistry ntReg = sessionContext.getNodeTypeRegistry();
try {
EffectiveNodeType ent = ntReg.getEffectiveNodeType(parentState.getNodeTypeName(), parentState.getMixinTypeNames());
QNodeDefinition def;
try {
def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
} catch (ConstraintViolationException e) {
// fallback to child node definition of a nt:unstructured
ent = ntReg.getEffectiveNodeType(NameConstants.NT_UNSTRUCTURED);
def = ent.getApplicableChildNodeDef(cne.getName(), state.getNodeTypeName(), ntReg);
log.warn("Fallback to nt:unstructured due to unknown child " + "node definition for type '" + state.getNodeTypeName() + "'");
}
return sessionContext.getNodeTypeManager().getNodeDefinition(def);
} catch (NodeTypeConflictException e) {
throw new RepositoryException(e);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class CachingHierarchyManager method nodeRemoved.
/**
* {@inheritDoc}
*/
public void nodeRemoved(NodeState state, Name name, int index, NodeId id) {
synchronized (cacheMonitor) {
if (idCache.containsKey(state.getNodeId())) {
// Optimization: ignore notifications for nodes that are not in the cache
try {
Path path = PathFactoryImpl.getInstance().create(getPath(state.getNodeId()), name, index, true);
nodeRemoved(state, path, id);
checkConsistency();
} catch (PathNotFoundException e) {
log.warn("Unable to get path of node " + state.getNodeId() + ", event ignored.");
} catch (MalformedPathException e) {
log.warn("Unable to create path of " + id, e);
} catch (ItemStateException e) {
log.warn("Unable to find item " + id, e);
} catch (ItemNotFoundException e) {
log.warn("Unable to get path of " + state.getNodeId(), e);
} catch (RepositoryException e) {
log.warn("Unable to get path of " + state.getNodeId(), e);
}
} else if (state.getParentId() == null && idCache.containsKey(id)) {
// A top level node was removed
evictAll(id, true);
}
}
}
Aggregations