com.ibm.tws.objects.validator
Class Validator

java.lang.Object
  extended bycom.ibm.tws.objects.validator.Validator
Direct Known Subclasses:
ModelValidator

public class Validator
extends java.lang.Object

This class is the root of all validator classes, and provides common utility methods that can be invoked by subclasses to check the validity of allowed lengths, ranges and other rules on object fields.


Field Summary
static java.lang.String COPYRIGHT
          Copyright.
 
Constructor Summary
protected Validator(java.util.Locale locale)
          Creates a new Validator, using the specified locale for error messages.
 
Method Summary
protected  void checkAlphabetic(java.lang.String field, java.lang.String value, java.lang.String allowed)
          Checks that the string specified for the given field includes only alphabetic characters.
protected  void checkAlphaNumeric(java.lang.String field, java.lang.String value, java.lang.String allowed)
          Checks that the string specified for the given field includes only alphanumeric characters.
protected  void checkComparison(java.lang.String field1, java.util.Date value1, java.lang.String field2, java.util.Date value2)
          Checks that the date values specified for the given fields meet a comparison constraint.
protected  void checkComparison(java.lang.String field1, int value1, java.lang.String field2, int value2)
          Checks that the integer values specified for the given fields meet a comparison constraint.
protected  void checkComparison(java.lang.String field1, long value1, java.lang.String field2, long value2)
          Checks that the long integer values specified for the given fields meet a comparison constraint.
protected  void checkConstraint(java.util.List masterFields, java.util.List masterValues, java.util.List masterChecks, java.util.List masterEquals, java.lang.String slaveField, java.lang.Object slaveValue, java.lang.Object slaveCheck, boolean slaveEquals)
          Checks that the value of a "slave" field is compliant with the constraint defined by the value of one or more "master" fields.
protected  void checkConstraint(java.lang.String masterField, java.lang.Object masterValue, java.lang.Object masterCheck, boolean masterEquals, java.lang.String slaveField, java.lang.Object slaveValue, java.lang.Object slaveCheck, boolean slaveEquals)
          Checks that the value of a "slave" field is compliant with the constraint defined by the value of a "master" field.
protected  void checkFilter(QueryFilter filter, java.lang.String name, java.lang.Class type, boolean isNullable)
          Checks that the value specified for a query filter element is an instance of the expected class.
protected  void checkInstanceOf(java.lang.String field, java.lang.Object value, java.lang.Class type)
          Checks that the object specified for the given field is an instance of the expected class.
protected  void checkInternetAddress(java.lang.String field, java.lang.String value)
          Checks that the string specified for the given field includes a valid internet address.
protected  void checkLength(java.lang.String field, java.lang.String value, int maxLength)
          Checks that the string specified for the given field does not exceed the specified length.
protected  void checkListFilter(QueryFilter filter, java.lang.String name, java.lang.Class type, boolean isNullable)
          Checks that the values specified for a query filter element of type List are correct.
protected  void checkNotAllowedChars(java.lang.String field, java.lang.String value, java.lang.String notAllowed)
          Checks that the string specified for the given field does not include not allowed characters.
protected  void checkNotAllowedStart(java.lang.String field, java.lang.String value, java.lang.String notAllowed)
          Checks that the string specified for the given field does not start with a not allowed character.
protected  void checkNotNull(java.util.List fields, java.util.List values)
          Checks that at least one of the values specified for the given fields is not null.
protected  void checkNotNull(java.lang.String field, int value)
          Checks that the integer specified for the given field is not null.
protected  void checkNotNull(java.lang.String field, long value)
          Checks that the long integer specified for the given field is not null.
protected  void checkNotNull(java.lang.String field, java.lang.Object value)
          Checks that the value specified for the given field is not null.
protected  void checkNotNull(java.lang.String field, java.lang.String value)
          Checks that the text value specified for the given field is not null.
protected  void checkNumeric(java.lang.String field, java.lang.String value, java.lang.String allowed)
          Checks that the string specified for the given field includes only numeric characters.
