org.javalid.core
Interface AnnotationValidator<T>

All Known Implementing Classes:
AnnotationValidatorImpl, SpringAnnotationValidatorImpl

public interface AnnotationValidator<T>

Validation interface for validating objects annotated with JV annotations. The ValidationMessage contains a message containing the path of the method that was validated wrong. For instance the class:

 class A {
 private String example;
 
 @JvGroup (name="1")
 @NotNull
 public String getExample() { .. }
 }
 
Assume getExample() returns null, in that case a path of: example is set with the error message. It is possible to use a prefix where needed, use the appropriate method in that case. For instance setting a prefix of: myInstance. would in this example result in an error path of: myInstance.example

In the current implementation, each AnnotationValidatorImpl loads its own configuration (read the xml configuration etc). So it would be wise to use the class as either singleton (e.g. make it a static variable somewhere and share in your application) or inject it using spring e.g. that its only instantiated once as well.

This implementation allows you to load multiple validators in the same JVM with different configurations if required.

Changes for 1.1:

Since:
1.0
Version:
1.1
Author:
M.Reuvers

Method Summary
 java.util.List<ValidationMessage> validateObject(T object)
          Validates given object using the default primary group specified on ValidateDefinition.
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group)
          Validates given object for specified group, NOT recursive using a default path prefixing.
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group, boolean recurse)
          Validates given object for specified group, either recursive or not using a default path prefixing.
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group, boolean recurse, JavalidValidationCallbackHandler callbackHandler)
          Validates given object for specified group, either recursive or not using a default path prefixing.
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group, JavalidValidationCallbackHandler callbackHandler)
          Validates given object for specified group, NOT recursive using a default path prefixing.
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group, java.lang.String pathPrefix)
          Validates given object for specified group using a special prefix (does not recurse).
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group, java.lang.String pathPrefix, boolean recurse)
          Validates given object for specified group using a special prefix and may recurse
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group, java.lang.String pathPrefix, boolean recurse, int levelDeep)
          Validates given object for specified group using a special prefix and may recurse, if recurse is true levelDeep must be >= 1
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group, java.lang.String pathPrefix, boolean recurse, int levelDeep, JavalidValidationCallbackHandler callbackHandler)
          Validates given object for specified group using a special prefix and may recurse, if recurse is true levelDeep must be >= 1.
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group, java.lang.String pathPrefix, boolean recurse, JavalidValidationCallbackHandler callbackHandler)
          Validates given object for specified group using a special prefix and may recurse
 java.util.List<ValidationMessage> validateObject(T object, java.lang.String group, java.lang.String pathPrefix, JavalidValidationCallbackHandler callbackHandler)
          Validates given object for specified group using a special prefix (does not recurse).
 java.util.List<ValidationMessage> validateProperty(T owningObject, java.lang.String groupName, java.lang.Object propertyValue, java.lang.String propertyName, java.lang.String pathPrefix)
          This method allows validation for a single property.
 

Method Detail

validateObject

java.util.List<ValidationMessage> validateObject(T object)
Validates given object using the default primary group specified on ValidateDefinition. No recursion or anything else is applied.

Parameters:
object - The object to validate
Returns:
List of validation messages
Since:
1.0

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group)
Validates given object for specified group, NOT recursive using a default path prefixing.

Parameters:
object - The object to validate
group - The group to validate
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.0

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group,
                                                 JavalidValidationCallbackHandler callbackHandler)
Validates given object for specified group, NOT recursive using a default path prefixing.

Parameters:
object - The object to validate
group - The group to validate
callbackHandler - Optional callbackhandler (any class that implements this interface). The framework will then call the methods on this interface during validation. For details see the class documentation itself.
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.1
See Also:
JavalidValidationCallbackHandler

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group,
                                                 boolean recurse)
Validates given object for specified group, either recursive or not using a default path prefixing.

Parameters:
object - The object to validate
group - The group to validate
recurse - True if you wish to recurse (default 1 level deep)
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.0

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group,
                                                 boolean recurse,
                                                 JavalidValidationCallbackHandler callbackHandler)
Validates given object for specified group, either recursive or not using a default path prefixing.

Parameters:
object - The object to validate
group - The group to validate
recurse - True if you wish to recurse (default 1 level deep)
callbackHandler - Optional callbackhandler (any class that implements this interface). The framework will then call the methods on this interface during validation. For details see the class documentation itself.
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.1
See Also:
JavalidValidationCallbackHandler

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group,
                                                 java.lang.String pathPrefix)
