} else {
jcrValue = null;
}
//
PropertyDefinition def = JCR.findPropertyDefinition(node, propertyName);
//
if (def == null) {
throw new NoSuchPropertyException("Property " + propertyName + " cannot be set on node " + node.getPath() + " with type " + node.getPrimaryNodeType().getName());
}
//
if (jcrValue != null) {
int neededType = def.getRequiredType();
if (neededType != PropertyType.UNDEFINED) {
if (neededType != jcrValue.getType()) {
throw new ClassCastException("Cannot cast type " + jcrValue.getType() + " to type " + neededType + " when setting property " + propertyName);
}
}
}
//
if (def.isMultiple()) {
if (jcrValue == null) {
node.setProperty(propertyName, new Value[0]);
} else {
node.setProperty(propertyName, new Value[]{jcrValue});
}