private boolean isLockedInternal
(SlideToken slideToken, NodeLock token,
boolean tryToLock, ObjectIsAlreadyLockedException nestedException)
throws ServiceAccessException, ObjectNotFoundException {
Uri objectUri = namespace.getUri(slideToken, token.getObjectUri(), false);
ObjectNode initialObject = objectUri.getStore()
.retrieveObject(objectUri);
Enumeration scopes = objectUri.getScopes();
// At the end of the test, this boolean's value is true if we can
// actually put the lock on the desired subject.
boolean isLocked = false;
// We parse all of the scopes which encompass the subject we want
// to lock.
// First, we parse all the parents of the subject.
while (!isLocked && scopes.hasMoreElements()) {
String currentScope = (String) scopes.nextElement();
Uri currentScopeUri = namespace.getUri(slideToken, currentScope, false);
Enumeration locks = currentScopeUri.getStore()
.enumerateLocks(currentScopeUri);
while (locks.hasMoreElements()) {
NodeLock currentLockToken = (NodeLock) locks.nextElement();
if (!isCompatible(slideToken, token, currentLockToken,
tryToLock)) {
isLocked = true;
if (nestedException != null) {
nestedException.addException
(new ObjectLockedException
(currentScopeUri.toString()));
}
}
}
}
// Then, if the desired scope is inheritable, we parse the
// locked subject's children to see if any of them has been
// locked with an incompatible lock.
if (token.isInheritable()) {
Stack childrenStack = new Stack();
childrenStack.push(initialObject);
while (!isLocked && !childrenStack.empty()) {
ObjectNode currentObject = (ObjectNode) childrenStack.pop();
Uri currentObjectUri =
namespace.getUri(slideToken, currentObject.getUri(), false);
// We test the compatibility of the child
Enumeration locks = currentObjectUri.getStore()
.enumerateLocks(currentObjectUri);
while (locks.hasMoreElements()) {
NodeLock currentLockToken = (NodeLock) locks.nextElement();
if (!isCompatible(slideToken, token,
currentLockToken, tryToLock)) {
isLocked = true;
if (nestedException != null) {
nestedException.addException
(new ObjectLockedException
(currentObjectUri.toString()));
}
}
}
// We get the children and add them to the Stack.
Vector childrenVector = new Vector();
Enumeration childrenUri = currentObject.enumerateChildren();
while (childrenUri.hasMoreElements()) {
String childUri = (String) childrenUri.nextElement();
Uri tempUri = namespace.getUri(slideToken, childUri, false);
ObjectNode child = tempUri.getStore()
.retrieveObject(tempUri);
childrenVector.addElement(child);
}
Enumeration children = childrenVector.elements();