Validates given object for specified group using a special prefix (does not recurse).

Parameters:
object - The object to validate
group - The group to validate
pathPrefix - The special path prefix to put before the normal object paths.
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.0

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group,
                                                 java.lang.String pathPrefix,
                                                 JavalidValidationCallbackHandler callbackHandler)
Validates given object for specified group using a special prefix (does not recurse).

Parameters:
object - The object to validate
group - The group to validate
pathPrefix - The special path prefix to put before the normal object paths.
callbackHandler - Optional callbackhandler (any class that implements this interface). The framework will then call the methods on this interface during validation. For details see the class documentation itself.
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.1
See Also:
JavalidValidationCallbackHandler

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group,
                                                 java.lang.String pathPrefix,
                                                 boolean recurse)
Validates given object for specified group using a special prefix and may recurse

Parameters:
object - The object to validate
group - The group to validate
pathPrefix - The special path prefix to put before the normal object paths.
recurse - True if you wish to recurse (1 level deep)
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.0

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group,
                                                 java.lang.String pathPrefix,
                                                 boolean recurse,
                                                 JavalidValidationCallbackHandler callbackHandler)
Validates given object for specified group using a special prefix and may recurse

Parameters:
object - The object to validate
group - The group to validate
pathPrefix - The special path prefix to put before the normal object paths.
recurse - True if you wish to recurse (1 level deep)
callbackHandler - Optional callbackhandler (any class that implements this interface). The framework will then call the methods on this interface during validation. For details see the class documentation itself.
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.1
See Also:
JavalidValidationCallbackHandler

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group,
                                                 java.lang.String pathPrefix,
                                                 boolean recurse,
                                                 int levelDeep)
Validates given object for specified group using a special prefix and may recurse, if recurse is true levelDeep must be >= 1

Parameters:
object - The object to validate
group - The group to validate
pathPrefix - The special path prefix to put before the normal object paths.
recurse - True if you wish to recurse
levelDeep - How deep the recursion should be, -1 for unlimited, otherwise >= 1. The recursion ends when either levelDeep is reached or the instance working on does not have any getXXX methods with JV group annotations anymore.
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.0

validateObject

java.util.List<ValidationMessage> validateObject(T object,
                                                 java.lang.String group,
                                                 java.lang.String pathPrefix,
                                                 boolean recurse,
                                                 int levelDeep,
                                                 JavalidValidationCallbackHandler callbackHandler)
Validates given object for specified group using a special prefix and may recurse, if recurse is true levelDeep must be >= 1. Also note that you can specify a callbackhandler if required

Parameters:
object - The object to validate
group - The group to validate
pathPrefix - The special path prefix to put before the normal object paths.
recurse - True if you wish to recurse
levelDeep - How deep the recursion should be, -1 for unlimited, otherwise >= 1. The recursion ends when either levelDeep is reached or the instance working on does not have any getXXX methods with JV group annotations anymore.
callbackHandler - Optional callbackhandler (any class that implements this interface). The framework will then call the methods on this interface during validation. For details see the class documentation itself.
Returns:
List with ValidationMessage (size > 0 means something was invalid)
Since:
1.1
See Also:
JavalidValidationCallbackHandler

validateProperty

java.util.List<ValidationMessage> validateProperty(T owningObject,
                                                   java.lang.String groupName,
                                                   java.lang.Object propertyValue,
                                                   java.lang.String propertyName,
                                                   java.lang.String pathPrefix)
This method allows validation for a single property. Note that recursion is not possible using this method. If you need that, please use one of the validateObject(..) methods.

The owning object represents where the property is from (thus owningObject.propertyName together denotes the method under validation). The owning object is used to determine if validation is allowed what is supported etc. However other than for information the owningObject is not used (thus no method is called on it, instead we rely on propertyValue to validate that).

Parameters:
owningObject - The owning object
groupName - Groupname we wish to validate for this property
propertyValue - The actual value to validate
propertyName - The name of the property (is a methodname from the owningObject, we use that to determine what validations must be processed on propertyValue), thus firstName is turned into getFirstName.
pathPrefix - The prefix to use in the path, in this case it must be the full expression EXCLUDING the propertyName but it should include owningObject's path (where it was from), e.g. in jsf: backingBean.person where backingBean is the name of the jsf bean, and person matches our owningObject.
Returns:
List with ValidationMessage instances (size > 0 means something was invalid)
Since:
1.0