|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.globalmentor.beans.BoundPropertyObject
com.guiseframework.event.GuiseBoundPropertyObject
com.guiseframework.validator.AbstractValidator<V>
V - The value type this validator supports.public abstract class AbstractValidator<V>
An abstract implementation of an object that can determine whether a value is valid.
| Field Summary |
|---|
| Fields inherited from class com.globalmentor.beans.BoundPropertyObject |
|---|
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS |
| Fields inherited from interface com.guiseframework.validator.Validator |
|---|
INVALID_VALUE_MESSAGE_PROPERTY, VALUE_REQUIRED_MESSAGE_PROPERTY, VALUE_REQUIRED_PROPERTY |
| Constructor Summary | |
|---|---|
AbstractValidator()
Default constructor with no value required. |
|
AbstractValidator(boolean valueRequired)
Value required constructor. |
|
| Method Summary | |
|---|---|
java.lang.String |
getInvalidValueMessage()
|
java.lang.String |
getValueRequiredMessage()
|
boolean |
isValid(V value)
Determines whether a given value is valid. |
boolean |
isValueRequired()
|
void |
setInvalidValueMessage(java.lang.String newInvalidValueMessage)
Sets the text of the invalid value message. |
void |
setValueRequired(boolean newValueRequired)
Sets whether the value must be non- null in order to be considered valid. |
void |
setValueRequiredMessage(java.lang.String newValueRequiredMessage)
Sets the text of the value required message. |
void |
throwInvalidValueValidationException(V value)
Throws a validation exception with a message indicating that the given value is invalid. |
void |
throwValueRequiredValidationException(V value)
Throws a validation exception with a message indicating that a valid is required. |
protected java.lang.String |
toString(V value)
Retrieves a string representation of the given value appropriate for error messages. |
void |
validate(V value)
Checks whether a given value is valid, and throws an exception if not. |
| Methods inherited from class com.guiseframework.event.GuiseBoundPropertyObject |
|---|
getSession |
| Methods inherited from class com.globalmentor.beans.BoundPropertyObject |
|---|
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.guiseframework.validator.Validator |
|---|
getSession |
| Methods inherited from interface com.globalmentor.beans.PropertyBindable |
|---|
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener |
| Constructor Detail |
|---|
public AbstractValidator()
public AbstractValidator(boolean valueRequired)
valueRequired - Whether the value must be non-null in order to be considered valid.| Method Detail |
|---|
public boolean isValueRequired()
null in order to be considered valid.public void setValueRequired(boolean newValueRequired)
null in order to be considered valid.
This is a bound property of type Boolean.
newValueRequired - true if the value must be non-null in order to be considered valid.Validator.VALUE_REQUIRED_PROPERTYpublic java.lang.String getInvalidValueMessage()
getInvalidValueMessage in interface Validator<V>public void setInvalidValueMessage(java.lang.String newInvalidValueMessage)
setInvalidValueMessage in interface Validator<V>newInvalidValueMessage - The new text of the invalid value message, which may include a resource reference.
java.lang.NullPointerException - if the given message is null.Validator.INVALID_VALUE_MESSAGE_PROPERTYpublic java.lang.String getValueRequiredMessage()
getValueRequiredMessage in interface Validator<V>public void setValueRequiredMessage(java.lang.String newValueRequiredMessage)
setValueRequiredMessage in interface Validator<V>newValueRequiredMessage - The new text of the value required message, which may include a resource reference.
java.lang.NullPointerException - if the given message is null.#VALUE_REQUIRED_VALUE_MESSAGE_PROPERTY
public void throwInvalidValueValidationException(V value)
throws ValidationException
value - The value being validated.
ValidationException - to indicate that the given value is invalid.getInvalidValueMessage()
public void throwValueRequiredValidationException(V value)
throws ValidationException
value - The value being validated.
ValidationException - to indicate that a value is required.getValueRequiredMessage()
public void validate(V value)
throws ValidationException
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.
validate in interface Validator<V>value - The value to validate, which may be null.
ValidationException - if the provided value is not valid.throwInvalidValueValidationException(Object),
throwValueRequiredValidationException(Object)public boolean isValid(V value)
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).
isValid in interface Validator<V>value - The value to validate.
true if a value is given and the value is valid; or a value is not required, else false.protected java.lang.String toString(V value)
Object.toString() string representation of the value.
value - The value for which a string representation should be returned.
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||