org.iscreen
Class BaseValidator

java.lang.Object
  extended by org.iscreen.BaseValidator
All Implemented Interfaces:
Validator
Direct Known Subclasses:
DateFormatValidator, NullValidator, RegularExpressionValidator, StringValidator

public abstract class BaseValidator
extends java.lang.Object
implements Validator

This abstract class acts as a base class for custom validators. Sub-classes can extend this class to take advantage of the default implementation this class provides.

Author:
Shellman, Dan

Field Summary
protected  FailureMessage defaultFailure
           
 
Constructor Summary
BaseValidator()
           
 
Method Summary
 java.lang.Object constructBeanToValidate()
          This is called prior to calling the validate() method.
 FailureMessage getDefaultFailure()
          Retrieves the default failure message.
protected  java.lang.String getStringValue(java.lang.Object obj)
          Gets the object to validate as a String.
 void setDefaultFailure(FailureMessage failure)
          Sets the failure message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.iscreen.Validator
validate
 

Field Detail

defaultFailure

protected FailureMessage defaultFailure
Constructor Detail

BaseValidator

public BaseValidator()
Method Detail

constructBeanToValidate

public java.lang.Object constructBeanToValidate()
Description copied from interface: Validator
This is called prior to calling the validate() method. This method is meant to construct a JavaBean that will have properties mapped to it for use by the validator.

Specified by:
constructBeanToValidate in interface Validator
Returns:
Returns a JavaBean that will have properties mapped to it for use by the call to the validate() method.

getDefaultFailure

public FailureMessage getDefaultFailure()
Retrieves the default failure message. If only one failure is used by the sub-class, then this property can be used to get the failure message for reporting a failure.

Returns:
Returns the default failure message.

setDefaultFailure

public void setDefaultFailure(FailureMessage failure)
Sets the failure message. This is called based upon what's configured for this validator. Ensure that this is properly configured: otherwise, the call to getDefaultFailure() will return null.

Parameters:
failure - The default failure message to use.

getStringValue

protected java.lang.String getStringValue(java.lang.Object obj)
Gets the object to validate as a String. This method assumes the object is of type SimpleBean. If object is null, this method returns null; otherwise, it returns the value as a String.

This method would normally be called by the validate() method like this:
public void validate( ValidatorContext context, Object beanToValidate ) { String str; str = getStringValue( beanToValidate ); ... }

Parameters:
obj - The object being validated.
Returns:
Returns the object to be validated as a String.