org.iscreen.impl
Class BaseConfiguredValidator

java.lang.Object
  extended by org.iscreen.impl.BaseConfiguredValidator
All Implemented Interfaces:
ValidatorWrapper
Direct Known Subclasses:
MvelConfiguredValidator, OgnlConfiguredValidator

public abstract class BaseConfiguredValidator
extends java.lang.Object
implements ValidatorWrapper

This base class represents a wrapper around a validator that handles the actual call to the validator. This class is subclassed by OGNL or MVEL to handle the actual interpretation of how to handle mappings, etc.

Author:
Shellman, Dan

Field Summary
protected  ValidationService containingService
           
protected  boolean declared
           
protected  java.lang.String doc
           
protected  boolean failFastFlag
           
protected  java.lang.String id
           
protected  java.lang.String ifExp
           
protected  ResourceValue label
           
protected  java.util.Set mappings
           
protected  java.lang.String name
           
protected  java.lang.String parsedDoc
           
protected  BaseConfiguredValidator ref
           
protected  java.util.Set staticProperties
           
protected  Validator validator
           
protected  java.lang.Class validatorClass
           
 
Constructor Summary
BaseConfiguredValidator()
          Default constructor.
 
Method Summary
abstract  void addMapping(java.lang.String from, java.lang.String to)
          Adds a mapping for mapping the object being validated to the beanToValidate object (that the Validator created).
abstract  void addStaticProperty(java.lang.String property, java.lang.Object obj)
          Adds a "static" property to set on the underlying Validator.
protected abstract  java.lang.String convertDoc(java.lang.Object contextBean, java.lang.String unconvertedDoc)
          Convert the documentation text using the embedded markers.
protected abstract  void executeMappings(java.lang.Object from, java.lang.Object to)
          Maps the appropriate properties from one object to another.
abstract  Validator getConfiguredValidator()
          Creates the Validator and configures it.
 DocumentationIterator getDoc()
          Retrieves the documentation (parsed and updated) for this validator.
protected abstract  java.util.Collection getFields()
          Retrieves the Collection of fields (the 'getter' OGNL expressions) that are used in mapping properties from the JavaBean/Object being validated to the validation bean.
 java.lang.String getFieldsTrace()
           
 java.lang.String getId()
          Gets the id of this wrapper.
 java.lang.String getIfExpression()
          Retrieves the 'if' expression, which is used to determine whether this validator will be executed during validation.
 java.lang.String getLabel(java.util.Locale locale)
          Gets the value of the label for this Validator wrapper.
 java.util.Set getMappings()
          Gets the Set of mappings for this Validator and any Validator this Validator references.
 java.lang.String getName()
          Called to retrieve the "name" of the validator.
protected  java.lang.String getRawDoc()
          Retrieves the raw documentation for this.
protected  java.lang.String getServiceId()
           
 java.util.Set getStaticProperties()
          Retrieves the Set of static properties (which are OgnlPropertyMapping objects).
 java.lang.Class getValidatorClass()
          Returns the Class of the Validator this class is wrapping (this may retrieve the Class from another wrapper this wrapper references).
 boolean isDeclared()
          Flag to determine if the validator has been declared or merely referenced
 boolean isFailFast()
          Whether this wrapper should report to the validation service not to continue validating if this wrapper finds a failure.
 void setClassName(java.lang.String className)
          Sets the class name of the Validator this class is wrapping.
 void setDoc(java.lang.String documentation)
          Sets the documentation for this configured validator.
 void setFailFast(boolean flag)
          Sets whether this wrapper should report to the validation service not to continue validating if this wrapper finds a failure.
 void setId(java.lang.String theId)
          Sets the id of this wrapper.
 void setIfExpression(java.lang.String theExp)
          Sets the 'if' expression that will determine whether this validator will be executed during validation.
 void setLabel(Resource resource, java.lang.String key)
          Sets the Label for this Validator wrapper.
 void setLabel(java.lang.String labelValue)
          Sets the label for this Validator wrapper.
 void setName(java.lang.String theName)
          Sets the name of the validator.
 void setRef(BaseConfiguredValidator configuredValidatorRef)
          Sets a wrapper this wrapper may reference.
 void setValidationService(ValidationService service)
          Sets the ValidationService (ValidationSet) that contains this Validator wrapper.
