toolbox.web.validation
Class AbstractField

Package class diagram package AbstractField
java.lang.Object
  extended by toolbox.web.validation.AbstractField
All Implemented Interfaces:
Field
Direct Known Subclasses:
BooleanField, NumberField, StringField

public abstract class AbstractField
extends java.lang.Object
implements Field

Abstract partial field implementation to provide a convenience base class for implementing fields.

Provide implementations of all Field methods except validate.


Constructor Summary
AbstractField()
          Protected constructor
 
Method Summary
 java.lang.String getDefault()
          Return the string representation of the default value of this field.
 java.lang.String getName()
          Return the name of this field.
 java.util.regex.Pattern getPattern()
          Return the pattern used to identify this field.
 java.util.Properties getProperties()
          Return all the field specific properties.
 java.lang.String getProperty(java.lang.String name)
          Return a field specific property.
 java.lang.String getResourceKey()
          Return the resource key used to lookup the display value of this field.
protected  java.lang.String getResourceString(java.lang.String key, java.lang.Object[] args, java.util.ResourceBundle bundle)
          Return a resource string by formatting the resource string using the provided parameters.
protected  java.lang.String getResourceString(java.lang.String key, java.util.ResourceBundle bundle)
          Return a resource string from the given bundle
 boolean isRequired()
          Indicates whether this field is required or not.
 void setDefault(java.lang.String def)
          Set the string representation of the default value of this field.
 void setName(java.lang.String name)
          Set the name of this field.
 void setPattern(java.util.regex.Pattern pattern)
          Set the pattern used to identify this field.
 void setProperties(java.util.Properties props)
          Set any field specific properties.
 void setRequired(java.lang.Boolean required)
          Set the required flag of this field.
 void setResourceKey(java.lang.String key)
          Set the value of the resource key used to look up the display value of this field.
protected  java.lang.String validateRequired(java.lang.String value, java.util.ResourceBundle bundle)
          Convenience method to perform the "required" validation test.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface toolbox.web.validation.Field
validate
 

Constructor Detail

AbstractField

public AbstractField()
Protected constructor

Method Detail

getName

public java.lang.String getName()
Return the name of this field.

Specified by:
getName in interface Field
Returns:
String containing the name of this field.

setName

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

Specified by:
setName in interface Field
Parameters:
name - String indicating the name of this field.

getResourceKey

public java.lang.String getResourceKey()
Return the resource key used to lookup the display value of this field.

Specified by:
getResourceKey in interface Field
Returns:
String containing the resource key of this field.

setResourceKey

public void setResourceKey(java.lang.String key)
Set the value of the resource key used to look up the display value of this field.

Specified by:
setResourceKey in interface Field
Parameters:
key - String containing resource key.

getPattern

public java.util.regex.Pattern getPattern()
Return the pattern used to identify this field.

Specified by:
getPattern in interface Field
Returns:
Pattern containing regex pattern used to identify this field.

setPattern

public void setPattern(java.util.regex.Pattern pattern)
Set the pattern used to identify this field.

Specified by:
setPattern in interface Field
Parameters:
pattern - Pattern containing the regex pattern used to identify this field.

isRequired

public boolean isRequired()
Indicates whether this field is required or not.

Specified by:
isRequired in interface Field
Returns:
boolean indicating whether this field is required.

setRequired

public void setRequired(java.lang.Boolean required)
Set the required flag of this field.

Specified by:
setRequired in interface Field
Parameters:
required - Flag to indicate whether this field is required.

getDefault

public java.lang.String getDefault()
Return the string representation of the default value of this field.

Specified by:
getDefault in interface Field
Returns:
String representing the default value of this field.

setDefault

public void setDefault(java.lang.String def)
Set the string representation of the default value of this field.

Specified by:
setDefault in interface Field
Parameters:
def - String representation of the default value of this field.

setProperties

public void setProperties(java.util.Properties props)
Set any field specific properties.

Specified by:
setProperties in interface Field
Parameters:
props - Field specific properties.

getProperty

public java.lang.String getProperty(java.lang.String name)
Return a field specific property.

Specified by:
getProperty in interface Field
Parameters:
name - Property name.
Returns:
String containing the value of the field specific property.

getProperties

public java.util.Properties getProperties()
Return all the field specific properties.

Specified by:
getProperties in interface Field
Returns:
Properties instance containing all field specific properties.

getResourceString

protected java.lang.String getResourceString(java.lang.String key,
                                             java.util.ResourceBundle bundle)
Return a resource string from the given bundle

Parameters:
key - The resource key.
bundle - The resource bundle.
Returns:
String containing resource string.

getResourceString

protected java.lang.String getResourceString(java.lang.String key,
                                             java.lang.Object[] args,
                                             java.util.ResourceBundle bundle)
                                      throws ValidationException
Return a resource string by formatting the resource string using the provided parameters.

Parameters:
key - The resource key.
args - Object array of arguments.
bundle - The resource bundle.
Returns:
String containing resource string.
Throws:
ValidationException

validateRequired

protected java.lang.String validateRequired(java.lang.String value,
                                            java.util.ResourceBundle bundle)
                                     throws ValidationException
Convenience method to perform the "required" validation test.

Parameters:
value - String to test.
bundle - ResourceBundle to use for localisation.
Returns:
String representing the value to further validate.
Throws:
ValidationException - if this field is reqiured and the given value is empty/null and no default is available.