Class PANValidator
- java.lang.Object
-
- com.globalmentor.beans.BoundPropertyObject
-
- io.guise.framework.event.GuiseBoundPropertyObject
-
- io.guise.framework.validator.AbstractValidator<com.globalmentor.iso.idcard.PAN>
-
- io.guise.framework.validator.PANValidator
-
- All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable
,com.globalmentor.beans.PropertyConstrainable
,Validator<com.globalmentor.iso.idcard.PAN>
public class PANValidator extends AbstractValidator<com.globalmentor.iso.idcard.PAN>
A validator to validate a Primary Account Number (PAN) of an identification card as defined in ISO/IEC 7812-1:2000(E), "Identification cards - Identification of issuers - Part 1: Numbering system". The validator ensures that the PAN represents one of the allowed ID card products. PANs for unknown products are considered invalid.- See Also:
IDCard
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
VALID_PRODUCTS_PROPERTY
The valid products bound property.-
Fields inherited from class com.globalmentor.beans.BoundPropertyObject
NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS
-
Fields inherited from interface io.guise.framework.validator.Validator
INVALID_VALUE_MESSAGE_PROPERTY, VALUE_REQUIRED_MESSAGE_PROPERTY, VALUE_REQUIRED_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description PANValidator(boolean valueRequired)
Value required constructor accepting all known products.PANValidator(boolean valueRequired, com.globalmentor.iso.idcard.Product... validProducts)
Value required and valid products constructor.PANValidator(com.globalmentor.iso.idcard.Product... validProducts)
Valid products constructor with no value required.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Set<com.globalmentor.iso.idcard.Product>
getValidProducts()
void
setValidProducts(com.globalmentor.iso.idcard.Product... validProducts)
Sets the PAN products that the validator considers valid.void
setValidProducts(java.util.Set<com.globalmentor.iso.idcard.Product> newValidProducts)
Sets the PAN products that the validator considers valid.void
validate(com.globalmentor.iso.idcard.PAN value)
Checks whether a given value is valid, and throws an exception if not.-
Methods inherited from class io.guise.framework.validator.AbstractValidator
getInvalidValueMessage, getValueRequiredMessage, isValid, isValueRequired, setInvalidValueMessage, setValueRequired, setValueRequiredMessage, throwInvalidValueValidationException, throwValueRequiredValidationException, toString
-
Methods inherited from class io.guise.framework.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.globalmentor.beans.PropertyBindable
addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener
-
Methods inherited from interface io.guise.framework.validator.Validator
getSession
-
-
-
-
Constructor Detail
-
PANValidator
public PANValidator(com.globalmentor.iso.idcard.Product... validProducts)
Valid products constructor with no value required.- Parameters:
validProducts
- The products that are allowed, if any.- Throws:
java.lang.NullPointerException
- if the given array of valid products isnull
.
-
PANValidator
public PANValidator(boolean valueRequired)
Value required constructor accepting all known products.- Parameters:
valueRequired
- Whether the value must be non-null
in order to be considered valid.
-
PANValidator
public PANValidator(boolean valueRequired, com.globalmentor.iso.idcard.Product... validProducts)
Value required and valid products constructor.- Parameters:
valueRequired
- Whether the value must be non-null
in order to be considered valid.validProducts
- The products that are allowed, if any.- Throws:
java.lang.NullPointerException
- if the given array of valid products isnull
.
-
-
Method Detail
-
getValidProducts
public java.util.Set<com.globalmentor.iso.idcard.Product> getValidProducts()
- Returns:
- The read-only set of valid products.
-
setValidProducts
public void setValidProducts(java.util.Set<com.globalmentor.iso.idcard.Product> newValidProducts)
Sets the PAN products that the validator considers valid. This is a bound property.- Parameters:
newValidProducts
- The set of valid products.- Throws:
java.lang.NullPointerException
- if the given set of valid products isnull
.- See Also:
VALID_PRODUCTS_PROPERTY
-
setValidProducts
public void setValidProducts(com.globalmentor.iso.idcard.Product... validProducts)
Sets the PAN products that the validator considers valid. This is a bound property. This implementation delegates tosetValidProducts(Set)
- Parameters:
validProducts
- The products that are allowed, if any.- Throws:
java.lang.NullPointerException
- if the given array of valid products isnull
.- See Also:
VALID_PRODUCTS_PROPERTY
-
validate
public void validate(com.globalmentor.iso.idcard.PAN 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 callAbstractValidator.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
Validator.isValid(Object)
may be overridden to provide optimized fast-fail determinations, adding new logic toValidator.isValid(Object)
cannot be used in place of overriding this method.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
AbstractValidator.isValid(Object)
may be overridden to provide optimized fast-fail determinations, adding new logic toAbstractValidator.isValid(Object)
cannot be used in place of overriding this method.This version determines whether a given PAN represents one of the supported products and is the correct length.
- Specified by:
validate
in interfaceValidator<com.globalmentor.iso.idcard.PAN>
- Overrides:
validate
in classAbstractValidator<com.globalmentor.iso.idcard.PAN>
- Parameters:
value
- The value to validate, which may benull
.- Throws:
ValidationException
- if the provided value is not valid.- See Also:
AbstractValidator.throwInvalidValueValidationException(Object)
,AbstractValidator.throwValueRequiredValidationException(Object)
-
-