I'm afraid it isn't going to work...
Let me explain:
I want to define a list of 'validations' on the classlevel.
But, an annotation can only have an array of another
concrete annotation-type. (This is a language limitation, you cannot extend annotations and use the 'super' class for the collection of validations)
Example, I can create a 'validations' annotation like this:
Code:
public @interface Validations {
Required [] validations();
}
This means, I can only add 'required' validations to the list, not other types of validations.
This is
not possible:
Code:
public @interface Validations {
Validation[] validations();
}
...
usage:
@Validations ( validations = {@Required(prop="startDate",message="Start date is required"), @After(prop="endDate",other="BeginDate",message="bla"} )
Now, I'm toying with the idea of allowing a classvalidator to return an array of InvalidValue objects.
This is however very different from the current way the validations work (=specify the messagekey in an annotation).
Don't know if this will be an accepted approach.
Edwin