com.sas.util.validators
Class CompositeValidator

com.sas.util.validators.CompositeValidator
All Implemented Interfaces:
ValidationInterface, java.io.Serializable
Direct Known Subclasses:
MaximumValueCompositeValidator, MinimumValueCompositeValidator, MinMaxValueCompositeValidator

public class CompositeValidator

CompositeValidator allows the validation of one or more Validators to be chained together such that all need to validate the value for the composite to be valid.

See Also:
ValidationInterface, Validator, Serialized Form

Field Summary
protected  ValidationInterface validator1
           
protected  ValidationInterface validator2
           
protected  java.util.List validators
           
 
Fields inherited from class com.sas.util.validators.Validator
message, messages, msgObject, RB_KEY
 
Constructor Summary
CompositeValidator()
          Default constructor, actuall validators still need to be added to the validator.
CompositeValidator(java.util.List validators)
          Constructor which allows specifying a list of validators to use.
CompositeValidator(ValidationInterface validator1)
          Constructor which allows specifying the first validator.
CompositeValidator(ValidationInterface validator1, ValidationInterface validator2)
          Constructor which allows specifying the first two validators.
 
Method Summary
 void addValidator(ValidationInterface validator)
          Adds a validator to the end of the validation list.
 ValidationInterface getFirstValidator()
          Deprecated. Use getValidatorAtIndex(0) instead
 ValidationInterface getSecondValidator()
          Deprecated. Use getValidatorAtIndex(1) instead
 ValidationInterface getValidatorAtIndex(int index)
          Returns the validator at the specified index, null if index is invalid.
 java.util.List getValidators()
          Returns the list that contains the validators.
 void insertValidatorAtIndex(int index, ValidationInterface validator)
          Inserts the validator at the specified index.
 java.lang.Object normalizeValue(java.lang.Object component, java.lang.Object value)
          Cycles through all the validators starting at index 0 and normalizes the value.
 boolean removeValidator(ValidationInterface validator)
          Removes the validator from the list of validators.
 void removeValidatorAtIndex(int index)
          Removes the validator at the specifed index from the list of validators.
 void setFirstValidator(ValidationInterface firstValidator)
          Deprecated. Use removeValidatorAtIndex(0) and then insertValidatorAtIndex(0, validator) instead
 void setSecondValidator(ValidationInterface secondValidator)
          Deprecated. Use removeValidatorAtIndex(1) and then insertValidatorAtIndex(1, validator) instead
 void setValidators(java.util.List validators)
          Sets the list of validators to use.
 boolean validateValue(java.lang.Object component, java.lang.Object value)
          Cycles through all the validators in the list.
 
Methods inherited from class com.sas.util.validators.Validator
createValidationMessages, getExtendedBeanInfo, getValidationMessage, getValidationMessageCode, newValidationMessage, setValidationMessage, setValidationMessageCode
 

Field Detail

validator1

protected ValidationInterface validator1

validator2

protected ValidationInterface validator2

validators

protected java.util.List validators
Constructor Detail

CompositeValidator

public CompositeValidator()
Default constructor, actuall validators still need to be added to the validator.


CompositeValidator

public CompositeValidator(ValidationInterface validator1)
Constructor which allows specifying the first validator.

Parameters:
validator1 - The first validator to run

CompositeValidator

public CompositeValidator(ValidationInterface validator1,
                          ValidationInterface validator2)
Constructor which allows specifying the first two validators.

Parameters:
validator1 - The first validator to run
validator2 - The second validator to run

CompositeValidator

public CompositeValidator(java.util.List validators)
Constructor which allows specifying a list of validators to use.

Parameters:
validators - The list of validators to run
Method Detail

addValidator

public void addValidator(ValidationInterface validator)
Adds a validator to the end of the validation list.

Parameters:
validator - The validator to append to the end of the validation list.

removeValidator

public boolean removeValidator(ValidationInterface validator)
Removes the validator from the list of validators. Returns true if the validator was successfully removed, false otherwise.

Parameters:
validator - The validator to remove from the list of validators.
Returns:
true if successfully removed, false otherwise

removeValidatorAtIndex

public void removeValidatorAtIndex(int index)
Removes the validator at the specifed index from the list of validators.

Parameters:
index - The index of the validator to remove from the list of validators.

validateValue

public boolean validateValue(java.lang.Object component,
                             java.lang.Object value)
Cycles through all the validators in the list. As soon as one validator determines the value is invalid, the validation process stops and false is return. Otherwise, the validation process starts at the first validator in the list and continues until all validators have validated the value.

Specified by:
validateValue in interface ValidationInterface
Overrides:
validateValue in class Validator
Parameters:
component - an object containing the value
value - the value to be validated
Returns:
true if the value us valid, false if not. If false is returned, the validator should call setValidationMessage with a String for a reason.
See Also:
ValidationInterface.validateValue(java.lang.Object, java.lang.Object)

normalizeValue

public java.lang.Object normalizeValue(java.lang.Object component,
                                       java.lang.Object value)
Cycles through all the validators starting at index 0 and normalizes the value. The value passed into the next validator is the result of the value normalized by the previous validator.

Specified by:
normalizeValue in interface ValidationInterface
Overrides:
normalizeValue in class Validator
Parameters:
component - an object containing the value
value - the value to be normalized
Returns:
the normalized value. This can be the input value or a value drived from it.
See Also:
ValidationInterface.normalizeValue(java.lang.Object, java.lang.Object)

getValidatorAtIndex

public ValidationInterface getValidatorAtIndex(int index)
Returns the validator at the specified index, null if index is invalid. Valid index values are from 0 to number of validators - 1.

Parameters:
index - the index of the validator to return
Returns:
the validator a the specified index.

insertValidatorAtIndex

public void insertValidatorAtIndex(int index,
                                   ValidationInterface validator)
Inserts the validator at the specified index. Valid index values are from 0 to number of validators - 1.

Parameters:
index - the index to insert the validator at
validator - the validator to insert at the index

getValidators

public java.util.List getValidators()
Returns the list that contains the validators.

Returns:
the list of validators that are currently set.

setValidators

public void setValidators(java.util.List validators)
Sets the list of validators to use. The validators are going to run starting at index 0 and continuing to the end of the list.

Parameters:
validators - the list of validators to use.

getFirstValidator

public ValidationInterface getFirstValidator()
Deprecated. Use getValidatorAtIndex(0) instead

Returns the first validator to be run.

Returns:
the first validator to be run.

setFirstValidator

public void setFirstValidator(ValidationInterface firstValidator)
Deprecated. Use removeValidatorAtIndex(0) and then insertValidatorAtIndex(0, validator) instead

Sets the first validator to be run.

Parameters:
firstValidator - the first validator to be run.

getSecondValidator

public ValidationInterface getSecondValidator()
Deprecated. Use getValidatorAtIndex(1) instead

Returns the second validator to be run.

Returns:
the second validator to be run.

setSecondValidator

public void setSecondValidator(ValidationInterface secondValidator)
Deprecated. Use removeValidatorAtIndex(1) and then insertValidatorAtIndex(1, validator) instead

Sets the second validator to be run.

Parameters:
secondValidator - the second validator to be run.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.