LOG.debug(bar.toString());
LOG.debug(header);
LOG.debug(bar.toString());
}
if (isInStep(object, validationAnnotation, step)) {
ValidatorDescriptor validatorDescriptor =
validationAnnotation
.annotationType().getAnnotation(
ValidatorDescriptor.class);
try {
if (!validateObject(
object, validatorDescriptor,
validationAnnotation)) {
String targetFieldName = (String) ReflectionUtil
.determineAnnotationParameterValue(
validationAnnotation,
"targetFieldName");
if (StringUtils.isBlank(targetFieldName)) {
// TODO: Make a proper exception for this.
throw new RuntimeException(
"Cannot supply a blank value for " +
"\"targetFieldName\" in a class level " +
"validator");
}
result.recordValidationViolation(
targetFieldName,
generateErrorCode(
object,
targetFieldName,
validatorDescriptor,
validationAnnotation),
object);
}
} catch (ReportedValidationException e) {
result.recordValidationViolation(
e.getField(),
generateErrorCode(e, object),
e.getArguments());
}
}
}
}
for (Field field : fields) {
// Scan for validation annotations
for (Annotation validationAnnotation : field.getAnnotations()) {
// See if nested validation should occur on this field
if (validationAnnotation.annotationType().equals(
ValidateNested.class)) {
boolean isCollection =
Boolean.valueOf(
ReflectionUtil.determineAnnotationParameterValue(
validationAnnotation,
"isCollection").toString());
Class<?> fieldType;
NestedResult nestedResult = null;
boolean anyError = false;
if (isCollection) {
int collectionIndex = 0;
for (Object fieldValue :
(Collection<?>) ReflectionUtil
.determineFieldValue(object, field)) {
fieldType = fieldValue.getClass();
nestedResult =
new NestedResult(
field.getName()
+ "[" + collectionIndex + "]",
fieldType.getSimpleName());
AnnotatedObjectValidator.validate(
fieldValue,
nestedResult);
if (nestedResult.hasNestedValidationErrors()) {
anyError = true;
nestedResult.mergeWithMainResults(result);
}
collectionIndex++;
nestedResult = null;
}
if (anyError) {
result.recordValidationViolation(
field.getName(),
generateErrorCode(
object.getClass().getSimpleName(),
field.getName(),
"nestedValidation"),
ReflectionUtil.determineFieldValue(
object, field));
}
} else {
fieldType = field.getType();
nestedResult =
new NestedResult(
field.getName(),
fieldType.getSimpleName());
validateNestedField(object, field, step, nestedResult);
if (nestedResult.hasNestedValidationErrors()) {
result.recordValidationViolation(
field.getName(),
generateErrorCode(
object.getClass().getSimpleName(),
field.getName(),
"nestedValidation"),
ReflectionUtil.determineFieldValue(object, field));
nestedResult.mergeWithMainResults(result);
}
}
}
// Proceed with normal validators.
if (validationAnnotation.annotationType().isAnnotationPresent(
ValidatorDescriptor.class)) {
if (LOG.isDebugEnabled()) {
String header = "Running Field Validator "
+ validationAnnotation.annotationType()
.getSimpleName()
+ " on field \"" + field.getName() + "\"";
StringBuffer bar = new StringBuffer();
while (bar.length() < header.length()) {
bar.append("-");
}
LOG.debug("");
LOG.debug(bar.toString());
LOG.debug(header);
LOG.debug(bar.toString());
}
// Validation annotation found!
if (isInStep(field, validationAnnotation, step)) {
ValidatorDescriptor validatorDescriptor =
validationAnnotation
.annotationType().getAnnotation(
ValidatorDescriptor.class);
try {
if (!validateField(object, field,