public class ValidatorAction extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
private String |
classname
The full class name of the class containing
the validation method associated with this action.
|
private List |
dependencyList
An internal List representation of the other
ValidatorAction s
this one depends on (if any). |
private String |
depends
The other
ValidatorAction s that this one depends on. |
private Object |
instance
If the java method matching the correct signature isn't static, the
instance is stored in the action.
|
private String |
javascript
An optional field to containing a JavaScript representation of the
java method assocated with this action.
|
private String |
jsFunction
An optional field to contain the class path to be used to retrieve the
JavaScript function.
|
private String |
jsFunctionName
An optional field to contain the name to be used if JavaScript is
generated.
|
private org.apache.commons.logging.Log |
log
Logger.
|
private String |
method
The full method name of the validation to be performed.
|
private List |
methodParameterList
An internal List representation of all the validation method's
parameters defined in the methodParams String.
|
private String |
methodParams
The method signature of the validation method.
|
private String |
msg
The default error message associated with this action.
|
private String |
name
The name of the validation.
|
private Class[] |
parameterClasses
The Class objects for each entry in methodParameterList.
|
private Class |
validationClass
The Class object loaded from the classname.
|
private Method |
validationMethod
The Method object loaded from the method name.
|
Constructor and Description |
---|
ValidatorAction() |
Modifier and Type | Method and Description |
---|---|
(package private) boolean |
executeValidationMethod(Field field,
Map params,
ValidatorResults results,
int pos)
Dynamically runs the validation method for this validator and returns
true if the data is valid.
|
private String |
formatJavascriptFileName() |
private String |
generateJsFunction()
Used to generate the javascript name when it is not specified.
|
private ClassLoader |
getClassLoader(Map params)
Returns the ClassLoader set in the Validator contained in the parameter
Map.
|
String |
getClassname()
Gets the class of the validator action.
|
List |
getDependencyList()
Returns the dependent validator names as an unmodifiable
List . |
String |
getDepends()
Gets the dependencies of the validator action as a comma separated list
of validator names.
|
String |
getJavascript()
Gets the Javascript equivalent of the java class and method
associated with this action.
|
String |
getJsFunctionName()
Gets the Javascript function name.
|
private org.apache.commons.logging.Log |
getLog()
Accessor method for Log instance.
|
String |
getMethod()
Gets the name of method being called for the validator action.
|
String |
getMethodParams()
Gets the method parameters for the method.
|
String |
getMsg()
Gets the message associated with the validator action.
|
String |
getName()
Gets the name of the validator action.
|
private Object[] |
getParameterValues(Map params)
Converts a List of parameter class names into their values contained in
the parameters Map.
|
private Object |
getValidationClassInstance()
Return an instance of the validation class or null if the validation
method is static so does not require an instance to be executed.
|
private void |
handleIndexedField(Field field,
int pos,
Object[] paramValues)
Modifies the paramValue array with indexed fields.
|
protected void |
init()
Initialize based on set.
|
boolean |
isDependency(String validatorName)
Checks whether or not the value passed in is in the depends field.
|
private boolean |
isValid(Object result)
If the result object is a
Boolean , it will return its
value. |
private boolean |
javascriptAlreadyLoaded() |
protected void |
loadJavascriptFunction()
Load the javascript function specified by the given path.
|
private void |
loadParameterClasses(ClassLoader loader)
Converts a List of parameter class names into their Class objects.
|
private void |
loadValidationClass(ClassLoader loader)
Load the Class object for the configured validation class name.
|
private void |
loadValidationMethod()
Load the Method object for the configured validation method name.
|
private boolean |
onlyReturnErrors(Map params)
Returns the onlyReturnErrors setting in the Validator contained in the
parameter Map.
|
private String |
readJavascriptFile(String javascriptFileName)
Read a javascript function from a file.
|
void |
setClassname(String classname)
Sets the class of the validator action.
|
void |
setDepends(String depends)
Sets the dependencies of the validator action.
|
void |
setJavascript(String javascript)
Sets the Javascript equivalent of the java class and method
associated with this action.
|
void |
setJsFunction(String jsFunction)
Sets the fully qualified class path of the Javascript function.
|
void |
setJsFunctionName(String jsFunctionName)
Sets the Javascript function name.
|
void |
setMethod(String method)
Sets the name of method being called for the validator action.
|
void |
setMethodParams(String methodParams)
Sets the method parameters for the method.
|
void |
setMsg(String msg)
Sets the message associated with the validator action.
|
void |
setName(String name)
Sets the name of the validator action.
|
String |
toString()
Returns a string representation of the object.
|
private transient org.apache.commons.logging.Log log
private String name
private String classname
private Class validationClass
private String method
private Method validationMethod
private String methodParams
The method signature of the validation method. This should be a comma delimited list of the full class names of each parameter in the correct order that the method takes.
Note: java.lang.Object
is reserved for the
JavaBean that is being validated. The ValidatorAction
and Field
that are associated with a field's
validation will automatically be populated if they are
specified in the method signature.
private Class[] parameterClasses
private String depends
ValidatorAction
s that this one depends on. If
any errors occur in an action that this one depends on, this action will
not be processsed.private String msg
private String jsFunctionName
private String jsFunction
private String javascript
private Object instance
private List dependencyList
ValidatorAction
s
this one depends on (if any). This List gets updated
whenever setDepends() gets called. This is synchronized so a call to
setDepends() (which clears the List) won't interfere with a call to
isDependency().private List methodParameterList
public String getName()
public void setName(String name)
name
- Validator Action name.public String getClassname()
public void setClassname(String classname)
classname
- Class name of the validator Action.public String getMethod()
public void setMethod(String method)
method
- The method name.public String getMethodParams()
public void setMethodParams(String methodParams)
methodParams
- A comma separated list of parameters.public String getDepends()
public void setDepends(String depends)
depends
- A comma separated list of validator names.public String getMsg()
public void setMsg(String msg)
msg
- The message for the validator action.public String getJsFunctionName()
public void setJsFunctionName(String jsFunctionName)
jsFunctionName
- The Javascript function name.public void setJsFunction(String jsFunction)
This is optional and can be used instead of the setJavascript().
Attempting to call both setJsFunction
and setJavascript
will result in an IllegalStateException
being thrown.
If neither setJsFunction or setJavascript is set then validator will attempt to load the default javascript definition.
Examples If in the validator.xml : #1: <validator name="tire" jsFunction="com.yourcompany.project.tireFuncion"> Validator will attempt to load com.yourcompany.project.validateTireFunction.js from its class path. #2: <validator name="tire"> Validator will use the name attribute to try and load org.apache.commons.validator.javascript.validateTire.js which is the default javascript definition.
jsFunction
- The Javascript function's fully qualified class path.public String getJavascript()
public void setJavascript(String javascript)
javascript
- The Javascript validation.protected void init()
protected void loadJavascriptFunction()
jsFunction
property should contain a
fully qualified package and script name, separated by periods, to be
loaded from the class loader that created this instance.
TODO if the path begins with a '/' the path will be intepreted as
absolute, and remain unchanged. If this fails then it will attempt to
treat the path as a file path. It is assumed the script ends with a
'.js'.private String readJavascriptFile(String javascriptFileName)
javascriptFileName
- The file containing the javascript.private String formatJavascriptFileName()
private boolean javascriptAlreadyLoaded()
private String generateJsFunction()
public boolean isDependency(String validatorName)
validatorName
- Name of the dependency to check.public List getDependencyList()
List
.public String toString()
boolean executeValidationMethod(Field field, Map params, ValidatorResults results, int pos) throws ValidatorException
field
- params
- A Map of class names to parameter values.results
- pos
- The index of the list property to validate if it's indexed.ValidatorException
private void loadValidationMethod() throws ValidatorException
ValidatorException
private void loadValidationClass(ClassLoader loader) throws ValidatorException
loader
- The ClassLoader used to load the Class object.ValidatorException
private void loadParameterClasses(ClassLoader loader) throws ValidatorException
ValidatorException
- if a class cannot be loaded.private Object[] getParameterValues(Map params)
params
- A Map of class names to parameter values.private Object getValidationClassInstance() throws ValidatorException
ValidatorException
private void handleIndexedField(Field field, int pos, Object[] paramValues) throws ValidatorException
field
- pos
- paramValues
- ValidatorException
private boolean isValid(Object result)
Boolean
, it will return its
value. If not it will return false
if the object is
null
and true
if it isn't.private ClassLoader getClassLoader(Map params)
private boolean onlyReturnErrors(Map params)
private org.apache.commons.logging.Log getLog()
Copyright (c) 2001-2004 Apache Software Foundation