org.apache.commons.validator
クラス Validator

java.lang.Object
  拡張org.apache.commons.validator.Validator
すべての実装インタフェース:
Serializable

public class Validator
extends Object
implements Serializable

妥当性チェック処理を行います。 ValidatorResources インスタンスを妥当性チェック処理と JavaBean に適用するチェックルールの定義に使用します。

バージョン:
$Revision: 1.1.1.1 $ $Date: 2004/02/13 10:02:01 $
作成者:
David Winterfeldt, James Turner, David Graham
関連項目:
直列化された形式
翻訳者:
日置 聡

フィールドの概要
static String BEAN_KEY
          Resources key the JavaBean is stored to perform validation on.
protected  ClassLoader classLoader
          The class loader to use for instantiating application objects.
static String FIELD_KEY
          Resources key the Field is stored under.
protected  String formName
           
protected  HashMap hResources
           
static 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 String VALIDATOR_ACTION_KEY
          Resources key the ValidatorAction is stored under.
static String VALIDATOR_KEY
          Resources key the Validator is stored under.
 
コンストラクタの概要
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, String formName)
          Construct a Validator that will use the ValidatorResources passed in to retrieve pluggable validators the different sets of validation rules.
 
メソッドの概要
 void addResource(String key, 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).
 ClassLoader getClassLoader()
          Return the class loader to be used for instantiating application objects when required.
 String getFormName()
          Gets the form name which is the key to a set of validation rules.
 int getPage()
          Gets the page.
 Object getResource(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(Object result)
          Returns if the result if valid.
 void setClassLoader(ClassLoader classLoader)
          Set the class loader to be used for instantiating application objects when required.
 void setFormName(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, Map actions, int pos)
          Executes the given ValidatorAction and all ValidatorActions that it depends on.
 
クラス java.lang.Object から継承したメソッド
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

フィールドの詳細

log

protected static org.apache.commons.logging.Log log
Logger


BEAN_KEY

public static String BEAN_KEY
Resources key the JavaBean is stored to perform validation on.


VALIDATOR_ACTION_KEY

public static String VALIDATOR_ACTION_KEY
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.


FIELD_KEY

public static String FIELD_KEY
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.


VALIDATOR_KEY

public static String VALIDATOR_KEY
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.


LOCALE_KEY

public static String LOCALE_KEY
Resources key the Locale is stored. This will be used to retrieve the appropriate FormSet and Form to be processed.


resources

protected ValidatorResources resources

formName

protected String formName

hResources

protected HashMap hResources

page

protected int page

classLoader

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


useContextClassLoader

protected boolean useContextClassLoader
Whether or not to use the Context ClassLoader when loading classes for instantiating new objects. Default is false.

コンストラクタの詳細

Validator

public Validator(ValidatorResources resources)
Construct a Validator that will use the ValidatorResources passed in to retrieve pluggable validators the different sets of validation rules.

パラメータ:
resources - ValidatorResources to use during validation.

Validator

public Validator(ValidatorResources resources,
                 String formName)
Construct a Validator that will use the ValidatorResources passed in to retrieve pluggable validators the different sets of validation rules.

パラメータ:
resources - ValidatorResources to use during validation.
formName - Key used for retrieving the set of validation rules.
メソッドの詳細

addResource

public void addResource(String key,
                        Object value)
Add a resource to be used during the processing of validations.

パラメータ:
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.

getResource

public Object getResource(String key)
Get a resource to be used during the processing of validations.

パラメータ:
key - The full class name of the parameter of the validation method that corresponds to the value/instance passed in with it.

getFormName

public String getFormName()
Gets the form name which is the key to a set of validation rules.


setFormName

public void setFormName(String formName)
Sets the form name which is the key to a set of validation rules.


getPage

public int getPage()
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.


setPage

public void setPage(int page)
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.


clear

public void clear()
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.


getUseContextClassLoader

public boolean getUseContextClassLoader()
Return the boolean as to whether the context classloader should be used.


setUseContextClassLoader

public 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. If not using Context ClassLoader, then the class-loading defaults to using the calling-class' ClassLoader.

パラメータ:
use - determines whether to use Context ClassLoader.

getClassLoader

public ClassLoader getClassLoader()
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.


setClassLoader

public void setClassLoader(ClassLoader classLoader)
Set the class loader to be used for instantiating application objects when required.

パラメータ:
classLoader - The new class loader to use, or null to revert to the standard rules

validateFieldForRule

private boolean validateFieldForRule(Field field,
                                     ValidatorAction va,
                                     ValidatorResults results,
                                     Map actions,
                                     int pos)
                              throws ValidatorException
Executes the given ValidatorAction and all ValidatorActions that it depends on.

戻り値:
True if the validation succeeded.
例外:
ValidatorException

validateField

private void validateField(Field field,
                           ValidatorResults allResults)
                    throws ValidatorException
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

validate

public ValidatorResults validate()
                          throws ValidatorException
Performs validations based on the configured resources.

戻り値:
The Map returned uses the property of the Field for the key and the value is the number of error the field had.
例外:
ValidatorException

isValid

private boolean isValid(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.



このドキュメントは、Ja-Jakartaにより訳されました。 コメントがある場合は report@jajakarta.orgまでお願いします。
Translated into Japanese by jajakarta.org. The original page is here.
Copyright (c) 2002-2003 - Apache Software Foundation