use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.
the class LockManagerImpl method getLockHoldingState.
// ------------------------------------------------------------< private >---
/**
* Search nearest ancestor that is locked. Returns <code>null</code> if neither
* the given state nor any of its ancestors is locked.
* Note, that this methods does NOT check if the given node state would
* be affected by the lock present on an ancestor state.
* Note, that in certain cases it might not be possible to detect a lock
* being present due to the fact that the hierarchy might be incomplete or
* not even readable completely. For this reason it seem equally reasonable
* to search for jcr:lockIsDeep property only and omitting all kind of
* verification regarding nodetypes present.
*
* @param nodeState <code>NodeState</code> from which searching starts.
* Note, that the given state must not have an overlaid state.
* @return a state holding a lock or <code>null</code> if neither the
* given state nor any of its ancestors is locked.
*/
private NodeState getLockHoldingState(NodeState nodeState) {
NodeEntry entry = nodeState.getNodeEntry();
while (!entry.hasPropertyEntry(NameConstants.JCR_LOCKISDEEP)) {
NodeEntry parent = entry.getParent();
if (parent == null) {
// reached root state without finding a locked node
return null;
}
entry = parent;
}
try {
return entry.getNodeState();
} catch (RepositoryException e) {
// may occur if the nodeState is not accessible or some generic
// error occurred.
// for this case, assume that no lock exists and delegate final
// validation to the spi-implementation.
log.warn("Error while accessing lock holding NodeState: {}", e.getMessage());
return null;
}
}
use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.
the class LockManagerImpl method buildLockState.
private LockState buildLockState(NodeState nodeState) throws RepositoryException {
NodeId nId = nodeState.getNodeId();
NodeState lockHoldingState;
LockInfo lockInfo = wspManager.getLockInfo(nId);
if (lockInfo == null) {
// no lock present
return null;
}
NodeId lockNodeId = lockInfo.getNodeId();
if (lockNodeId.equals(nId)) {
lockHoldingState = nodeState;
} else {
NodeEntry lockedEntry = wspManager.getHierarchyManager().getNodeEntry(lockNodeId);
try {
lockHoldingState = lockedEntry.getNodeState();
} catch (RepositoryException e) {
log.warn("Cannot build LockState");
throw new RepositoryException("Cannot build LockState", e);
}
}
if (lockHoldingState == null) {
return null;
} else {
return new LockState(lockHoldingState, lockInfo);
}
}
use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.
the class SessionImpl method getNodeById.
/**
* Retrieve the <code>Node</code> with the given id.
*
* @param id
* @return node with the given <code>NodeId</code>.
* @throws ItemNotFoundException if no such node exists or if this
* <code>Session</code> does not have permission to access the node.
* @throws RepositoryException
*/
private Node getNodeById(NodeId id) throws ItemNotFoundException, RepositoryException {
// check sanity of this session
checkIsAlive();
try {
NodeEntry nodeEntry = getHierarchyManager().getNodeEntry(id);
Item item = getItemManager().getItem(nodeEntry);
if (item.isNode()) {
return (Node) item;
} else {
log.error("NodeId '" + id + " does not point to a Node");
throw new ItemNotFoundException(LogUtil.saveGetIdString(id, getPathResolver()));
}
} catch (AccessDeniedException e) {
throw new ItemNotFoundException(LogUtil.saveGetIdString(id, getPathResolver()));
}
}
use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.
the class NodeState method reorderChildNodeEntries.
/**
* Reorders the child node <code>insertNode</code> before the child node
* <code>beforeNode</code>.
*
* @param insertNode the child node to reorder.
* @param beforeNode the child node where to insert the node before. If
* <code>null</code> the child node <code>insertNode</code> is moved to the
* end of the child node entries.
* @throws ItemNotFoundException if <code>insertNode</code> or
* <code>beforeNode</code> is not a child node of this <code>NodeState</code>.
*/
synchronized void reorderChildNodeEntries(NodeState insertNode, NodeState beforeNode) throws ItemNotFoundException, RepositoryException {
NodeEntry before = (beforeNode == null) ? null : beforeNode.getNodeEntry();
insertNode.getNodeEntry().orderBefore(before);
// mark this state as modified
markModified();
}
use of org.apache.jackrabbit.jcr2spi.hierarchy.NodeEntry in project jackrabbit by apache.
the class SessionItemStateManager method visit.
/**
* @see OperationVisitor#visit(SetPrimaryType)
*/
public void visit(SetPrimaryType operation) throws ConstraintViolationException, RepositoryException {
// NOTE: nodestate is only modified upon save of the changes!
Name primaryName = operation.getPrimaryTypeName();
NodeState nState = operation.getNodeState();
NodeEntry nEntry = nState.getNodeEntry();
// detect obvious node type conflicts
EffectiveNodeTypeProvider entProvider = mgrProvider.getEffectiveNodeTypeProvider();
// try to build new effective node type (will throw in case of conflicts)
Name[] mixins = nState.getMixinTypeNames();
List<Name> all = new ArrayList<Name>(Arrays.asList(mixins));
all.add(primaryName);
// retrieve effective to assert validity of arguments
entProvider.getEffectiveNodeType(all.toArray(new Name[all.size()]));
// modify the value of the jcr:primaryType property entry without
// changing the node state itself
PropertyEntry pEntry = nEntry.getPropertyEntry(NameConstants.JCR_PRIMARYTYPE);
PropertyState pState = pEntry.getPropertyState();
setPropertyStateValue(pState, getQValues(new Name[] { primaryName }, qValueFactory), PropertyType.NAME, operation.getOptions());
// mark the affected node state modified and remember the operation
nState.markModified();
transientStateMgr.addOperation(operation);
}
Aggregations