NodeState nodeState = (NodeState) itemState;
ItemId id = nodeState.getNodeId();
NodeImpl node = (NodeImpl) itemMgr.getItem(id);
NodeDefinition def = node.getDefinition();
// primary type
NodeTypeImpl pnt = (NodeTypeImpl) node.getPrimaryNodeType();
// effective node type (primary type incl. mixins)
EffectiveNodeType ent = node.getEffectiveNodeType();
/**
* if the transient node was added (i.e. if it is 'new'),
* check its node's node type against the required node type
* in its definition
*/
if (nodeState.getStatus() == ItemState.STATUS_NEW) {
NodeType[] nta = def.getRequiredPrimaryTypes();
for (int i = 0; i < nta.length; i++) {
NodeTypeImpl ntReq = (NodeTypeImpl) nta[i];
if (!(pnt.getQName().equals(ntReq.getQName())
|| pnt.isDerivedFrom(ntReq.getQName()))) {
/**
* the transient node's primary node type does not
* satisfy the 'required primary types' constraint
*/
String msg = node.safeGetJCRPath()
+ " must be of node type " + ntReq.getName();
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
}