org.javalid.core.validator
Class AbstractJavalidValidatorImpl<T extends java.lang.annotation.Annotation>

java.lang.Object
  extended by org.javalid.core.validator.AbstractJavalidValidatorImpl<T>
All Implemented Interfaces:
JavalidValidator<T>
Direct Known Subclasses:
AbstractLengthValidatorImpl, CollectionSizeValidatorImpl, DateAfterValidatorImpl, DateBeforeValidatorImpl, DateCheckValidatorImpl, DateEqualValidatorImpl, DateNotEqualValidatorImpl, DbNumCheckValidatorImpl, EmptyOrNotEmptyAllValidatorImpl, LovConstraintValidatorImpl, MaxValueValidatorImpl, MinValueValidatorImpl, NotEmptyAllValidatorImpl, NotEmptyValidatorImpl, NotNullAllValidatorImpl, NotNullValidatorImpl, NullOrNotNullAllValidatorImpl, RegularExpressionValidatorImpl, ValidateListValidatorImpl, ValidateMapValidatorImpl

public abstract class AbstractJavalidValidatorImpl<T extends java.lang.annotation.Annotation>
extends java.lang.Object
implements JavalidValidator<T>

Since:
1.2

Constructor Summary
AbstractJavalidValidatorImpl()
           
 
Method Summary
protected  void checkIsSingleExpression(java.lang.String expression)
          Checks if given value confirms to a single expression, if not raises a JaValidException
abstract  java.util.List<ValidationMessage> doValidate(T annotation, java.lang.Object value, java.lang.String path, JvConfigurationWrapper config)
           
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractJavalidValidatorImpl

public AbstractJavalidValidatorImpl()
Method Detail

validate

public java.util.List<ValidationMessage> validate(T annotation,
                                                  java.lang.Object value,
                                                  java.lang.String path,
                                                  JvConfigurationWrapper config)
Description copied from interface: JavalidValidator
This method is responsible for validating given value for the annotation this class is responsible for.

Specified by:
validate in interface JavalidValidator<T extends java.lang.annotation.Annotation>
Parameters:
annotation - The annotation it is about
value - The value to validate
path - 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)
Returns:
List with ValidationMessage when validation fails, if no error returns an EMPTY list (not NULL!!!)

validateComplex

public java.util.List<ValidationMessage> validateComplex(T annotation,
                                                         java.lang.Object value,
                                                         java.lang.String path,
                                                         JvConfigurationWrapper config,
                                                         ComplexValidationInfo info)
Description copied from interface: JavalidValidator
This the complex variant for validation and is called by the framework if requiresComplexCall is set to true. The framework delivers an extra parameter with a lot of extra validation information then.

Specified by:
validateComplex in interface JavalidValidator<T extends java.lang.annotation.Annotation>
Parameters:
annotation - The annotation it is about
value - The value to validate
path - 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.
Returns:
List with ValidationMessage when validation fails, if no error returns an EMPTY list (not NULL!!!)

doValidate

public abstract java.util.List<ValidationMessage> doValidate(T annotation,
                                                             java.lang.Object value,
                                                             java.lang.String path,
                                                             JvConfigurationWrapper config)

validationMustBeAppliedToGroup

public boolean validationMustBeAppliedToGroup(T annotation,
                                              java.lang.String groupName,
                                              JvGroup jvGroup,
                                              JvConfigurationWrapper config)
Description copied from interface: JavalidValidator
Implementors must return true if given groupName must indeed apply validation on its method. By default JV validation annotations have a property 'applyToGroups' where one can specify 1 or more groupnames if needed. Custom implementations may decide whether to adhere to that custom or use something else. If a custom annotation must always be applied for any group, simply return true.

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).

Specified by:
validationMustBeAppliedToGroup in interface JavalidValidator<T extends java.lang.annotation.Annotation>
Parameters:
annotation - The annotation it is about
groupName - 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)
Returns:
True if for the groupname validation must be applied, false otherwise.

requiresComplexCall

public boolean requiresComplexCall()
Description copied from interface: JavalidValidator
Returns true if this validator requires the current annotation validator to fullfill its validation (and all extra info).

Normal validators must return false. In that case the default validate(..) method is called. If false is returned, the validateComplex(..) method is called.

Specified by:
requiresComplexCall in interface JavalidValidator<T extends java.lang.annotation.Annotation>
Returns:
True if it intends to do complex validation

checkIsSingleExpression

protected void checkIsSingleExpression(java.lang.String expression)
Checks if given value confirms to a single expression, if not raises a JaValidException

Parameters:
expression - The expression to check