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.

Since:
1.0
Version:
1.2
Author:
M.Reuvers

Field Summary
protected  CacheSupport cacheSupport
           
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 callConfigurationLoadedComplete)
          Introduced with 1.1 which allows the control of when the extension's method 'configurationLoadingComplete' is called.
protected AnnotationValidatorImpl(java.lang.String xmlConfigFile, java.net.URL urlConfigFile, boolean callConfigurationLoadedComplete)
          Protected constructor called by the others which does the actual work (one of configs must be set)
  AnnotationValidatorImpl(java.net.URL urlConfigFile)
          Constructs this validator using given urlConfigFile.
  AnnotationValidatorImpl(java.net.URL urlConfigFile, boolean callConfigurationLoadedComplete)
          Allows the control of when the extension's method 'configurationLoadingComplete' is called.
 
Method Summary
 LocaleResolver getLocaleResolver()
          Returns the current locale resolver in use (which is the default implementation if not set).
 MessageCodeResolver getMessageCodeResolver()
          Returns the current MessageCodeResolver in use (which is the default implementation if not set).
 boolean isMessageResolvingEnabled()
          Returns true if automatic message resolving is enabled
 void setLocaleResolver(LocaleResolver localeResolver)
          Overrides and sets a new LocaleResolver to be used by the framework.
 void setMessageCodeResolver(MessageCodeResolver messageCodeResolver)
          Overrides and sets a new MessageCodeResolver
 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

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 callConfigurationLoadedComplete)
Introduced with 1.1 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
callConfigurationLoadedComplete - Set to true if a call after configuration must be sent to extensions (default is true)
Since:
1.1

AnnotationValidatorImpl

public AnnotationValidatorImpl(java.net.URL urlConfigFile)
Constructs this validator using given urlConfigFile.

Parameters:
urlConfigFile - The config file to use (as an url so it can point to nearly everything)
Since:
1.2

AnnotationValidatorImpl

public AnnotationValidatorImpl(java.net.URL urlConfigFile,
                               boolean callConfigurationLoadedComplete)
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:
urlConfigFile - The config file to use (as an url so it can point to nearly everything)
callConfigurationLoadedComplete - Set to true if a call after configuration must be sent to extensions (default is true)
Since:
1.2

AnnotationValidatorImpl

protected AnnotationValidatorImpl(java.lang.String xmlConfigFile,
                                  java.net.URL urlConfigFile,
                                  boolean callConfigurationLoadedComplete)
Protected constructor called by the others which does the actual work (one of configs must be set)

Parameters:
xmlConfigFile - Xml config file
urlConfigFile - Url config file
callConfigurationLoadedComplete - Set to true if a call after configuration must be sent to extensions (default is true)
Since:
1.2
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)

setLocaleResolver

public void setLocaleResolver(LocaleResolver localeResolver)
Description copied from interface: AnnotationValidator
Overrides and sets a new LocaleResolver to be used by the framework. This resolver is used when resolving messages for instance (which locale to use). If not set it uses the default implementation.

Specified by:
setLocaleResolver in interface AnnotationValidator
Parameters:
localeResolver - The resolver to use

getLocaleResolver

public LocaleResolver getLocaleResolver()
Description copied from interface: AnnotationValidator
Returns the current locale resolver in use (which is the default implementation if not set).

Note that the default implementation is not threadsafe as for setting a new Locale (in other words its best to do this when initializing the validator or set your own LocaleResolver instead).

Specified by:
getLocaleResolver in interface AnnotationValidator
Returns:
LocaleResolver in use

getMessageCodeResolver

public MessageCodeResolver getMessageCodeResolver()
Description copied from interface: AnnotationValidator
Returns the current MessageCodeResolver in use (which is the default implementation if not set).

Specified by:
getMessageCodeResolver in interface AnnotationValidator
Returns:
MessageCodeResolver The current message resolver

setMessageCodeResolver

public void setMessageCodeResolver(MessageCodeResolver messageCodeResolver)
Description copied from interface: AnnotationValidator
Overrides and sets a new MessageCodeResolver

Specified by:
setMessageCodeResolver in interface AnnotationValidator
Parameters:
messageCodeResolver - New message code resolver

isMessageResolvingEnabled

public boolean isMessageResolvingEnabled()
Description copied from interface: AnnotationValidator
Returns true if automatic message resolving is enabled

Specified by:
isMessageResolvingEnabled in interface AnnotationValidator
Returns:
True if automatic message resolving is enabled

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.
callbackHandler - Callback handler to be called during validation
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