protected  void checkRange(java.lang.String field, java.util.Date value, java.util.Date start, java.util.Date end)
          Checks that the date specified for the given field is within the specified range.
protected  void checkRange(java.lang.String field, int value, int start, int end)
          Checks that the integer specified for the given field is within the specified range.
protected  void checkRange(java.lang.String field, long value, long start, long end)
          Checks that the long integer specified for the given field is within the specified range.
protected  void checkStartWithAlphabetic(java.lang.String field, java.lang.String value, java.lang.String allowed)
          Checks that the string specified for the given field starts with an alphabetic character.
protected  void checkStartWithAlphaNumeric(java.lang.String field, java.lang.String value, java.lang.String allowed)
          Checks that the string specified for the given field starts with an alphanumeric character.
protected  void checkStartWithNumeric(java.lang.String field, java.lang.String value, java.lang.String allowed)
          Checks that the string specified for the given field starts with a numeric character.
protected  void checkValue(java.lang.String field, int value, int invalid)
          Checks that the integer specified for the given field is not equal to the specified invalid value.
protected  void checkValue(java.lang.String field, long value, long invalid)
          Checks that the long integer specified for the given field is not equal to the specified invalid value.
protected  void checkValue(java.lang.String field, java.lang.Object value, java.lang.Object invalid)
          Checks that the object specified for the given field is not equal to the specified invalid value.
protected  int getLength(java.lang.String value)
          Returns the length of the specified string.
protected  java.util.Locale getLocale()
          Returns the locale used by this validator to generate error messages.
protected  java.lang.String getLocalizedField(java.lang.String field)
          Returns the localized text to be shown for the specified field name.
protected  java.lang.String getLocalizedValue(java.lang.Object value)
          Returns the localized text to be shown for the specified field value.
 java.lang.String getObjectName()
          Returns the name of the object for which this validator is working.
 void setObjectName(java.lang.String value)
          Sets the name of the object for which this validator is working.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
Copyright.

Constructor Detail

Validator

protected Validator(java.util.Locale locale)
Creates a new Validator, using the specified locale for error messages.

Parameters:
locale - The locale requested for error messages.
Method Detail

getObjectName

public java.lang.String getObjectName()
Returns the name of the object for which this validator is working.

Returns:
The name of the object for which this validator is working.

setObjectName

public void setObjectName(java.lang.String value)
Sets the name of the object for which this validator is working.

Parameters:
value - The name of the object for which this validator is working.

checkNotNull

protected void checkNotNull(java.lang.String field,
                            java.lang.Object value)
                     throws NullValidatorException
Checks that the value specified for the given field is not null.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
Throws:
NullValidatorException - The specified value is null.

checkNotNull

protected void checkNotNull(java.lang.String field,
                            java.lang.String value)
                     throws NullValidatorException
Checks that the text value specified for the given field is not null.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
Throws:
NullValidatorException - The specified text value is null.

checkNotNull

protected void checkNotNull(java.lang.String field,
                            int value)
                     throws NullValidatorException
Checks that the integer specified for the given field is not null.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
Throws:
NullValidatorException - The specified integer is null.

checkNotNull

protected void checkNotNull(java.lang.String field,
                            long value)
                     throws NullValidatorException
Checks that the long integer specified for the given field is not null.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
Throws:
NullValidatorException - The specified long integer is null.

checkNotNull

protected void checkNotNull(java.util.List fields,
                            java.util.List values)
                     throws NullValidatorException
Checks that at least one of the values specified for the given fields is not null.

Parameters:
fields - A list of the names of the fields that cannot be null at the same time.
values - A list of the values of the fields that cannot be null at the same time.
Throws:
NullValidatorException - All the specified values are null.

checkInstanceOf

protected void checkInstanceOf(java.lang.String field,
                               java.lang.Object value,
                               java.lang.Class type)
                        throws InstanceValidatorException
Checks that the object specified for the given field is an instance of the expected class.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
type - The expected class for the given field.
Throws:
InstanceValidatorException - The specified object is not an instance of the expected class.

