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, 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:
  • Field Details

    • INVALID_VALUE_MESSAGE_PROPERTY

      static final String INVALID_VALUE_MESSAGE_PROPERTY
      The invalid value message bound property.
    • VALUE_REQUIRED_MESSAGE_PROPERTY

      static final String VALUE_REQUIRED_MESSAGE_PROPERTY
      The value required message bound property.
    • VALUE_REQUIRED_PROPERTY

      static final String VALUE_REQUIRED_PROPERTY
      The value required bound property.
  • Method Details

    • getInvalidValueMessage

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

      void setInvalidValueMessage(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:
      NullPointerException - if the given message is null.
      See Also:
    • getValueRequiredMessage

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

      void setValueRequiredMessage(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:
      NullPointerException - if the given message is null.
      See Also:
    • 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 AbstractValidator.throwInvalidValueValidationException(Object) as a convenience. A child class may also call AbstractValidator.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:
    • 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.