org.javalid.core
Class AnnotationValidatorImpl

java.lang.Object
  extended by org.javalid.core.AnnotationValidatorImpl
All Implemented Interfaces:
AnnotationValidator
Direct Known Subclasses:
SpringAnnotationValidatorImpl

public class AnnotationValidatorImpl
extends java.lang.Object
implements AnnotationValidator

Core validator implementing AnnotationValidator interface.

Changes for 1.0.1:

Since:
1.0
Version:
1.1
Author:
M.Reuvers

Field Summary
protected  AnnotationSupport annotationSupport
           
protected  CacheSupport cacheSupport
           
protected  DebugSupport debugSupport
           
protected  JvConfiguration jvConfig
           
protected  JvConfigurationWrapper jvConfigWrapper
          Wrapper around JvConfiguration, this one should be passed to client code (e.g. validator implementations).
 
Constructor Summary
AnnotationValidatorImpl()
          Default constructor, using the default XML config file for JV.
AnnotationValidatorImpl(java.lang.String xmlConfigFile)
          Create this validator using given xml file.
AnnotationValidatorImpl(java.lang.String xmlConfigFile, boolean setValueToNullIfEmptyString)
          Creates this validator using given xml file.
AnnotationValidatorImpl(java.lang.String xmlConfigFile, boolean setValueToNullIfEmptyString, boolean callConfigurationLoadedComplete)
          Introduced which allows the control of when the extension's method 'configurationLoadingComplete' is called.
 