checkFilter

protected void checkFilter(QueryFilter filter,
                           java.lang.String name,
                           java.lang.Class type,
                           boolean isNullable)
                    throws FilterValidatorException
Checks that the value specified for a query filter element is an instance of the expected class.

Parameters:
filter - The query filter including all filter elements.
name - The name of the filter element to be checked.
type - The expected class for the given filter element.
isNullable - True if null values are allowed in addition to objects of the given type.
Throws:
FilterValidatorException - The current value of the filter element is not allowed.

checkListFilter

protected void checkListFilter(QueryFilter filter,
                               java.lang.String name,
                               java.lang.Class type,
                               boolean isNullable)
                        throws FilterValidatorException
Checks that the values specified for a query filter element of type List are correct.

Parameters:
filter - The query filter including all filter elements.
name - The name of the filter element of type List to be checked.
type - The expected class for every object in the list.
isNullable - True if null values are allowed in addition to objects of the given type.
Throws:
FilterValidatorException - The current value of the filter element is not allowed.

getLength

protected int getLength(java.lang.String value)
Returns the length of the specified string.

Parameters:
value - The string whose length must be calculated.
Returns:
The length of the specified string, or -1 if the string is null.

checkLength

protected void checkLength(java.lang.String field,
                           java.lang.String value,
                           int maxLength)
                    throws LengthValidatorException
Checks that the string specified for the given field does not exceed the specified length.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
maxLength - The allowed maximum length for the given field.
Throws:
LengthValidatorException - The specified string exceeds the allowed maximum length.

checkAlphabetic

protected void checkAlphabetic(java.lang.String field,
                               java.lang.String value,
                               java.lang.String allowed)
                        throws CharValidatorException
Checks that the string specified for the given field includes only alphabetic characters.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
allowed - A string including the characters allowed in addition to alphabetic ones, if any.
Throws:
CharValidatorException - An invalid character was found in the specified string.

checkNumeric

protected void checkNumeric(java.lang.String field,
                            java.lang.String value,
                            java.lang.String allowed)
                     throws CharValidatorException
Checks that the string specified for the given field includes only numeric characters.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
allowed - A string including the characters allowed in addition to numeric ones, if any.
Throws:
CharValidatorException - An invalid character was found in the specified string.

checkAlphaNumeric

protected void checkAlphaNumeric(java.lang.String field,
                                 java.lang.String value,
                                 java.lang.String allowed)
                          throws CharValidatorException
Checks that the string specified for the given field includes only alphanumeric characters.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
allowed - A string including the characters allowed in addition to alphanumeric ones, if any.
Throws:
CharValidatorException - An invalid character was found in the specified string.

checkInternetAddress

protected void checkInternetAddress(java.lang.String field,
                                    java.lang.String value)
                             throws AddressValidatorException
Checks that the string specified for the given field includes a valid internet address.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
Throws:
AddressValidatorException - An invalid internet address was found in the specified string.

checkNotAllowedChars

protected void checkNotAllowedChars(java.lang.String field,
                                    java.lang.String value,
                                    java.lang.String notAllowed)
                             throws CharValidatorException
Checks that the string specified for the given field does not include not allowed characters.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
notAllowed - A string including the characters that are not allowed for the given field.
Throws:
CharValidatorException - An invalid character was found in the specified string.

checkStartWithAlphabetic

protected void checkStartWithAlphabetic(java.lang.String field,
                                        java.lang.String value,
                                        java.lang.String allowed)
                                 throws StartValidatorException
Checks that the string specified for the given field starts with an alphabetic character.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
allowed - A string including the characters allowed in addition to alphabetic ones, if any.
Throws:
StartValidatorException - The specified string does not start as expected.

checkStartWithNumeric

protected void checkStartWithNumeric(java.lang.String field,
                                     java.lang.String value,
                                     java.lang.String allowed)
                              throws StartValidatorException
