Commons Resources (Unofficial)
|
- All Implemented Interfaces:
- java.io.Serializable
- public class Validator
- extends java.lang.Object
- implements java.io.Serializable
Validations are processed by the validate method.
An instance of ValidatorResources is
used to define the validators (validation methods)
and the validation rules for a JavaBean.
Field Summary |
static java.lang.String |
BEAN_KEY
Resources key the JavaBean is stored to perform validation on. |
protected java.lang.ClassLoader |
classLoader
The class loader to use for instantiating application objects. |
static java.lang.String |
FIELD_KEY
Resources key the Field is stored under. |
protected java.lang.String |
formName
|
protected java.util.HashMap |
hResources
|
static java.lang.String |
LOCALE_KEY
Resources key the Locale is stored. |
protected static org.apache.commons.logging.Log |
log
Logger |
protected int |
page
|
protected
ValidatorResources
|
resources
|
protected boolean |
useContextClassLoader
Whether or not to use the Context ClassLoader when loading classes
for instantiating new objects. |
static java.lang.String |
VALIDATOR_ACTION_KEY
Resources key the ValidatorAction is stored under. |
static java.lang.String |
VALIDATOR_KEY
Resources key the Validator is stored under. |
Constructor Summary |
Validator
(
ValidatorResources
resources)
Construct a Validator that will
use the ValidatorResources
passed in to retrieve pluggable validators
the different sets of validation rules. |
Validator
(
ValidatorResources
resources,
java.lang.String formName)
Construct a Validator that will
use the ValidatorResources
passed in to retrieve pluggable validators
the different sets of validation rules. |
Method Summary |
void |
addResource
(java.lang.String key,
java.lang.Object value)
Add a resource to be used during the processing
of validations. |
void |
clear
()
Clears the form name, resources that were added,
and the page that was set (if any). |
java.lang.ClassLoader |
getClassLoader
()
Return the class loader to be used for instantiating application objects
when required. |
java.lang.String |
getFormName
()
Gets the form name which is the key
to a set of validation rules. |
int |
getPage
()
Gets the page. |
java.lang.Object |
getResource
(java.lang.String key)
Get a resource to be used during the processing
of validations. |
boolean |
getUseContextClassLoader
()
Return the boolean as to whether the context classloader should be used. |
private boolean |
isValid
(java.lang.Object result)
Returns if the result if valid. |
void |
setClassLoader
(java.lang.ClassLoader classLoader)
Set the class loader to be used for instantiating application objects
when required. |
void |
setFormName
(java.lang.String formName)
Sets the form name which is the key
to a set of validation rules. |
void |
setPage
(int page)
Sets the page. |
void |
setUseContextClassLoader
(boolean use)
Determine whether to use the Context ClassLoader (the one found by
calling Thread.currentThread().getContextClassLoader() )
to resolve/load classes that are defined in various rules. |
ValidatorResults
|
validate
()
Performs validations based on the configured resources. |
private void |
validateField
(
Field
field,
ValidatorResults
allResults)
Run the validations on a given field, modifying the passed
ValidatorResults to add in any new errors found. |
private boolean |
validateFieldForRule
(
Field
field,
ValidatorAction
va,
ValidatorResults
results,
java.util.Map actions,
int pos)
Executes the given ValidatorAction and all ValidatorActions that it depends on. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
protected static org.apache.commons.logging.Log
- Logger
public static java.lang.String
- Resources key the JavaBean is stored to perform validation on.
public static java.lang.String
- Resources key the
ValidatorAction is stored under.
This will be automatically passed into a validation method
with the current ValidatorAction if it is
specified in the method signature.
public static java.lang.String
- Resources key the
Field is stored under.
This will be automatically passed into a validation method
with the current Field if it is
specified in the method signature.
public static java.lang.String
- Resources key the
Validator is stored under.
This will be automatically passed into a validation method
with the current Validator if it is
specified in the method signature.
public static java.lang.String
- Resources key the
Locale is stored.
This will be used to retrieve the appropriate
FormSet and Form to be
processed.
protected java.lang.String
protected java.util.HashMap
protected java.lang.ClassLoader
- The class loader to use for instantiating application objects.
If not specified, the context class loader, or the class loader
used to load Digester itself, is used, based on the value of the
useContextClassLoader variable.
- Whether or not to use the Context ClassLoader when loading classes
for instantiating new objects. Default is
false .
- Construct a
Validator that will
use the ValidatorResources
passed in to retrieve pluggable validators
the different sets of validation rules.
- Parameters:
resources - ValidatorResources
to use during validation.
public ( resources,
java.lang.String formName)
- Construct a
Validator that will
use the ValidatorResources
passed in to retrieve pluggable validators
the different sets of validation rules.
- Parameters:
resources - ValidatorResources
to use during validation.formName - Key used for retrieving the set of
validation rules.
public void (java.lang.String key,
java.lang.Object value)
- Add a resource to be used during the processing
of validations.
- Parameters:
key - The full class name of the parameter
of the validation method that
corresponds to the value/instance
passed in with it.value - The instance that will be passed
into the validation method.
public java.lang.Object (java.lang.String key)
- Get a resource to be used during the processing
of validations.
- Parameters:
key - The full class name of the parameter
of the validation method that
corresponds to the value/instance
passed in with it.
public java.lang.String ()
- Gets the form name which is the key
to a set of validation rules.
public void (java.lang.String formName)
- Sets the form name which is the key
to a set of validation rules.
- Gets the page. This in conjunction with
the page property of a
Field
can control the processing of fields.
If the field's page is less than or equal
to this page value, it will be processed.
- Sets the page. This in conjunction with
the page property of a
Field
can control the processing of fields.
If the field's page is less than or equal
to this page value, it will be processed.
- Clears the form name, resources that were added,
and the page that was set (if any). This can
be called to reinitialize the Validator instance
so it can be reused. The form name (key to
set of validation rules) and any resources needed,
like the JavaBean being validated, will need to
set and/or added to this instance again. The
ValidatorResources will not be removed
since it can be used again and is thread safe.
- Return the boolean as to whether the context classloader should be used.
public void (boolean use)
- Determine whether to use the Context ClassLoader (the one found by
calling
Thread.currentThread().getContextClassLoader() )
to resolve/load classes that are defined in various rules. If not
using Context ClassLoader, then the class-loading defaults to
using the calling-class' ClassLoader.
public java.lang.ClassLoader ()
- Return the class loader to be used for instantiating application objects
when required. This is determined based upon the following rules:
- The class loader set by
setClassLoader() , if any
- The thread context class loader, if it exists and the
useContextClassLoader property is set to true
- The class loader used to load the Digester class itself.
public void (java.lang.ClassLoader classLoader)
- Set the class loader to be used for instantiating application objects
when required.
- Parameters:
classLoader - The new class loader to use, or null
to revert to the standard rules
private boolean ( field,
va,
results,
java.util.Map actions,
int pos)
throws
- Executes the given ValidatorAction and all ValidatorActions that it depends on.
- Returns:
- True if the validation succeeded.
ValidatorException
private void ( field,
allResults)
throws
- Run the validations on a given field, modifying the passed
ValidatorResults to add in any new errors found. If the
field is indexed, run all the validations in the depends
clause over each item in turn, returning when the first one fails.
If it's non-indexed, just run it on the field.
ValidatorException
- Performs validations based on the configured resources.
- Returns:
- The
Map returned uses the property
of the Field for the key and the value
is the number of error the field had.
ValidatorException
private boolean (java.lang.Object result)
- Returns if the result if valid. If the
result object is
Boolean , then it will
the value. If the result object isn't Boolean ,
then it will return false if the result
object is null and true if it
isn't.
Copyright (c) 2001-2002 - Apache Software Foundation
|