protected abstract  boolean shouldExecute(java.lang.Object obj)
          Determines whether this validator should be executed or not.
 void signalDeclared()
          Sets the flag to signal that the validator has been declared, rather than merely referenced
 boolean validate(InternalValidatorContext context, ContextBean contextBean, ValidationTrace trace, java.lang.Object obj)
          Called to have the wrapper validate the passed object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

containingService

protected ValidationService containingService

failFastFlag

protected boolean failFastFlag

ifExp

protected java.lang.String ifExp

id

protected java.lang.String id

label

protected ResourceValue label

doc

protected java.lang.String doc

parsedDoc

protected java.lang.String parsedDoc

mappings

protected java.util.Set mappings

name

protected java.lang.String name

ref

protected BaseConfiguredValidator ref

staticProperties

protected java.util.Set staticProperties

validator

protected Validator validator

validatorClass

protected java.lang.Class validatorClass

declared

protected boolean declared
Constructor Detail

BaseConfiguredValidator

public BaseConfiguredValidator()
Default constructor.

Method Detail

addMapping

public abstract void addMapping(java.lang.String from,
                                java.lang.String to)
Adds a mapping for mapping the object being validated to the beanToValidate object (that the Validator created).

Parameters:
from - The OGNL from expression (getter)
to - The OGNL to expression (setter)

addStaticProperty

public abstract void addStaticProperty(java.lang.String property,
                                       java.lang.Object obj)
Adds a "static" property to set on the underlying Validator. A "static" property is really an OGNL expression that will set some value on the Validator once (such as a constraint, service, or failure message).

For failures, the object type should be an OgnlMessage. For a constraint or service, any object type is fine (as long as it maps to the underlying Validator property).

Parameters:
property - The OGNL expression to set a value
obj - The value to set, once, on the Validator to configure it.

executeMappings

protected abstract void executeMappings(java.lang.Object from,
                                        java.lang.Object to)
Maps the appropriate properties from one object to another.

Parameters:
from - The object to map from.
to - The object to map to.

getConfiguredValidator

public abstract Validator getConfiguredValidator()
Creates the Validator and configures it. Multiple calls will NOT construct a new Validator each call, but will return the same instance created the first time.

Returns:
Returns a created and configured Validator.

getFields

protected abstract java.util.Collection getFields()
Retrieves the Collection of fields (the 'getter' OGNL expressions) that are used in mapping properties from the JavaBean/Object being validated to the validation bean.

Returns:
Returns the Collection of fields.

getId

public java.lang.String getId()
Gets the id of this wrapper. If one hasn't been set, the validator this references will be returned. However, if there is no id, then an empty string is returned.

Returns:
Returns the id of this wrapper.

getLabel

public java.lang.String getLabel(java.util.Locale locale)
Gets the value of the label for this Validator wrapper. Based upon the locale, the value of the label *may* be different (if a static one was set, then it won't be different from what was set).

Returns:
Returns the value of the label, based on the current locale.

getMappings

public java.util.Set getMappings()
Gets the Set of mappings for this Validator and any Validator this Validator references.

Returns:
Returns the Set of mappings for this Validator.

getFieldsTrace

public java.lang.String getFieldsTrace()

getName

public java.lang.String getName()
Description copied from interface: ValidatorWrapper
Called to retrieve the "name" of the validator. The name represents some form of identification, though it does not have to be unique in any way. The name is merely associated with the configured validator, and is referenced when reporting failures.

Specified by:
getName in interface ValidatorWrapper
Returns:
Returns the name of this validator.

getIfExpression

public java.lang.String getIfExpression()
Retrieves the 'if' expression, which is used to determine whether this validator will be executed during validation.

Returns:
Returns the 'if' expression.

getStaticProperties

public java.util.Set getStaticProperties()
Retrieves the Set of static properties (which are OgnlPropertyMapping objects). This method is used to retrieve not only this wrapper's Set of static properties (see the addStaticProperty() method for what a static property is), but to also get the properties from any wrapper that this wrapper references, returning a combined Set (it's a Set to ensure that there are no duplicates based upon the property, or OGNL expression, of the OgnlPropertyMapping objects).

Returns:
Returns the Set of "static" properties for this wrapper and any referenced wrapper (no duplicates, though).

getValidatorClass

