Lists with Java Annotations
public class myAnnotation_Validator implements ConstraintValidator<myAnnotation, Collection> {
private String[] names;
@Override
public void initialize(myAnnotation a) {
//get values which are defined in the annotation
names = myAnnotation.namen();
}
@Override
public boolean isValid(Collection objectToValidate, ConstraintValidatorContext cvc) {
if(objectToValidate == null) return true; // use the @NotNull annotation for null checks
for(Object o : objectToValidate) {
//check if value is valid
}
return false;
}
}
In the initialize method you can get the values, which are defined in the annotation. The isValid method is used to validate the object (objectToValidate -> your list object).
For more information on how to write a custom validator see http://docs.jboss.org/hibernate/validator/4.3/reference/en-US/html/validator-customconstraints.html#validator-customconstraints-validator
Also the Hibernate-Validator implementation is a good reference. https://github.com/hibernate/hibernate-validator/tree/master/engine/src/main/java/org/hibernate/validator/internal/constraintvalidators
I hope this answer helps you.