buf.append(" and ");
if (hasNested)
buf.append("@ValidateNestedProperties");
buf.append('\n');
}
throw new StripesRuntimeException(buf.toString());
}
// after the conflict check, stop processing fields we've already seen
if (seen.contains(propertyName))
continue;
// get the @Validate and/or @ValidateNestedProperties
Validate simple;
ValidateNestedProperties nested;
if (onAccessor) {
simple = accessor.getAnnotation(Validate.class);
nested = accessor.getAnnotation(ValidateNestedProperties.class);
seen.add(propertyName);
}
else if (onMutator) {
simple = mutator.getAnnotation(Validate.class);
nested = mutator.getAnnotation(ValidateNestedProperties.class);
seen.add(propertyName);
}
else if (onField) {
simple = field.getAnnotation(Validate.class);
nested = field.getAnnotation(ValidateNestedProperties.class);
seen.add(propertyName);
}
else {
simple = null;
nested = null;
}
// add to allow list if @Validate present
if (simple != null) {
if (simple.field() == null || "".equals(simple.field())) {
meta.put(propertyName, new ValidationMetadata(propertyName, simple));
}
else {
log.warn("Field name present in @Validate but should be omitted: ",
clazz, ", property ", propertyName, ", given field name ",
simple.field());
}
}
// add all sub-properties referenced in @ValidateNestedProperties
if (nested != null) {
Validate[] validates = nested.value();
if (validates != null) {
for (Validate validate : validates) {
if (validate.field() != null && !"".equals(validate.field())) {
String fullName = propertyName + '.' + validate.field();
if (meta.containsKey(fullName)) {
log.warn("More than one nested @Validate with same field name: "
+ validate.field() + " on property " + propertyName);
}
meta.put(fullName, new ValidationMetadata(fullName, validate));
}
else {
log.warn("Field name missing from nested @Validate: ", clazz,
", property ", propertyName);
}
}
}
}
}
}
}
catch (RuntimeException e) {
log.error(e, "Failure checking @Validate annotations ", getClass().getName());
throw e;
}
catch (Exception e) {
log.error(e, "Failure checking @Validate annotations ", getClass().getName());
StripesRuntimeException sre = new StripesRuntimeException(e.getMessage(), e);
sre.setStackTrace(e.getStackTrace());
throw sre;
}
// Print out a pretty debug message showing what validations got configured
StringBuilder builder = new StringBuilder(128);