public java.lang.Class getValidatorClass()
Returns the Class of the Validator this class is wrapping (this may retrieve the Class from another wrapper this wrapper references).

Returns:
Returns the Validator this class is wrapping.

isFailFast

public boolean isFailFast()
Whether this wrapper should report to the validation service not to continue validating if this wrapper finds a failure.

Returns:
Returns if a failure will result in no further validations.

setClassName

public void setClassName(java.lang.String className)
Sets the class name of the Validator this class is wrapping.

Parameters:
className - The class name of the Validator

setFailFast

public void setFailFast(boolean flag)
Sets whether this wrapper should report to the validation service not to continue validating if this wrapper finds a failure.

Parameters:
flag - If true, a failure will result in no further validations.

setId

public void setId(java.lang.String theId)
Sets the id of this wrapper. A Validator may or may not have an id. If this wrapper represents a configured validator that's configured as part of a validation set, then it won't have an id.

Parameters:
theId - The id of this wrapper.

setLabel

public void setLabel(Resource resource,
                     java.lang.String key)
Sets the Label for this Validator wrapper. This label is based upon a Resource and a key into that resource.

Parameters:
resource - The Resource the label's value is in
key - The key to the label's value

setLabel

public void setLabel(java.lang.String labelValue)
Sets the label for this Validator wrapper. This label is a static string.

Parameters:
labelValue - The value of the label.

setName

public void setName(java.lang.String theName)
Sets the name of the validator. This name is a non-unique identifier used to report back on validation failures the validator that was involved in the failure.

Parameters:
theName - The name of the validator.

setIfExpression

public void setIfExpression(java.lang.String theExp)
Sets the 'if' expression that will determine whether this validator will be executed during validation.

Parameters:
theExp - The 'if' expression.

setDoc

public void setDoc(java.lang.String documentation)
Sets the documentation for this configured validator.

Parameters:
documentation - The documentation for this validator.

getDoc

public DocumentationIterator getDoc()
Retrieves the documentation (parsed and updated) for this validator.

Specified by:
getDoc in interface ValidatorWrapper
Returns:
Returns the documentation for this validator.

setRef

public void setRef(BaseConfiguredValidator configuredValidatorRef)
Sets a wrapper this wrapper may reference. Consider this reference as a delegated parent.

Parameters:
configuredValidatorRef - The delegated parent of this wrapper.

setValidationService

public void setValidationService(ValidationService service)
Sets the ValidationService (ValidationSet) that contains this Validator wrapper.

Parameters:
service - The ValidationService that contains this wrapper.

isDeclared

public boolean isDeclared()
Flag to determine if the validator has been declared or merely referenced

Returns:
true If declared, else just referenced.

signalDeclared

public void signalDeclared()
Sets the flag to signal that the validator has been declared, rather than merely referenced

Throws:
ConfigurationException - If a re-declaration occurs.

validate

public boolean validate(InternalValidatorContext context,
                        ContextBean contextBean,
                        ValidationTrace trace,
                        java.lang.Object obj)
Description copied from interface: ValidatorWrapper
Called to have the wrapper validate the passed object. It is expected that the wrapper will update the root object as appropriate. The context already has access to the root that is being passed in.

Specified by:
validate in interface ValidatorWrapper
Parameters:
context - The validation context to pass on to the contained validator.
contextBean - The OGNL root, to be updated as appropriate.
trace - The validation trace to track what calls what.
obj - The object to be validated.
Returns:
Returns true if validation should continue; false if it should be halted.

getServiceId

protected java.lang.String getServiceId()

convertDoc

protected abstract java.lang.String convertDoc(java.lang.Object contextBean,
                                               java.lang.String unconvertedDoc)
Convert the documentation text using the embedded markers.

Parameters:
contextBean - The context bean (root) for converting the doc.
unconvertedDoc - The raw documentation text.
Returns:
Returns the converted documentation text.

getRawDoc

protected java.lang.String getRawDoc()
Retrieves the raw documentation for this. The referenced validator is also checked, if necessary.

Returns:
Returns the raw documentation.

shouldExecute

protected abstract boolean shouldExecute(java.lang.Object obj)
Determines whether this validator should be executed or not.

Parameters:
bean - The object (the one being validated) to use to check the 'if' expression.
Returns:
Returns true if the validator should be executed.