Checks that the string specified for the given field starts with a numeric character.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
allowed - A string including the characters allowed in addition to numeric ones, if any.
Throws:
StartValidatorException - The specified string does not start as expected.

checkStartWithAlphaNumeric

protected void checkStartWithAlphaNumeric(java.lang.String field,
                                          java.lang.String value,
                                          java.lang.String allowed)
                                   throws StartValidatorException
Checks that the string specified for the given field starts with an alphanumeric character.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
allowed - A string including the characters allowed in addition to alphanumeric ones, if any.
Throws:
StartValidatorException - The specified string does not start as expected.

checkNotAllowedStart

protected void checkNotAllowedStart(java.lang.String field,
                                    java.lang.String value,
                                    java.lang.String notAllowed)
                             throws StartValidatorException
Checks that the string specified for the given field does not start with a not allowed character.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
notAllowed - A string including the characters thar are not allowed as a start of the given field.
Throws:
StartValidatorException - The specified string does not start as expected.

checkRange

protected void checkRange(java.lang.String field,
                          int value,
                          int start,
                          int end)
                   throws RangeValidatorException
Checks that the integer specified for the given field is within the specified range.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
start - The lower bound of the range allowed for the given field.
end - The upper bound of the range allowed for the given field.
Throws:
RangeValidatorException - The specified integer is out of the allowed range.

checkRange

protected void checkRange(java.lang.String field,
                          long value,
                          long start,
                          long end)
                   throws RangeValidatorException
Checks that the long integer specified for the given field is within the specified range.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
start - The lower bound of the range allowed for the given field.
end - The upper bound of the range allowed for the given field.
Throws:
RangeValidatorException - The specified long integer is out of the allowed range.

checkRange

protected void checkRange(java.lang.String field,
                          java.util.Date value,
                          java.util.Date start,
                          java.util.Date end)
                   throws RangeValidatorException
Checks that the date specified for the given field is within the specified range.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
start - The lower bound of the range allowed for the given field.
end - The upper bound of the range allowed for the given field.
Throws:
RangeValidatorException - The specified date is out of the allowed range.

checkValue

protected void checkValue(java.lang.String field,
                          int value,
                          int invalid)
                   throws ValueValidatorException
Checks that the integer specified for the given field is not equal to the specified invalid value.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
invalid - An invalid value for the given field.
Throws:
ValueValidatorException - The specified integer is equal to the invalid value.

checkValue

protected void checkValue(java.lang.String field,
                          long value,
                          long invalid)
                   throws ValueValidatorException
Checks that the long integer specified for the given field is not equal to the specified invalid value.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
invalid - An invalid value for the given field.
Throws:
ValueValidatorException - The specified long integer is equal to the invalid value.

checkValue

protected void checkValue(java.lang.String field,
                          java.lang.Object value,
                          java.lang.Object invalid)
                   throws ValueValidatorException
Checks that the object specified for the given field is not equal to the specified invalid value.

Parameters:
field - The name of the field that is being checked.
value - The value specified for the given field.
invalid - An invalid value for the given field.
Throws:
ValueValidatorException - The specified object is equal to the invalid value.

checkComparison

protected void checkComparison(java.lang.String field1,
                               int value1,
                               java.lang.String field2,
                               int value2)
                        throws ComparisonValidatorException
Checks that the integer values specified for the given fields meet a comparison constraint.

Parameters:
field1 - The name of the first field (the one that must be greater).
value1 - The value of the first field.
field2 - The name of the second field (the one that must be lower).
value2 - The value of the second field.
Throws:
ComparisonValidatorException - The value of the first field is lower than the value of the second field.

checkComparison

protected void checkComparison(java.lang.String field1,
                               long value1,
                               java.lang.String field2,
                               long value2)
                        throws ComparisonValidatorException
Checks that the long integer values specified for the given fields meet a comparison constraint.

Parameters:
field1 - The name of the first field (the one that must be greater).
value1 - The value of the first field.
field2 - The name of the second field (the one that must be lower).
value2 - The value of the second field.
Throws:
ComparisonValidatorException - The value of the first field is lower than the value of the second field.

