}
} else {
// the transient item is a property
PropertyState propState = (PropertyState) itemState;
ItemId propId = propState.getPropertyId();
PropertyDefinitionImpl propDef = (PropertyDefinitionImpl) def;
/**
* check value constraints
* (no need to check value constraints of protected properties
* as those are set by the implementation only, i.e. they
* cannot be set by the user through the api)
*/
if (!def.isProtected()) {
String[] constraints = propDef.getValueConstraints();
if (constraints != null) {
InternalValue[] values = propState.getValues();
try {
EffectiveNodeType.checkSetPropertyValueConstraints(
propDef.unwrap(), values);
} catch (RepositoryException e) {
// repack exception for providing more verbose error message
String msg = itemMgr.safeGetJCRPath(propId) + ": " + e.getMessage();
log.debug(msg);
throw new ConstraintViolationException(msg);
}
/**
* need to manually check REFERENCE value constraints
* as this requires a session (target node needs to
* be checked)
*/
if (constraints.length > 0
&& (propDef.getRequiredType() == PropertyType.REFERENCE
|| propDef.getRequiredType() == PropertyType.WEAKREFERENCE)) {
for (int i = 0; i < values.length; i++) {
boolean satisfied = false;
String constraintViolationMsg = null;
try {
UUID targetUUID = values[i].getUUID();
if (propDef.getRequiredType() == PropertyType.WEAKREFERENCE
&& !itemMgr.itemExists(new NodeId(targetUUID))) {
// target of weakref doesn;t exist, skip
continue;
}
Node targetNode = session.getNodeByUUID(targetUUID);
/**
* constraints are OR-ed, i.e. at least one
* has to be satisfied
*/
for (int j = 0; j < constraints.length; j++) {
/**
* a [WEAK]REFERENCE value constraint specifies
* the name of the required node type of
* the target node
*/
String ntName = constraints[j];
if (targetNode.isNodeType(ntName)) {
satisfied = true;
break;
}
}
if (!satisfied) {
NodeType[] mixinNodeTypes = targetNode.getMixinNodeTypes();
String[] targetMixins = new String[mixinNodeTypes.length];
for (int j = 0; j < mixinNodeTypes.length; j++) {
targetMixins[j] = mixinNodeTypes[j].getName();
}
String targetMixinsString = Text.implode(targetMixins, ", ");
String constraintsString = Text.implode(constraints, ", ");
constraintViolationMsg = itemMgr.safeGetJCRPath(propId)
+ ": is constraint to ["
+ constraintsString
+ "] but references [primaryType="
+ targetNode.getPrimaryNodeType().getName()
+ ", mixins="
+ targetMixinsString + "]";
}
} catch (RepositoryException re) {
String msg = itemMgr.safeGetJCRPath(propId)
+ ": failed to check "
+ ((propDef.getRequiredType() == PropertyType.REFERENCE) ? "REFERENCE" : "WEAKREFERENCE")
+ " value constraint";
log.debug(msg);
throw new ConstraintViolationException(msg, re);
}
if (!satisfied) {