public static boolean isRequired(Class<?> clazz, String propertyName) {
if (clazz == null) {
return false;
}
if (clazz == null || propertyName == null) {
throw new CrankException("CrankUtils.isRequired: Null arguments are not allowed " +
" clazz = %s, propertyName = %s ", clazz, propertyName);
}
try {
PropertyDescriptor descriptor = getPropertyDescriptor( clazz, propertyName);
if (descriptor==null) {
throw new CrankException("CrankUtils.isRequired: Unable to find property descriptor");
}
if (descriptor.getPropertyType().isPrimitive()) {
return true;
}
Map<String, AnnotationData> map = getAnnotationDataAsMap( clazz, propertyName );
boolean found = map.get( "required" ) != null;
/* If you found an annotation called required, return true. */
if (found) {
return true;
} else {
/*Otherwise check to see if a column annotation data can be found. */
return (isRequiredColumnNullable(map, "column") || isRequiredColumnNullable(map, "joinColumn")
|| isRequiredColumnOptional(map, "manyToOne"));
}
} catch (Exception ex) {
throw new CrankException(ex, "CrankUtils.isRequired: Problem %s" +
" clazz = %s, propertyName = %s ", ex.getMessage(), clazz, propertyName);
}
}