Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
org.apache.commons.validator.Field
public class Field
extends java.lang.Object
implements Cloneable, Serializable
Form
Field Summary | |
private static String |
|
protected static String |
|
static String |
|
protected static String |
|
protected static String |
|
protected Map[] |
|
private List |
|
protected String |
|
protected int |
|
protected FastHashMap |
|
protected FastHashMap |
|
protected String |
|
protected String |
|
protected String |
|
protected int |
|
protected String |
|
Method Summary | |
void | |
void | |
void |
|
void | |
Object |
|
private void |
|
private void |
|
void |
|
Arg |
|
Arg |
|
Arg[] |
|
List |
|
String |
|
int |
|
String |
|
String |
|
(package private) Object[] |
|
private int |
|
String |
|
Msg |
|
Map |
|
String |
|
protected Map |
|
int |
|
String |
|
Var |
|
protected Map |
|
String |
|
Map |
|
private void |
|
boolean |
|
boolean |
|
(package private) void |
|
private void |
|
private void |
|
private void |
|
private boolean |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
void |
|
String |
|
ValidatorResults |
|
private boolean |
|
private static final String DEFAULT_ARG
This is the value that will be used as a key if theArg
name field has no value.
protected static final String TOKEN_END
The end of a token.
public static final String TOKEN_INDEXED
This indicates an indexed property is being referenced.
protected static final String TOKEN_START
The start of a token.
protected static final String TOKEN_VAR
A Vriable token.
protected Map[] args
Holds Maps of arguments. args[0] returns the Map for the first replacement argument. Start with a 0 length array so that it will only grow to the size of the highest argument position.
- Since:
- Validator 1.1
private List dependencyList
Internal representation of this.depends String as a List. This List gets updated whenever setDepends() gets called. This List is synchronized so a call to setDepends() (which clears the List) won't interfere with a call to isDependency().
protected String depends
A comma separated list of validator's this field depends on.
protected int fieldOrder
The order of the Field in the Form.
protected FastHashMap hMsgs
Deprecated. Subclasses should use getMsgMap() instead.
protected FastHashMap hVars
Deprecated. Subclasses should use getVarMap() instead.
protected String indexedListProperty
The Field's indexed list property name.
protected String indexedProperty
The Field's indexed property name.
protected String key
The Field's unique key.
protected int page
The Page Number
protected String property
The Field's property name.
public void addArg(Arg arg)
Add anArg
to the replacement argument list.
- Parameters:
arg
- Validation message's argument.
- Since:
- Validator 1.1
public void addVar(String name, String value, String jsType)
Add aVar
, based on the values passed in, to theField
.
- Parameters:
name
- Name of the validation.value
- The Argument's value.jsType
- The Javascript type.
public Object clone()
Creates and returns a copy of this object.
- Returns:
- A copy of the Field.
private void ensureArgsCapacity(Arg arg)
Ensures that the args array can hold the given arg. Resizes the array as necessary.
- Parameters:
arg
- Determine if the args array is long enough to store this arg's position.
public void generateKey()
Generate correctkey
value.
public Arg getArg(String key, int position)
Gets theArg
object at the given position. If the key finds anull
value then the default value will be retrieved.
- Parameters:
key
- The name the Arg is stored under. If not found, the default Arg for the given position (if any) will be retrieved.position
- The Arg number to find.
- Returns:
- The Arg with the given name and position or null if not found.
- Since:
- Validator 1.1
public Arg getArg(int position)
Gets the defaultArg
object at the given position.
- Parameters:
position
- Validation message argument's position.
- Returns:
- The default Arg or null if not found.
- Since:
- Validator 1.1
public Arg[] getArgs(String key)
Retrieves the Args for the given validator name.
- Parameters:
key
- The validator's args to retrieve.
- Returns:
- An Arg[] sorted by the Args' positions (i.e. the Arg at index 0 has a position of 0).
- Since:
- Validator 1.1.1
public List getDependencyList()
Gets an unmodifiableList
of the dependencies in the same order they were defined in parameter passed to the setDepends() method.
- Returns:
- A list of the Field's dependancies.
public String getDepends()
Gets the validation rules for this field as a comma separated list.
- Returns:
- A comma separated list of validator names.
public int getFieldOrder()
Gets the position of theField
in the validation list.
- Returns:
- The field position.
public String getIndexedListProperty()
Gets the indexed property name of the field. This is the method name that will return an array or aCollection
used to retrieve the list and then loop through the list performing the specified validations.
- Returns:
- The field's indexed List property name.
public String getIndexedProperty()
Gets the indexed property name of the field. This is the method name that can take anint
as a parameter for indexed property value retrieval.
- Returns:
- The field's indexed property name.
(package private) Object[] getIndexedProperty(Object bean) throws ValidatorException
Returns an indexed property from the object we're validating.
- Parameters:
bean
- The bean to extract the indexed values from.
- Throws:
ValidatorException
- If there's an error looking up the property or, the property found is not indexed.
private int getIndexedPropertySize(Object bean) throws ValidatorException
Returns the size of an indexed property from the object we're validating.
- Parameters:
bean
- The bean to extract the indexed values from.
- Throws:
ValidatorException
- If there's an error looking up the property or, the property found is not indexed.
public String getKey()
Gets a unique key based on the property and indexedProperty fields.
- Returns:
- a unique key for the field.
public Msg getMessage(String key)
Retrieve a message object.
- Parameters:
key
- Validation key.
- Returns:
- A validation message for a specified validator.
- Since:
- Validator 1.1.4
public Map getMessages()
TheField
's messages are returned as an unmodifiableMap
.
- Returns:
- Map of validation messages for the field.
- Since:
- Validator 1.1.4
public String getMsg(String key)
Retrieve a message value.
- Parameters:
key
- Validation key.
- Returns:
- A validation message for a specified validator.
protected Map getMsgMap()
Returns a Map of String Msg names to Msg objects.
- Returns:
- A Map of the Field's messages.
- Since:
- Validator 1.2.0
public int getPage()
Gets the page value that the Field is associated with for validation.
- Returns:
- The page number.
public String getProperty()
Gets the property name of the field.
- Returns:
- The field's property name.
public Var getVar(String mainKey)
Retrieve a variable.
- Parameters:
mainKey
- The Variable's key
- Returns:
- the Variable
protected Map getVarMap()
Returns a Map of String Var names to Var objects.
- Returns:
- A Map of the Field's variables.
- Since:
- Validator 1.2.0
public String getVarValue(String mainKey)
Retrieve a variable's value.
- Parameters:
mainKey
- The Variable's key
- Returns:
- the Variable's value
public Map getVars()
TheField
's variables are returned as an unmodifiableMap
.
- Returns:
- the Map of Variable's for a Field.
private void handleMissingAction(String name) throws ValidatorException
Called when a validator name is used in a depends clause but there is no know ValidatorAction configured for that name.
- Parameters:
name
- The name of the validator in the depends list.
- Throws:
ValidatorException
-
public boolean isDependency(String validatorName)
Checks if the validator is listed as a dependency.
- Parameters:
validatorName
- Name of the validator to check.
- Returns:
- Whether the field is dependant on a validator.
public boolean isIndexed()
If there is a value specified for the indexedProperty field thentrue
will be returned. Otherwise it will befalse
.
- Returns:
- Whether the Field is indexed.
(package private) void process(Map globalConstants, Map constants)
Replace constants with values in fields and process the depends field to create the dependencyMap
.
private void processArg(String key, String replaceValue)
Replace the argCollection
key value with the key/value pairs passed in.
private void processMessageComponents(String key, String replaceValue)
Replace the args key value with the key/value pairs passed in.
private void processVars(String key, String replaceValue)
Replace the vars value with the key/value pairs passed in.
private boolean runDependentValidators(ValidatorAction va, ValidatorResults results, Map actions, Map params, int pos) throws ValidatorException
Calls all of the validators that this validator depends on. TODO ValidatorAction should know how to run its own dependencies.
- Parameters:
va
- Run dependent validators for this action.results
-actions
-pos
-
- Returns:
- true if all of the dependent validations passed.
- Throws:
ValidatorException
- If there's an error running a validator
public void setDepends(String depends)
Sets the validation rules for this field as a comma separated list.
- Parameters:
depends
- A comma separated list of validator names.
public void setFieldOrder(int fieldOrder)
Sets the position of theField
in the validation list.
- Parameters:
fieldOrder
- The field position.
public void setIndexedListProperty(String indexedListProperty)
Sets the indexed property name of the field.
- Parameters:
indexedListProperty
- The field's indexed List property name.
public void setIndexedProperty(String indexedProperty)
Sets the indexed property name of the field.
- Parameters:
indexedProperty
- The field's indexed property name.
public void setKey(String key)
Sets a unique key for the field. This can be used to change the key temporarily to have a unique key for an indexed field.
- Parameters:
key
- a unique key for the field
public void setPage(int page)
Sets the page value that the Field is associated with for validation.
- Parameters:
page
- The page number.
public void setProperty(String property)
Sets the property name of the field.
- Parameters:
property
- The field's property name.
public String toString()
Returns a string representation of the object.
- Returns:
- A string representation of the object.
public ValidatorResults validate(Map params, Map actions) throws ValidatorException
Run the configured validations on this field. Run all validations in the depends clause over each item in turn, returning when the first one fails.
- Parameters:
params
- A Map of parameter class names to parameter values to pass into validation methods.actions
- A Map of validator names to ValidatorAction objects.
- Returns:
- A ValidatorResults object containing validation messages for this field.
- Throws:
ValidatorException
- If an error occurs during validation.
private boolean validateForRule(ValidatorAction va, ValidatorResults results, Map actions, Map params, int pos) throws ValidatorException
Executes the given ValidatorAction and all ValidatorActions that it depends on.
- Returns:
- true if the validation succeeded.