Method Summary
 java.util.List<ValidationMessage> validateObject(java.lang.Object object)
          Validates given object using the default primary group specified on ValidateDefinition.
 java.util.List<ValidationMessage> validateObject(java.lang.Object object, java.lang.String group)
          Validates given object for specified group, NOT recursive using a default path prefixing.
 java.util.List<ValidationMessage> validateObject(java.lang.Object 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 validateObject(java.lang.Object 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 validateObject(java.lang.Object 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(java.lang.Object 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(java.lang.Object 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(java.lang.Object 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(java.lang.Object 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 validateObject(java.lang.Object 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 validateObject(java.lang.Object object, java.lang.String group, java.lang.String pathPrefix, JavalidValidationCallbackHandler callbackHandler)
          Validates given object for specified group using a special prefix (does not recurse).
protected  void validateObjectPriv(ValidatorParams params, int currentLevelDeep, java.lang.String currentPath, JavalidValidationCallbackHandler callbackHandler, java.util.List<ValidationMessage> messages)
          The real validation method, which will recursively call itself until given parameters/constraints are met.
 java.util.List<ValidationMessage> validateProperty(java.lang.Object 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

jvConfig

protected JvConfiguration jvConfig

annotationSupport

protected AnnotationSupport annotationSupport

debugSupport

protected DebugSupport debugSupport

cacheSupport

protected CacheSupport cacheSupport

jvConfigWrapper

protected JvConfigurationWrapper jvConfigWrapper
Wrapper around JvConfiguration, this one should be passed to client code (e.g. validator implementations). Never expose JvConfiguration directly as that one may change in the future!

Constructor Detail

AnnotationValidatorImpl

public AnnotationValidatorImpl()
Default constructor, using the default XML config file for JV. If you need to specify a custom file, please use the other constructor.


AnnotationValidatorImpl

public AnnotationValidatorImpl(java.lang.String xmlConfigFile)
Create this validator using given xml file.

Parameters:
xmlConfigFile - The config file to use

AnnotationValidatorImpl

public AnnotationValidatorImpl(java.lang.String xmlConfigFile,
                               boolean setValueToNullIfEmptyString)
Creates this validator using given xml file.

Parameters:
xmlConfigFile - The config file to use
setValueToNullIfEmptyString - Defaults to false, but if set to true when a String/StringBuffer value to validate is encountered and they are EMPTY, they are set to null instead of leaving it like "". It is recommended to use @NotEmpty annotation instead.

AnnotationValidatorImpl

public AnnotationValidatorImpl(java.lang.String xmlConfigFile,
                               boolean setValueToNullIfEmptyString,
                               boolean callConfigurationLoadedComplete)
Introduced which allows the control of when the extension's method 'configurationLoadingComplete' is called. By default it is called at the end of the constructor unless you set it to false, in that case YOU are responsible for calling it once your own annotationvalidator implementation is ready. e.g. The SpringAnnotationValidatorImpl calls it after its own application context is ready for usage instead of in the constructor.

Parameters:
xmlConfigFile - The config file to use
setValueToNullIfEmptyString - Defaults to false, but if set to true when a String/StringBuffer value to validate is encountered and they are EMPTY, they are set to null instead of leaving it like "". It is recommended to use @NotEmpty annotation instead.
callConfigurationLoadedComplete -
Since:
1.1
Method Detail

validateObject

public java.util.List<ValidationMessage> validateObject(java.lang.Object object)
Description copied from interface: AnnotationValidator
Validates given object using the default primary group specified on ValidateDefinition. No recursion or anything else is applied.

Specified by:
validateObject in interface AnnotationValidator
Parameters:
object - The object to validate
Returns:
List of validation messages

validateObject

public java.util.List<ValidationMessage> validateObject(java.lang.Object object,
                                                        java.lang.String group)
Description copied from interface: AnnotationValidator
Validates given object for specified group, NOT recursive using a default path prefixing.

Specified by:
validateObject in interface AnnotationValidator
Parameters:
object - The object to validate
group - The group to validate
Returns:
List with ValidationMessage (size > 0 means something was invalid)

validateObject

public java.util.List<ValidationMessage> validateObject(java.lang.Object object,
                                                        java.lang.String group,
                                                        boolean recurse)
Description copied from interface: AnnotationValidator
Validates given object for specified group, either recursive or not using a default path prefixing.

Specified by:
validateObject in interface AnnotationValidator
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)

validateObject

public java.util.List<ValidationMessage> validateObject(java.lang.Object object,
                                                        java.lang.String group,
                                                        java.lang.String pathPrefix)
Description copied from interface: AnnotationValidator
Validates given object for specified group using a special prefix (does not recurse).

Specified by:
validateObject in interface AnnotationValidator
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)

validateObject

public java.util.List<ValidationMessage> validateObject(java.lang.Object object,
                                                        java.lang.String group,
                                                        java.lang.String pathPrefix,
                                                        boolean recurse)
Description copied from interface: AnnotationValidator
Validates given object for specified group using a special prefix and may recurse

Specified by:
validateObject in interface AnnotationValidator
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)

validateObject

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

Specified by:
validateObject in interface AnnotationValidator
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)

validateObject

public java.util.List validateObject(java.lang.Object object,
                                     java.lang.String group,
                                     JavalidValidationCallbackHandler callbackHandler)
Description copied from interface: AnnotationValidator
Validates given object for specified group, NOT recursive using a default path prefixing.

Specified by:
validateObject in interface AnnotationValidator
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)
See Also:
JavalidValidationCallbackHandler

validateObject

public java.util.List validateObject(java.lang.Object object,
                                     java.lang.String group,
                                     boolean recurse,
                                     JavalidValidationCallbackHandler callbackHandler)
Description copied from interface: AnnotationValidator
Validates given object for specified group, either recursive or not using a default path prefixing.

Specified by:
validateObject in interface AnnotationValidator
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)
See Also:
JavalidValidationCallbackHandler

validateObject

public java.util.List validateObject(java.lang.Object object,
                                     java.lang.String group,
                                     java.lang.String pathPrefix,
                                     JavalidValidationCallbackHandler callbackHandler)
Description copied from interface: AnnotationValidator
Validates given object for specified group using a special prefix (does not recurse).

Specified by:
validateObject in interface AnnotationValidator
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)
See Also:
JavalidValidationCallbackHandler

validateObject

public java.util.List validateObject(java.lang.Object object,
                                     java.lang.String group,
                                     java.lang.String pathPrefix,
                                     boolean recurse,
                                     JavalidValidationCallbackHandler callbackHandler)
Description copied from interface: AnnotationValidator
Validates given object for specified group using a special prefix and may recurse

Specified by:
validateObject in interface AnnotationValidator
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)
See Also:
JavalidValidationCallbackHandler

validateObject

public java.util.List<ValidationMessage> validateObject(java.lang.Object object,
                                                        java.lang.String group,
                                                        java.lang.String pathPrefix,
                                                        boolean recurse,
                                                        int levelDeep,
                                                        JavalidValidationCallbackHandler callbackHandler)
Description copied from interface: AnnotationValidator
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

Specified by:
validateObject in interface AnnotationValidator
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)
See Also:
JavalidValidationCallbackHandler

validateProperty

public java.util.List<ValidationMessage> validateProperty(java.lang.Object owningObject,
                                                          java.lang.String groupName,
                                                          java.lang.Object propertyValue,
                                                          java.lang.String propertyName,
                                                          java.lang.String pathPrefix)
Description copied from interface: AnnotationValidator
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).

Specified by:
validateProperty in interface AnnotationValidator
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)

validateObjectPriv

protected void validateObjectPriv(ValidatorParams params,
                                  int currentLevelDeep,
                                  java.lang.String currentPath,
                                  JavalidValidationCallbackHandler callbackHandler,
                                  java.util.List<ValidationMessage> messages)
The real validation method, which will recursively call itself until given parameters/constraints are met.

Parameters:
params - The non-changing parameters (static)
currentLevelDeep - The current level of recursion, 1 is the start level.
currentPath - The current path of the object, if a method on given object is validated and contains an error the error path would be: currentPath.methodName (e.g. examplePath.example)
messages - The list of messages to append new messages to