org.iscreen.impl
Class ConfiguredValidator

java.lang.Object
  extended by org.iscreen.impl.ConfiguredValidator
All Implemented Interfaces:
ValidatorWrapper

public class ConfiguredValidator
extends java.lang.Object
implements ValidatorWrapper

A special validator wrapper that wraps a Validator and the configuration associated with it.

Author:
Shellman, Dan

Field Summary
protected  ValidationService containingService
           
static java.lang.String DEFAULT_FROM
           
static java.lang.String DEFAULT_TO
           
protected  boolean failFastFlag
           
protected  java.lang.String id
           
protected  ResourceValue label
           
protected  java.util.Set mappings
           
protected  ConfiguredValidator ref
           
protected  java.util.Set staticProperties
           
protected  Validator validator
           
protected  java.lang.Class validatorClass
           
 
Constructor Summary
ConfiguredValidator()
          Default constructor.
 
Method Summary
 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).
 void addStaticProperty(java.lang.String property, java.lang.Object obj)
          Adds a "static" property to set on the underlying Validator.
protected  void executeMappings(java.lang.Object from, java.lang.Object to)
          Maps the appropriate properties from one object to another.
 Validator getConfiguredValidator()
          Creates the Validator and configures it.
protected static OgnlObjectMapping getDefaultMapping()
          Create a default mapping so that if no mapping is defined in configuration, a default mapping can be used.
protected  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 getId()
          Gets the id of this wrapper.
 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.
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 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 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 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 setRef(ConfiguredValidator configuredValidatorRef)
          Sets a wrapper this wrapper may reference.
 void setValidationService(ValidationService service)
          Sets the ValidationService (ValidationSet) that contains this Validator wrapper.
 boolean validate(DefaultValidatorContext context, OgnlRoot root, 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

DEFAULT_TO

public static final java.lang.String DEFAULT_TO
See Also:
Constant Field Values

DEFAULT_FROM

public static final java.lang.String DEFAULT_FROM
See Also:
Constant Field Values

id

protected java.lang.String id

containingService

protected ValidationService containingService

validator

protected Validator validator

validatorClass

protected java.lang.Class validatorClass

ref

protected ConfiguredValidator ref

label

protected ResourceValue label

mappings

protected java.util.Set mappings

staticProperties

protected java.util.Set staticProperties

failFastFlag

protected boolean failFastFlag
Constructor Detail

ConfiguredValidator

public ConfiguredValidator()
Default constructor.

Method Detail

validate

public boolean validate(DefaultValidatorContext context,
                        OgnlRoot root,
                        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.
root - The OGNL root, to be updated as appropriate.
obj - The object to be validated.

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.

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.

getConfiguredValidator

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

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.

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

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.

setRef

public void setRef(ConfiguredValidator 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.

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.

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.

addStaticProperty

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

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

addMapping

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

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.

getServiceId

protected java.lang.String getServiceId()

executeMappings

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

getFields

protected 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 (the 'getter' OGNL expressions).

getDefaultMapping

protected static OgnlObjectMapping getDefaultMapping()
Create a default mapping so that if no mapping is defined in configuration, a default mapping can be used.

Returns:
Returns a default configured mapping.