Class
caplin.trading.validation

AbstractFieldValidator

The AbstractFieldValidator is a caplin.trading.validation.Validator that makes it easy to write Validators that record information about errors in data that is structured as fields.
If validation errors are found, error objects are appended to the supplied caplin.trading.validation.ValidationResult. These error objects take the form of maps with the field name as the key and the error message as a value. A map contains one or more key/value pairs. Each FieldValidator will only append one map to the ValidationResult, containing only the errors that were found within that validator.
Subclasses of AbstractFieldValidator must call the constructor in their constructor, and must implement #validateField. This class is immutable. Its subclasses must be as well.

Constructor Summary

Attributes Name and Description
caplin.trading.validation.AbstractFieldValidator(Array l_pFields)

The constructor for AbstractFieldValidator.

Method Summary

Attributes Name and Description
void validate(caplin.trading.trademodel.DataHolder oDataToValidate, caplin.trading.validation.ValidationResult oValidationResult)

Validates the supplied data and adds an error map to the validation result if any of the fields are missing, or if the implementing validator deems that the field contains an error.

String validateField(String sFieldValue)

Performs validation on the specified field according to rules in the implementing class and returns an error message if the field contains an error.

Constructor Detail

caplin.trading.validation.AbstractFieldValidator(Array l_pFields)

The constructor for AbstractFieldValidator.

Parameters
Array l_pFields An array of field names as strings that must be present in the data to validate. Must not be null.
Throws
caplin.core.Error
if l_pFields is not an array of strings.

Method Detail

void validate(caplin.trading.trademodel.DataHolder oDataToValidate, caplin.trading.validation.ValidationResult oValidationResult)

Validates the supplied data and adds an error map to the validation result if any of the fields are missing, or if the implementing validator deems that the field contains an error. The error object is a map with the field name as the key and the error as the value.

Parameters
caplin.trading.trademodel.DataHolder oDataToValidate The data to validate. Must not be null or undefined.
caplin.trading.validation.ValidationResult oValidationResult A caplin.trading.validation.ValidationResult to which the error map is added. Must not be null or undefined.

String validateField(String sFieldValue)

Performs validation on the specified field according to rules in the implementing class and returns an error message if the field contains an error. This method is abstract. Extending classes should implement this method to provide specific validation for a field value.

Parameters
String sFieldValue The field value to validate.
Returns
The error message that is associated with the field, or null if the field is not in error.