use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class HierarchyManagerImpl method isAncestor.
/**
* {@inheritDoc}
*/
public boolean isAncestor(NodeId nodeId, ItemId itemId) throws ItemNotFoundException, RepositoryException {
if (nodeId.equals(itemId)) {
// can't be ancestor of self
return false;
}
try {
ItemState state = getItemState(itemId);
NodeId parentId = getParentId(state);
while (parentId != null) {
if (parentId.equals(nodeId)) {
return true;
}
state = getItemState(parentId);
parentId = getParentId(state);
}
// not an ancestor
return false;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine degree of relationship of " + nodeId + " and " + itemId;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine degree of relationship of " + nodeId + " and " + itemId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class NodeImpl method getOrCreateProperty.
/**
* @param name
* @param type
* @param multiValued
* @param exactTypeMatch
* @param status
* @return
* @throws ConstraintViolationException if no applicable property definition
* could be found
* @throws RepositoryException if another error occurs
*/
protected synchronized PropertyImpl getOrCreateProperty(Name name, int type, boolean multiValued, boolean exactTypeMatch, BitSet status) throws ConstraintViolationException, RepositoryException {
status.clear();
if (isNew() && !hasProperty(name)) {
// this is a new node and the property does not exist yet
// -> no need to check item manager
PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
PropertyImpl prop = createChildProperty(name, type, def);
status.set(CREATED);
return prop;
}
/*
* Please note, that this implementation does not win a price for beauty
* or speed. It's never a good idea to use exceptions for semantical
* control flow.
* However, compared to the previous version, this one is thread save
* and makes the test/get block atomic in respect to transactional
* commits. the test/set can still fail.
*
* Old Version:
NodeState thisState = (NodeState) state;
if (thisState.hasPropertyName(name)) {
/**
* the following call will throw ItemNotFoundException if the
* current session doesn't have read access
/
return getProperty(name);
}
[...create block...]
*/
PropertyId propId = new PropertyId(getNodeId(), name);
try {
return (PropertyImpl) itemMgr.getItem(propId);
} catch (AccessDeniedException ade) {
throw new ItemNotFoundException(name.toString());
} catch (ItemNotFoundException e) {
// does not exist yet or has been removed transiently:
// find definition for the specified property and (re-)create property
PropertyDefinitionImpl def = getApplicablePropertyDefinition(name, type, multiValued, exactTypeMatch);
PropertyImpl prop;
if (stateMgr.hasTransientItemStateInAttic(propId)) {
// remove from attic
try {
stateMgr.disposeTransientItemStateInAttic(stateMgr.getAttic().getItemState(propId));
} catch (ItemStateException ise) {
// shouldn't happen because we checked if it is in the attic
throw new RepositoryException(ise);
}
prop = (PropertyImpl) itemMgr.getItem(propId);
PropertyState state = (PropertyState) prop.getOrCreateTransientItemState();
state.setMultiValued(multiValued);
state.setType(type);
getNodeState().addPropertyName(name);
} else {
prop = createChildProperty(name, type, def);
}
status.set(CREATED);
return prop;
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class NodeImpl method replaceChildNode.
/**
* Replaces the child node with the specified <code>id</code>
* by a new child node with the same id and specified <code>nodeName</code>,
* <code>nodeTypeName</code> and <code>mixinNames</code>.
*
* @param id id of the child node to be replaced
* @param nodeName name of the new node
* @param nodeTypeName name of the new node's node type
* @param mixinNames name of the new node's mixin types
*
* @return the new child node replacing the existing child
* @throws ItemNotFoundException
* @throws NoSuchNodeTypeException
* @throws VersionException
* @throws ConstraintViolationException
* @throws LockException
* @throws RepositoryException
*/
public synchronized NodeImpl replaceChildNode(NodeId id, Name nodeName, Name nodeTypeName, Name[] mixinNames) throws ItemNotFoundException, NoSuchNodeTypeException, VersionException, ConstraintViolationException, LockException, RepositoryException {
// check state of this instance
sanityCheck();
Node existing = (Node) itemMgr.getItem(id);
// 'replace' is actually a 'remove existing/add new' operation;
// this unfortunately changes the order of this node's
// child node entries (JCR-1055);
// => backup list of child node entries beforehand in order
// to restore it afterwards
NodeState state = data.getNodeState();
ChildNodeEntry cneExisting = state.getChildNodeEntry(id);
if (cneExisting == null) {
throw new ItemNotFoundException(this + ": no child node entry with id " + id);
}
List<ChildNodeEntry> cneList = new ArrayList<ChildNodeEntry>(state.getChildNodeEntries());
// remove existing
existing.remove();
// create new child node
NodeImpl node = addNode(nodeName, nodeTypeName, id);
if (mixinNames != null) {
for (Name mixinName : mixinNames) {
node.addMixin(mixinName);
}
}
// fetch <code>state</code> again, as it changed while removing child
state = data.getNodeState();
// restore list of child node entries (JCR-1055)
if (cneExisting.getName().equals(nodeName)) {
// restore original child node list
state.setChildNodeEntries(cneList);
} else {
// replace child node entry with different name
// but preserving original position
state.removeAllChildNodeEntries();
for (ChildNodeEntry cne : cneList) {
if (cne.getId().equals(id)) {
// replace entry with different name
state.addChildNodeEntry(nodeName, id);
} else {
state.addChildNodeEntry(cne.getName(), cne.getId());
}
}
}
return node;
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class NodeImpl method removeChildNode.
protected void removeChildNode(NodeId childId) throws RepositoryException {
// modify the state of 'this', i.e. the parent node
NodeState thisState = (NodeState) getOrCreateTransientItemState();
ChildNodeEntry entry = thisState.getChildNodeEntry(childId);
if (entry == null) {
String msg = "failed to remove child " + childId + " of " + this;
log.debug(msg);
throw new RepositoryException(msg);
}
// notify target of removal
try {
NodeImpl childNode = itemMgr.getNode(childId, getNodeId());
childNode.onRemove(getNodeId());
} catch (ItemNotFoundException e) {
boolean ignoreError = false;
if (sessionContext.getSessionImpl().autoFixCorruptions()) {
// it might be an access right problem
// we need to check if the item doesn't exist in the ism
ItemStateManager ism = sessionContext.getItemStateManager();
if (!ism.hasItemState(childId)) {
log.warn("Node " + childId + " not found, ignore", e);
ignoreError = true;
}
}
if (!ignoreError) {
throw e;
}
}
// remove the child node entry
if (!thisState.removeChildNodeEntry(childId)) {
String msg = "failed to remove child " + childId + " of " + this;
log.debug(msg);
throw new RepositoryException(msg);
}
}
use of javax.jcr.ItemNotFoundException in project jackrabbit by apache.
the class NodeImpl method getPrimaryItem.
/**
* {@inheritDoc}
*/
public Item getPrimaryItem() throws ItemNotFoundException, RepositoryException {
// check state of this instance
sanityCheck();
String name = getPrimaryNodeType().getPrimaryItemName();
if (name == null) {
throw new ItemNotFoundException();
}
if (hasProperty(name)) {
return getProperty(name);
} else if (hasNode(name)) {
return getNode(name);
} else {
throw new ItemNotFoundException();
}
}
Aggregations