use of org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl in project jackrabbit by apache.
the class NodeImpl method canAddMixin.
/**
*
* @param mixinName
* @return
* @throws NoSuchNodeTypeException
* @throws ConstraintViolationException
*/
private boolean canAddMixin(Name mixinName) throws NoSuchNodeTypeException, ConstraintViolationException {
NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
// first check characteristics of each mixin
NodeType mixin = ntMgr.getNodeType(mixinName);
if (!mixin.isMixin()) {
log.error(mixin.getName() + ": not a mixin node type");
return false;
}
// get list of existing nodetypes
Name[] existingNts = getNodeState().getNodeTypeNames();
// build effective node type representing primary type including existing mixins
EffectiveNodeType entExisting = session.getEffectiveNodeTypeProvider().getEffectiveNodeType(existingNts);
// check if the base type supports adding this mixin
if (!entExisting.supportsMixin(mixinName)) {
log.debug(mixin.getName() + ": not supported on node type " + getPrimaryNodeTypeName());
return false;
}
// second, build new effective node type for nts including the new mixin
// types, detecting eventual incompatibilities
Name[] resultingNts = new Name[existingNts.length + 1];
System.arraycopy(existingNts, 0, resultingNts, 0, existingNts.length);
resultingNts[existingNts.length] = mixinName;
session.getEffectiveNodeTypeProvider().getEffectiveNodeType(resultingNts);
// all validations succeeded: return true
return true;
}
use of org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeManagerImpl in project jackrabbit by apache.
the class NodeImpl method setPrimaryType.
/**
* @see javax.jcr.Node#setPrimaryType(String)
*/
public void setPrimaryType(String nodeTypeName) throws RepositoryException {
checkStatus();
if (getNodeState().isRoot()) {
String msg = "The primary type of the root node may not be changed.";
log.debug(msg);
throw new RepositoryException(msg);
}
Name ntName = getQName(nodeTypeName);
if (ntName.equals(getPrimaryNodeTypeName())) {
log.debug("Changing the primary type has no effect: '" + nodeTypeName + "' already is the primary node type.");
return;
}
NodeTypeManagerImpl ntMgr = session.getNodeTypeManager();
NodeType nt = ntMgr.getNodeType(ntName);
if (nt.isMixin() || nt.isAbstract()) {
throw new ConstraintViolationException("Cannot change the primary type: '" + nodeTypeName + "' is a mixin type or abstract.");
}
// perform the operation
Operation op = SetPrimaryType.create(getNodeState(), ntName);
session.getSessionItemStateManager().execute(op);
}
Aggregations