|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface JavalidValidator<T extends java.lang.annotation.Annotation>
This interface is the contract for a class that performs validation for an annotation. For instance the annotation @NotNull has a NotNullValidatorImpl class, which is responsible for validating a method on the constraint not null.
You can define your own annotations and add a validator for them. Your choice of annotation is free (no restrictions). The validator class responsible for validating for that annotation however must implement this interface. Don't forget to register the annotation with its validator class in your own jv-config.xml file!
The framework first calls validationMustBeAppliedToGroup(Annotation annotation, String group) to determine if this validation must be applied or not. If true, then it calls validate(..)
The implementing class must have a default constructor and NOT use state information (as the classes are instantiated only once and then shared).
| Method Summary | |
|---|---|
boolean |
requiresComplexCall()
Returns true if this validator requires the current annotation validator to fullfill its validation (and all extra info). |
java.util.List<ValidationMessage> |
validate(T annotation,
java.lang.Object value,
java.lang.String path,
JvConfigurationWrapper config)
This method is responsible for validating given value for the annotation this class is responsible for. |
java.util.List<ValidationMessage> |
validateComplex(T annotation,
java.lang.Object value,
java.lang.String path,
JvConfigurationWrapper config,
ComplexValidationInfo info)
This the complex variant for validation and is called by the framework if requiresComplexCall is set to true. |
boolean |
validationMustBeAppliedToGroup(T annotation,
java.lang.String groupName,
JvGroup jvGroup,
JvConfigurationWrapper config)
Implementors must return true if given groupName must indeed apply validation on its method. |
| Method Detail |
|---|
java.util.List<ValidationMessage> validate(T annotation,
java.lang.Object value,
java.lang.String path,
JvConfigurationWrapper config)
annotation - The annotation it is aboutvalue - The value to validatepath - The framework gives the full path for this value you are validating, thus
you can use it directly in the ValidationMessage as path.config - Wrapper containing public configuration info (such as reflectionsupport, beanlookup, can be used if needed)
java.util.List<ValidationMessage> validateComplex(T annotation,
java.lang.Object value,
java.lang.String path,
JvConfigurationWrapper config,
ComplexValidationInfo info)
annotation - The annotation it is aboutvalue - The value to validatepath - The framework gives the full path for this value you are validating, thus
you can use it directly in the ValidationMessage as path.config - Wrapper containing public configuration info (such as reflectionsupport, beanlookup, can be used if needed)info - Information object about the current validation. Careful with using it! Know what you are doing.
boolean validationMustBeAppliedToGroup(T annotation,
java.lang.String groupName,
JvGroup jvGroup,
JvConfigurationWrapper config)
Example: JvGroup (create,edit), groupName=create and the annotation in question has as groups {JvGroup.GROUP_APPLY_ALL}. This means the annotation supports ANY group that is defined for JvGroup, in this example JvGroup defines create and an edit group. As the annotation defines JV_GROUP_ALL and the requested group=create, it does exist in JvGroup and the annotation supports any group, thus true must be returend.
Another example: JvGroup(create,edit), groupName=edit, annotation={create}. Group requested is edit, this exists for JvGroup, yet the annotation defines only to validate for create. Thus false must be returned.
Last example: JvGroup(create,edit), groupName='delete', annotation={create,edit,delete}. The groupName requested (delete) does not exist in JvGroup and must be skipped always whatever the annotation says (delete group in annotation is useless as it is not part of the JvGroup).
annotation - The annotation it is aboutgroupName - The groupName, the groupName we wish to know about whether it is allowed
or not (this is the group currently being validated).jvGroup - the group to check in if requested groupName is indeed ok to be validated (it must exist in that array of groups)config - Wrapper containing public configuration info (such as reflectionsupport, beanlookup, can be used if needed)
boolean requiresComplexCall()
Normal validators must return false. In that case the default validate(..) method is called. If false is returned, the validateComplex(..) method is called.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||