Package org.nuiton.validator.bean
Class AbstractValidator<O>
- java.lang.Object
-
- org.nuiton.validator.bean.AbstractValidator<O>
-
- Type Parameters:
O- type of bean to validate
- Direct Known Subclasses:
BeanListValidator,SimpleBeanValidator
public abstract class AbstractValidator<O> extends Object
TODO- Since:
- 2.5.2
- Author:
- Tony Chemit - chemit@codelutin.com
-
-
Field Summary
Fields Modifier and Type Field Description protected booleancanValidateState to know if the validator can be used (we keep this state for performance reasons : do not want to compute this value each time a validation is asked...).protected booleanchangedState to indicate that validator has changed since the last time bean was setted.static StringCHANGED_PROPERTYName of the bounded propertychanged.static StringCONTEXT_PROPERTYName of the bounded propertycontext.protected PropertyChangeListenerlListener that listens on bean modification.protected EventListenerListlistenerListA list of event listeners for this validatorsprotected PropertyChangeSupportpcsdelegate property change supportstatic StringSCOPES_PROPERTYName of the bounded propertyscopes.protected booleanvalidState of the validator (is true if no errors of error scope is found).static StringVALID_PROPERTYName of the bounded propertyvalid.protected NuitonValidatorProvidervalidatorProviderThe provider of delegate validators.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractValidator(NuitonValidatorProvider validatorProvider, Class<O> beanClass)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(PropertyChangeListener listener)voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener)booleancontainsField(String fieldName)Test a the validator contains the field given his nameabstract <T> Tconvert(O bean, String fieldName, String value, Class<T> valueClass)abstract voiddoValidate()protected abstract voiddoValidate(O bean)voidfirePropertyChange(String propertyName, Object oldValue, Object newValue)StringgetContext()protected abstract NuitonValidator<O>getDelegate()Set<String>getEffectiveFields()Set<String>getEffectiveFields(NuitonValidatorScope scope)Set<NuitonValidatorScope>getEffectiveScopes()abstract NuitonValidatorScopegetHighestScope(String field)protected NuitonValidatorModel<O>getModel()Set<NuitonValidatorScope>getScopes()Class<O>getType()abstract booleanhasErrors()abstract booleanhasFatalErrors()abstract booleanhasInfos()abstract booleanhasWarnings()booleanisCanValidate()booleanisChanged()Obtain thechangedproperty value.booleanisValid()Obtain thevalidproperty value.abstract booleanisValid(String fieldName)protected abstract voidrebuildDelegateValidator(Class<O> beanType, String context, NuitonValidatorScope... scopes)voidremovePropertyChangeListener(PropertyChangeListener listener)voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener)voidsetCanValidate(boolean canValidate)voidsetChanged(boolean changed)To force the value of the propertychanged.voidsetContext(String context)voidsetScopes(NuitonValidatorScope... scopes)voidsetValid(boolean valid)Change the value of thevalidproperty.
-
-
-
Field Detail
-
CONTEXT_PROPERTY
public static final String CONTEXT_PROPERTY
Name of the bounded propertycontext.- See Also:
getContext(),setContext(String), Constant Field Values
-
SCOPES_PROPERTY
public static final String SCOPES_PROPERTY
Name of the bounded propertyscopes.
-
VALID_PROPERTY
public static final String VALID_PROPERTY
Name of the bounded propertyvalid.- See Also:
valid,isValid(),setValid(boolean), Constant Field Values
-
CHANGED_PROPERTY
public static final String CHANGED_PROPERTY
Name of the bounded propertychanged.- See Also:
changed,isChanged(),setChanged(boolean), Constant Field Values
-
changed
protected boolean changed
State to indicate that validator has changed since the last time bean was setted.
-
valid
protected boolean valid
State of the validator (is true if no errors of error scope is found).
-
canValidate
protected boolean canValidate
State to know if the validator can be used (we keep this state for performance reasons : do not want to compute this value each time a validation is asked...).
-
l
protected final PropertyChangeListener l
Listener that listens on bean modification.
-
pcs
protected final PropertyChangeSupport pcs
delegate property change support
-
listenerList
protected final EventListenerList listenerList
A list of event listeners for this validators
-
validatorProvider
protected final NuitonValidatorProvider validatorProvider
The provider of delegate validators. It will also produce validator model.- See Also:
NuitonValidatorProvider
-
-
Constructor Detail
-
AbstractValidator
protected AbstractValidator(NuitonValidatorProvider validatorProvider, Class<O> beanClass)
-
-
Method Detail
-
isChanged
public boolean isChanged()
Obtain thechangedproperty value. Returnstrueif bean was modified since last time a bean was attached.- Returns:
trueif bean was modified since last attachement of a bean.
-
setChanged
public void setChanged(boolean changed)
To force the value of the propertychanged.- Parameters:
changed- flag to force reset of propertychanged
-
isCanValidate
public boolean isCanValidate()
-
setCanValidate
public void setCanValidate(boolean canValidate)
-
isValid
public boolean isValid()
Obtain thevalidproperty value.- Returns:
trueif attached bean is valid (no error or fatal messages)
-
setValid
public void setValid(boolean valid)
Change the value of thevalidproperty.- Parameters:
valid- the new value of the property
-
getContext
public String getContext()
-
setContext
public void setContext(String context)
-
getScopes
public Set<NuitonValidatorScope> getScopes()
-
getEffectiveScopes
public Set<NuitonValidatorScope> getEffectiveScopes()
-
getEffectiveFields
public Set<String> getEffectiveFields(NuitonValidatorScope scope)
-
setScopes
public void setScopes(NuitonValidatorScope... scopes)
-
doValidate
public abstract void doValidate()
-
hasFatalErrors
public abstract boolean hasFatalErrors()
-
hasErrors
public abstract boolean hasErrors()
-
hasWarnings
public abstract boolean hasWarnings()
-
hasInfos
public abstract boolean hasInfos()
-
isValid
public abstract boolean isValid(String fieldName)
-
getHighestScope
public abstract NuitonValidatorScope getHighestScope(String field)
-
doValidate
protected abstract void doValidate(O bean)
-
getDelegate
protected abstract NuitonValidator<O> getDelegate()
-
rebuildDelegateValidator
protected abstract void rebuildDelegateValidator(Class<O> beanType, String context, NuitonValidatorScope... scopes)
-
containsField
public boolean containsField(String fieldName)
Test a the validator contains the field given his name- Parameters:
fieldName- the name of the searched field- Returns:
trueif validator contaisn this field,falseotherwise
-
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
-
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
-
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
-
removePropertyChangeListener
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
-
firePropertyChange
public void firePropertyChange(String propertyName, Object oldValue, Object newValue)
-
getModel
protected NuitonValidatorModel<O> getModel()
-
-