com.sas.util.validators
Class Validator

com.sas.util.validators.Validator
All Implemented Interfaces:
ValidationInterface, java.io.Serializable
Direct Known Subclasses:
CompositeValidator, DateStringValidator, IntegerStringValidator, JavaScriptValidator, RequiredStringValidator

public class Validator
implements ValidationInterface, java.io.Serializable

This is the base validator class which provides a default implementation of the ValidationInterface. Validator also provides a base framework for creating, storing, and overriding Message objects used during the validation.

See Also:
Serialized Form

Field Summary
protected  java.lang.String message
          The validation message code.
protected  java.util.ArrayList messages
          The list of com.sas.text.Message objects which can be used by the validation code.
protected  com.sas.text.Message msgObject
          The validation message which was set the last time validateValue returned false.
static java.lang.String RB_KEY
           
 
Constructor Summary
Validator()
          Constructor.
 
Method Summary
 void createValidationMessages()
          createValidationMessages is called by the constructor to create the collection of message objects that are accessed by validateValue.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
           
 com.sas.text.Message getValidationMessage()
          Returns the Message object set with setValidationMessage.
 java.lang.String getValidationMessageCode()
          Returns the message code String set in setValidationMessage.
 com.sas.text.Message newValidationMessage(java.lang.String template)
          Creates a new Message object to store a message and it's arguments.
 java.lang.Object normalizeValue(java.lang.Object component, java.lang.Object value)
          Default implementation.
 void setValidationMessage(com.sas.text.Message message)
          Sets the message to be displayed in the error handler when the validation returns false.
 void setValidationMessageCode(java.lang.String message)
          Sets the String used to indicate why the validation failed.
 boolean validateValue(java.lang.Object component, java.lang.Object value)
          Default implementation.
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

message

protected java.lang.String message
The validation message code. A non-translatable string. May be null.


msgObject

protected com.sas.text.Message msgObject
The validation message which was set the last time validateValue returned false. May be null.


messages

protected java.util.ArrayList messages
The list of com.sas.text.Message objects which can be used by the validation code.

Constructor Detail

Validator

public Validator()
Constructor. Calls createValidationMessages to create the default list of validation message objects.

See Also:
createValidationMessages()
Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()

validateValue

public boolean validateValue(java.lang.Object component,
                             java.lang.Object value)
Default implementation. Returns true. Subclasses should override and perform the actual validation.

Specified by:
validateValue in interface ValidationInterface
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)
Default implementation. Returns the value passed in. Subclasses may override to modify the value and return it, or return a different Object.

Specified by:
normalizeValue in interface ValidationInterface
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)

getValidationMessageCode

public java.lang.String getValidationMessageCode()
Returns the message code String set in setValidationMessage. May return null if no message code is set.

Specified by:
getValidationMessageCode in interface ValidationInterface
Returns:
a validation message code. The validation message code is a non-translatable string which identifies the cause of the last validation error. This will typically be used as a key to a resource bundle.
See Also:
ValidationInterface.getValidationMessageCode()

getValidationMessage

public com.sas.text.Message getValidationMessage()
Returns the Message object set with setValidationMessage.

Specified by:
getValidationMessage in interface ValidationInterface
Returns:
the Message object, containing a format string and substitution values, which describe why the value passed to validateValue() is invalid.
See Also:
ValidationInterface.getValidationMessage()

setValidationMessage

public void setValidationMessage(com.sas.text.Message message)
Sets the message to be displayed in the error handler when the validation returns false.

Specified by:
setValidationMessage in interface ValidationInterface
Parameters:
message - a Message object that contains a format string and substitution values, which describe why the value passed to validateValue() is invalid.
See Also:
ValidationInterface.setValidationMessage(com.sas.text.Message)

setValidationMessageCode

public void setValidationMessageCode(java.lang.String message)
Sets the String used to indicate why the validation failed.

See Also:
setValidationMessage(com.sas.text.Message)

createValidationMessages

public void createValidationMessages()
createValidationMessages is called by the constructor to create the collection of message objects that are accessed by validateValue. This can be overridden by subclasses to allow for different messages to be displayed. For each message, newValidationMessage is called to create the actual Message object. Other data can then be set on the Message object if desired.

See Also:
newValidationMessage(java.lang.String)

newValidationMessage

public com.sas.text.Message newValidationMessage(java.lang.String template)
Creates a new Message object to store a message and it's arguments. Subclasses may override this method to create a subclass of the Message object.

See Also:
createValidationMessages()



Copyright © 2009 SAS Institute Inc. All Rights Reserved.