checkComparison

protected void checkComparison(java.lang.String field1,
                               java.util.Date value1,
                               java.lang.String field2,
                               java.util.Date value2)
                        throws ComparisonValidatorException
Checks that the date values specified for the given fields meet a comparison constraint.

Parameters:
field1 - The name of the first field (the one that must be greater).
value1 - The value of the first field.
field2 - The name of the second field (the one that must be lower).
value2 - The value of the second field.
Throws:
ComparisonValidatorException - The value of the first field is lower than the value of the second field.

checkConstraint

protected void checkConstraint(java.lang.String masterField,
                               java.lang.Object masterValue,
                               java.lang.Object masterCheck,
                               boolean masterEquals,
                               java.lang.String slaveField,
                               java.lang.Object slaveValue,
                               java.lang.Object slaveCheck,
                               boolean slaveEquals)
                        throws ConstraintValidatorException
Checks that the value of a "slave" field is compliant with the constraint defined by the value of a "master" field. The constraint is triggered when the current value of the master field is equal to or different than its check value (depending on the "masterEquals" rule specified for the master field) and defines a value for the slave field that is either mandatory or not allowed (depending on the "slaveEquals" rule specified for the slave field).

Parameters:
masterField - The name of the field that defines the constraint.
masterValue - The current value of the field that defines the constraint.
masterCheck - The value of the master field that constrains the value of the slave field.
masterEquals - True (false) if the constraint is triggered when masterValue is equal to (different than) masterCheck.
slaveField - The name of the field that must comply with the constraint.
slaveValue - The current value of the field that must comply with the constraint.
slaveCheck - A value of the slave field to be compared with the current one.
slaveEquals - True (false) if slaveValue must be equal to (different than) slaveCheck if the constraint is triggered.
Throws:
ConstraintValidatorException - The constraint is violated by the current value of the slave field.

checkConstraint

protected void checkConstraint(java.util.List masterFields,
                               java.util.List masterValues,
                               java.util.List masterChecks,
                               java.util.List masterEquals,
                               java.lang.String slaveField,
                               java.lang.Object slaveValue,
                               java.lang.Object slaveCheck,
                               boolean slaveEquals)
                        throws ConstraintValidatorException
Checks that the value of a "slave" field is compliant with the constraint defined by the value of one or more "master" fields. The constraint is triggered when the current value of each master field is equal to or different than its check value (depending on the "masterEquals" rule specified for the master field) and defines a value for the slave field that is either mandatory or not allowed (depending on the "slaveEquals" rule specified for the slave field).

Parameters:
masterFields - A list of the names of all the fields that define the constraint.
masterValues - A list of the current values of all the fields that define the constraint.
masterChecks - A list of the values of the master fields that constrain the value of the slave field.
masterEquals - True (false) if the constraint is triggered when masterValue is equal to (different than) masterCheck.
slaveField - The name of the field that must comply with the constraint.
slaveValue - The current value of the field that must comply with the constraint.
slaveCheck - A value of the slave field to be compared with the current one.
slaveEquals - True (false) if slaveValue must be equal to (different than) slaveCheck if the constraint is triggered.
Throws:
ConstraintValidatorException - The constraint is violated by the current value of the slave field.

getLocale

protected java.util.Locale getLocale()
Returns the locale used by this validator to generate error messages.

Returns:
The locale used by this validator to generate error messages.

getLocalizedField

protected java.lang.String getLocalizedField(java.lang.String field)
Returns the localized text to be shown for the specified field name.

Parameters:
field - The non-localized field name.
Returns:
The localized field name to be shown in error messages.

getLocalizedValue

protected java.lang.String getLocalizedValue(java.lang.Object value)
Returns the localized text to be shown for the specified field value.

Parameters:
value - The non-localized field value.
Returns:
The localized field value to be shown in error messages.


Copyright © 2005 IBM All Rights Reserved.