com.guiseframework.validator
Interface Validator<V>

Type Parameters:
V - The value type this validator supports.
All Superinterfaces:
com.globalmentor.beans.PropertyBindable
All Known Subinterfaces:
RangeValidator<V>
All Known Implementing Classes:
AbstractComparableRangeValidator, AbstractRangeValidator, AbstractRegularExpressionValidator, AbstractValidator, DateRangeValidator, DecimalRangeValidator, IntegerRangeValidator, LongRangeValidator, PANValidator, RegularExpressionCharArrayValidator, RegularExpressionStringValidator, ResourceImportValidator, TextSearchPanel.PatternSyntaxValidator, ValueRequiredValidator

public interface Validator<V>
extends com.globalmentor.beans.PropertyBindable

Indicates an object that can determine whether a value is valid. The invalid value message should be in the form "Invalid value: '{0}'.", where "{0}" represents the invalid value.

Author:
Garret Wilson
See Also:
Resources.VALIDATOR_INVALID_VALUE_MESSAGE_RESOURCE_REFERENCE, Resources.VALIDATOR_VALUE_REQUIRED_MESSAGE_RESOURCE_REFERENCE

Field Summary
static java.lang.String INVALID_VALUE_MESSAGE_PROPERTY
          The invalid value message bound property.
static java.lang.String VALUE_REQUIRED_MESSAGE_PROPERTY
          The value required message bound property.
static java.lang.String VALUE_REQUIRED_PROPERTY
          The value required bound property.
 
Method Summary
 java.lang.String getInvalidValueMessage()
           
 GuiseSession getSession()
           
 java.lang.String getValueRequiredMessage()
           
 boolean isValid(V value)
          Determines whether a given value is valid.
 void setInvalidValueMessage(java.lang.String newInvalidValueMessage)
          Sets the text of the invalid value message.
 void setValueRequiredMessage(java.lang.String newValueRequiredMessage)
          Sets the text of the value required message.
 void validate(V value)
          Checks whether a given value is valid, and throws an exception if not.
 
Methods inherited from interface com.globalmentor.beans.PropertyBindable
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
 

Field Detail

INVALID_VALUE_MESSAGE_PROPERTY

static final java.lang.String INVALID_VALUE_MESSAGE_PROPERTY
The invalid value message bound property.


VALUE_REQUIRED_MESSAGE_PROPERTY

static final java.lang.String VALUE_REQUIRED_MESSAGE_PROPERTY
The value required message bound property.


VALUE_REQUIRED_PROPERTY

static final java.lang.String VALUE_REQUIRED_PROPERTY
The value required bound property.

Method Detail

getInvalidValueMessage

java.lang.String getInvalidValueMessage()
Returns:
The invalid value message text, which may include a resource reference.

setInvalidValueMessage

void setInvalidValueMessage(java.lang.String newInvalidValueMessage)
Sets the text of the invalid value message. This is a bound property.

Parameters:
newInvalidValueMessage - The new text of the invalid value message, which may include a resource reference.
Throws:
java.lang.NullPointerException - if the given message is null.
See Also:
INVALID_VALUE_MESSAGE_PROPERTY

getValueRequiredMessage

java.lang.String getValueRequiredMessage()
Returns:
The value required message text, which may include a resource reference.

setValueRequiredMessage

void setValueRequiredMessage(java.lang.String newValueRequiredMessage)
Sets the text of the value required message. This is a bound property.

Parameters:
newValueRequiredMessage - The new text of the value required message, which may include a resource reference..
Throws:
java.lang.NullPointerException - if the given message is null.
See Also:
#VALUE_REQUIRED_VALUE_MESSAGE_PROPERTY

getSession

GuiseSession getSession()
Returns:
The Guise session that owns this validator.

validate

void validate(V value)
              throws ValidationException
Checks whether a given value is valid, and throws an exception if not.

The message of the thrown exception should be appropriate for display to the user, although it may include string resource references. If a child class has no specific message to return, that class may call #throwInvalidValueValidationException(Object) as a convenience. A child class may also call #throwValueRequiredValidationException(Object) as a convenience, but this is usually not required if this version of the method, which provides a missing value check, is called first.

This version checks whether a value is provided if values are required. Child classes should call this version as a convenience for checking non-null and required status.

Adding new validation logic always requires overriding this method. Although isValid(Object) may be overridden to provide optimized fast-fail determinations, adding new logic to isValid(Object) cannot be used in place of overriding this method.

Parameters:
value - The value to validate, which may be null.
Throws:
ValidationException - if the provided value is not valid.
See Also:
#throwInvalidValueValidationException(Object), #throwValueRequiredValidationException(Object)

isValid

boolean isValid(V value)
Determines whether a given value is valid. This convenience version calls validate(Object), returning false only if an exception is thrown. Although this method may be overridden to provide optimized fast-fail determinations, adding new logic to this method cannot be used in place of overriding validate(Object).

Parameters:
value - The value to validate.
Returns:
true if a value is given and the value is valid; or a value is not required, else false.


Copyright © 2005-2010 GlobalMentor, Inc. All Rights Reserved.