org.formaria.aria.validation
Class AbstractValidator

java.lang.Object
  extended by org.formaria.aria.validation.AbstractValidator
All Implemented Interfaces:
Validator
Direct Known Subclasses:
CommonsValidator, DateValidator, EditorValidationProxy, EditorValidator, MandatoryValidator, MinMaxValidator, NameValidator, PasswordValidator, PojoCommonsValidator, PojoValidator, RegularExpressionValidator, SetValidator

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

A basic implementation of the Validator interface

Copyright: Copyright (c) Formaria Ltd., 2008
License: see license.txt

$Revision: 2.6 $


Field Summary
protected  java.lang.Object container
          Container to be used for validation methods
protected  Project currentProject
          The owner project and the context for this object
protected  int errorLevel
          The level of the errors detected by the validation
protected  java.lang.String formattedMessage
          The formatted message
protected  boolean mandatory
          boolean indicating whether component requires input
protected  int mask
          The event mask of the validation
protected  java.lang.String message
          The unformatted message to be displayed
protected  boolean showErrorBadges
          If true show error badges for validation errors
protected  boolean start
          Indicates that the validation has started
protected  Translator translator
           
static int USE_FAIL_STYLE
           
static int USE_NORMAL_STYLE
           
static int USE_WARN_STYLE
           
protected  java.lang.reflect.Method validationMethod
          Method to be used for callback validations
protected  java.lang.String validationName
          The name of the validation which is being handled by this validator
protected  java.lang.String value
          Used to store the current value contained in the component
 
Fields inherited from interface org.formaria.aria.validation.Validator
IGNORE_BLANKS, LEVEL_ERROR, LEVEL_IGNORE, LEVEL_WARNING, MANDATORY, STRICT_CHECK, WEAK_CHECK
 
Constructor Summary
AbstractValidator(Project project)
           
 
Method Summary
 void applyErrorStyle(java.lang.Object comp, int errorStatus)
          Modify the evaluated component to indicate the error status
 int getLevel()
          Get the error level of the validations
 int getMask()
          Get the event mask.
 java.lang.String getMessage()
          Get the validation message which is formatted after the tokens have been replaced
 java.lang.String getName()
          Get the name of the validation
protected  java.lang.String getText(java.lang.Object c)
          Get the text value of the component.
 java.lang.String getValueAsString()
          Get the value as a string object
 java.lang.Object invokeMethod()
          Call the funcion to get the value we are validating.
protected  void replaceToken(java.lang.String lookup, java.lang.String replacement)
          Carry out a replacement on the validation message
protected  void replaceTokens()
          Replace any further tokens in the message
 void setMask(int newMask)
          Set the event mask.
 void setName(java.lang.String name)
          Set the name of the validation
 void setup(XmlElement ruleConfig, XmlElement instanceConfig)
          Set the validation parameters
static void setValidationColors(java.awt.Color[] validationColors)
          Set the validation colors
 void setValidationMethod(java.lang.reflect.Method m, java.lang.Object c)
          Set the Method of the Page to be invoked when we are doing a funcion validation
protected  void throwException()
          Replace the remaining tokens and throw the exception
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.formaria.aria.validation.Validator
validate
 

Field Detail

USE_NORMAL_STYLE

public static final int USE_NORMAL_STYLE
See Also:
Constant Field Values

USE_WARN_STYLE

public static final int USE_WARN_STYLE
See Also:
Constant Field Values

USE_FAIL_STYLE

public static final int USE_FAIL_STYLE
See Also:
Constant Field Values

mandatory

protected boolean mandatory
boolean indicating whether component requires input


message

protected java.lang.String message
The unformatted message to be displayed


value

protected java.lang.String value
Used to store the current value contained in the component


formattedMessage

protected java.lang.String formattedMessage
The formatted message


validationName

protected java.lang.String validationName
The name of the validation which is being handled by this validator


container

protected java.lang.Object container
Container to be used for validation methods


validationMethod

protected java.lang.reflect.Method validationMethod
Method to be used for callback validations


mask

protected int mask
The event mask of the validation


errorLevel

protected int errorLevel
The level of the errors detected by the validation


start

protected boolean start
Indicates that the validation has started


currentProject

protected Project currentProject
The owner project and the context for this object


showErrorBadges

protected boolean showErrorBadges
If true show error badges for validation errors


translator

protected Translator translator
Constructor Detail

AbstractValidator

public AbstractValidator(Project project)
Parameters:
project - the owner project
Method Detail

getMask

public int getMask()
Get the event mask. The mask helps filter the events for which the validator is invoked

Specified by:
getMask in interface Validator
Returns:
the mask

setMask

public void setMask(int newMask)
Set the event mask. The mask helps filter the events for which the validator is invoked

Parameters:
newMask - The new mask which is to be used by the validator

setValidationMethod

public void setValidationMethod(java.lang.reflect.Method m,
                                java.lang.Object c)
Set the Method of the Page to be invoked when we are doing a funcion validation

Specified by:
setValidationMethod in interface Validator
Parameters:
c - The component being validated
m - The method to be invoked

getName

public java.lang.String getName()
Get the name of the validation

Specified by:
getName in interface Validator
Returns:
The name

setName

public void setName(java.lang.String name)
Set the name of the validation

Parameters:
name - the new name

getMessage

public java.lang.String getMessage()
Get the validation message which is formatted after the tokens have been replaced

Specified by:
getMessage in interface Validator
Returns:
The formatted message.

setup

public void setup(XmlElement ruleConfig,
                  XmlElement instanceConfig)
Set the validation parameters

Specified by:
setup in interface Validator
Parameters:
ruleConfig - the validator parameters as declared in the validations rules file
instanceConfig - the validator instance parameters as declared in the page file

getValueAsString

public java.lang.String getValueAsString()
Get the value as a string object

Specified by:
getValueAsString in interface Validator
Returns:
the value as string

getLevel

public int getLevel()
Get the error level of the validations

Specified by:
getLevel in interface Validator
Returns:
the error level

invokeMethod

public java.lang.Object invokeMethod()
Call the funcion to get the value we are validating.

Returns:
The result of the function call

replaceToken

protected void replaceToken(java.lang.String lookup,
                            java.lang.String replacement)
Carry out a replacement on the validation message

Parameters:
lookup - The text to find
replacement - The text to replace the text with

replaceTokens

protected void replaceTokens()
Replace any further tokens in the message


getText

protected java.lang.String getText(java.lang.Object c)
Get the text value of the component.

Parameters:
c - The component
Returns:
The text components value

throwException

protected void throwException()
                       throws java.lang.Exception
Replace the remaining tokens and throw the exception

Throws:
java.lang.Exception - Throw an exception so that it can be caught

applyErrorStyle

public void applyErrorStyle(java.lang.Object comp,
                            int errorStatus)
Modify the evaluated component to indicate the error status

Parameters:
comp - the validated component
errorStatus - the error status

setValidationColors

public static void setValidationColors(java.awt.Color[] validationColors)
Set the validation colors

Parameters:
validationColors - the validation colors in the following order:
  1. Normal - the style for normal or valid input
  2. Warn - the style for values that are near the limit or values that may fail secondary validation, but that will allow the application to proceed, or non-mandatory validation failures
  3. Fail - the style for failed inputs