if (stateMgr.hasNodeReferences(activityId)) {
try {
NodeReferences refs = stateMgr.getNodeReferences(activityId);
for (PropertyId id: refs.getReferences()) {
if (!state.hasNode(id.getParentId())) {
throw new ActivityViolationException("Unable to checkout. " +
"Activity is already used for the same node in " +
"another workspace.");
}
}
} catch (ItemStateException e) {
throw new RepositoryException("Error during checkout.", e);
}
}
// If there is a version in H that is not an eventual predecessor of N but
// whose jcr:activity references A, then the checkout fails with an
// ActivityViolationException
InternalActivityImpl a = (InternalActivityImpl) getItem(activityId);
NodeId historyId = state.getPropertyValue(NameConstants.JCR_VERSIONHISTORY).getNodeId();
InternalVersionHistory history = (InternalVersionHistory) getItem(historyId);
InternalVersion version = a.getLatestVersion(history);
if (version != null) {
InternalVersion baseVersion = (InternalVersion) getItem(baseId);
while (baseVersion != null && !baseVersion.getId().equals(version.getId())) {
baseVersion = baseVersion.getLinearPredecessor();
}
if (baseVersion == null) {
throw new ActivityViolationException("Unable to checkout. " +
"Activity is used by another version on a different branch: " + version.getName());
}
}
}
return baseId;