public boolean canAddMixin(String mixinName)
throws NoSuchNodeTypeException, RepositoryException {
// check state of this instance
sanityCheck();
Name ntName = session.getQName(mixinName);
NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
NodeTypeImpl mixin = ntMgr.getNodeType(ntName);
if (!mixin.isMixin()) {
return false;
}
int options = ItemValidator.CHECK_LOCK | ItemValidator.CHECK_CHECKED_OUT
| ItemValidator.CHECK_CONSTRAINTS | ItemValidator.CHECK_HOLD;
int permissions = Permission.NODE_TYPE_MNGMT;
// special handling of mix:(simple)versionable. since adding the mixin alters
// the version storage jcr:versionManagement privilege is required
// in addition.
if (NameConstants.MIX_VERSIONABLE.equals(ntName)
|| NameConstants.MIX_SIMPLE_VERSIONABLE.equals(ntName)) {
permissions |= Permission.VERSION_MNGMT;
}
if (!session.getValidator().canModify(this, options, permissions)) {
return false;
}
final Name primaryTypeName = data.getNodeState().getNodeTypeName();
NodeTypeImpl primaryType = ntMgr.getNodeType(primaryTypeName);
if (primaryType.isDerivedFrom(ntName)) {
// mixin already inherited -> addMixin is allowed but has no effect.
return true;