*/
public void validate(NodeState nodeState) throws ConstraintViolationException,
RepositoryException {
// effective primary node type
EffectiveNodeType entPrimary = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(nodeState.getNodeTypeName());
QNodeDefinition def = nodeState.getDefinition();
// check if primary type satisfies the 'required node types' constraint
Name[] requiredPrimaryTypes = def.getRequiredPrimaryTypes();
for (int i = 0; i < requiredPrimaryTypes.length; i++) {
if (!entPrimary.includesNodeType(requiredPrimaryTypes[i])) {
String msg = safeGetJCRPath(nodeState)
+ ": missing required primary type "
+ requiredPrimaryTypes[i];
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
// mandatory properties
// effective node type (primary type incl. mixins)
Name[] ntNames = nodeState.getAllNodeTypeNames();
EffectiveNodeType entPrimaryAndMixins = mgrProvider.getEffectiveNodeTypeProvider().getEffectiveNodeType(ntNames);
QPropertyDefinition[] pda = entPrimaryAndMixins.getMandatoryQPropertyDefinitions();
for (int i = 0; i < pda.length; i++) {
QPropertyDefinition pd = pda[i];
if (!nodeState.hasPropertyName(pd.getName())) {
String msg = safeGetJCRPath(nodeState)
+ ": mandatory property " + pd.getName()
+ " does not exist";
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}
// mandatory child nodes
QNodeDefinition[] cnda = entPrimaryAndMixins.getMandatoryQNodeDefinitions();
for (int i = 0; i < cnda.length; i++) {
QNodeDefinition cnd = cnda[i];
if (!nodeState.getNodeEntry().hasNodeEntry(cnd.getName())) {
String msg = safeGetJCRPath(nodeState)
+ ": mandatory child node " + cnd.getName()
+ " does not exist";
log.debug(msg);
throw new ConstraintViolationException(msg);
}
}