use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.
the class HierarchyManagerImpl method getRelativeDepth.
/**
* {@inheritDoc}
*/
public int getRelativeDepth(NodeId ancestorId, ItemId descendantId) throws ItemNotFoundException, RepositoryException {
if (ancestorId.equals(descendantId)) {
return 0;
}
int depth = 1;
try {
ItemState state = getItemState(descendantId);
NodeId parentId = getParentId(state);
while (parentId != null) {
if (parentId.equals(ancestorId)) {
return depth;
}
depth++;
state = getItemState(parentId);
parentId = getParentId(state);
}
// not an ancestor
return -1;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine depth of " + descendantId + " relative to " + ancestorId;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.
the class HierarchyManagerImpl method isShareAncestor.
/**
* {@inheritDoc}
*/
public boolean isShareAncestor(NodeId ancestor, NodeId descendant) throws ItemNotFoundException, RepositoryException {
if (ancestor.equals(descendant)) {
// can't be ancestor of self
return false;
}
try {
ItemState state = getItemState(descendant);
Set<NodeId> parentIds = getParentIds(state, false);
while (parentIds.size() > 0) {
if (parentIds.contains(ancestor)) {
return true;
}
Set<NodeId> grandparentIds = new LinkedHashSet<NodeId>();
for (NodeId parentId : parentIds) {
grandparentIds.addAll(getParentIds(getItemState(parentId), false));
}
parentIds = grandparentIds;
}
// not an ancestor
return false;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine degree of relationship of " + ancestor + " and " + descendant;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
use of org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.
the class HierarchyManagerImpl method getDepth.
/**
* {@inheritDoc}
*/
public int getDepth(ItemId id) throws ItemNotFoundException, RepositoryException {
// shortcut
if (id.equals(rootNodeId)) {
return 0;
}
try {
ItemState state = getItemState(id);
NodeId parentId = getParentId(state);
int depth = 0;
while (parentId != null) {
depth++;
state = getItemState(parentId);
parentId = getParentId(state);
}
return depth;
} catch (NoSuchItemStateException nsise) {
String msg = "failed to determine depth of " + id;
log.debug(msg);
throw new ItemNotFoundException(msg, nsise);
} catch (ItemStateException ise) {
String msg = "failed to determine depth of " + id;
log.debug(msg);
throw new RepositoryException(msg, ise);
}
}
use of org.apache.jackrabbit.core.state.ItemState 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 org.apache.jackrabbit.core.state.ItemState in project jackrabbit by apache.
the class ItemImpl method setRemoved.
/**
* Marks this instance as 'removed' and notifies its listeners.
* The resulting state is either 'temporarily invalidated' or
* 'permanently invalidated', depending on the initial state.
*
* @throws RepositoryException if an error occurs
*/
protected void setRemoved() throws RepositoryException {
final int status = data.getStatus();
if (status == STATUS_INVALIDATED || status == STATUS_DESTROYED) {
// this instance is already 'invalid', get outta here
return;
}
ItemState transientState = getOrCreateTransientItemState();
if (transientState.getStatus() == ItemState.STATUS_NEW) {
// this is a 'new' item, simply dispose the transient state
// (it is no longer used); this will indirectly (through
// stateDiscarded listener method) invalidate this instance permanently
stateMgr.disposeTransientItemState(transientState);
} else {
// this is an 'existing' item (i.e. it is backed by persistent
// state), mark it as 'removed'
transientState.setStatus(ItemState.STATUS_EXISTING_REMOVED);
// transfer the transient state to the attic
stateMgr.moveTransientItemStateToAttic(transientState);
// set state of this instance to 'invalid'
data.setStatus(STATUS_INVALIDATED);
// notify the manager that this instance has been
// temporarily invalidated
itemMgr.itemInvalidated(id, data);
}
}
Aggregations