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 java.lang.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 java.lang.StringCHANGED_PROPERTYName of the bounded propertychanged.static java.lang.StringCONTEXT_PROPERTYName of the bounded propertycontext.protected java.beans.PropertyChangeListenerlListener that listens on bean modification.protected javax.swing.event.EventListenerListlistenerListA list of event listeners for this validatorsprotected java.beans.PropertyChangeSupportpcsdelegate property change supportstatic java.lang.StringSCOPES_PROPERTYName of the bounded propertyscopes.protected booleanvalidState of the validator (is true if no errors of error scope is found).static java.lang.StringVALID_PROPERTYName of the bounded propertyvalid.protected NuitonValidatorProvidervalidatorProviderThe provider of delegate validators. -
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractValidator(NuitonValidatorProvider validatorProvider, java.lang.Class<O> beanClass) -
Method Summary
Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)voidaddPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)booleancontainsField(java.lang.String fieldName)Test a the validator contains the field given his nameabstract <T> Tconvert(O bean, java.lang.String fieldName, java.lang.String value, java.lang.Class<T> valueClass)abstract voiddoValidate()protected abstract voiddoValidate(O bean)voidfirePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue)java.lang.StringgetContext()protected abstract NuitonValidator<O>getDelegate()java.util.Set<java.lang.String>getEffectiveFields()java.util.Set<java.lang.String>getEffectiveFields(NuitonValidatorScope scope)java.util.Set<NuitonValidatorScope>getEffectiveScopes()abstract NuitonValidatorScopegetHighestScope(java.lang.String field)protected NuitonValidatorModel<O>getModel()java.util.Set<NuitonValidatorScope>getScopes()java.lang.Class<O>getType()abstract booleanhasErrors()abstract booleanhasFatalErrors()abstract booleanhasInfos()abstract booleanhasWarnings()booleanisCanValidate()booleanisChanged()Obtain thechangedproperty value.booleanisValid()Obtain thevalidproperty value.abstract booleanisValid(java.lang.String fieldName)protected abstract voidrebuildDelegateValidator(java.lang.Class<O> beanType, java.lang.String context, NuitonValidatorScope... scopes)voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)voidremovePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)voidsetCanValidate(boolean canValidate)voidsetChanged(boolean changed)To force the value of the propertychanged.voidsetContext(java.lang.String context)voidsetScopes(NuitonValidatorScope... scopes)voidsetValid(boolean valid)Change the value of thevalidproperty.
-
Field Details
-
CONTEXT_PROPERTY
public static final java.lang.String CONTEXT_PROPERTYName of the bounded propertycontext.- See Also:
getContext(),setContext(String), Constant Field Values
-
SCOPES_PROPERTY
public static final java.lang.String SCOPES_PROPERTYName of the bounded propertyscopes. -
VALID_PROPERTY
public static final java.lang.String VALID_PROPERTYName of the bounded propertyvalid.- See Also:
valid,isValid(),setValid(boolean), Constant Field Values
-
CHANGED_PROPERTY
public static final java.lang.String CHANGED_PROPERTYName of the bounded propertychanged.- See Also:
changed,isChanged(),setChanged(boolean), Constant Field Values
-
changed
protected boolean changedState to indicate that validator has changed since the last time bean was setted. -
valid
protected boolean validState of the validator (is true if no errors of error scope is found). -
canValidate
protected boolean canValidateState 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 java.beans.PropertyChangeListener lListener that listens on bean modification. -
pcs
protected final java.beans.PropertyChangeSupport pcsdelegate property change support -
listenerList
protected final javax.swing.event.EventListenerList listenerListA list of event listeners for this validators -
validatorProvider
The provider of delegate validators. It will also produce validator model.- See Also:
NuitonValidatorProvider
-
-
Constructor Details
-
AbstractValidator
protected AbstractValidator(NuitonValidatorProvider validatorProvider, java.lang.Class<O> beanClass)
-
-
Method Details
-
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 java.lang.String getContext() -
setContext
public void setContext(java.lang.String context) -
getScopes
-
getEffectiveScopes
-
getEffectiveFields
public java.util.Set<java.lang.String> getEffectiveFields() -
getEffectiveFields
-
setScopes
-
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(java.lang.String fieldName) -
getHighestScope
-
convert
public abstract <T> T convert(O bean, java.lang.String fieldName, java.lang.String value, java.lang.Class<T> valueClass) -
doValidate
-
getDelegate
-
rebuildDelegateValidator
protected abstract void rebuildDelegateValidator(java.lang.Class<O> beanType, java.lang.String context, NuitonValidatorScope... scopes) -
getType
-
containsField
public boolean containsField(java.lang.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(java.beans.PropertyChangeListener listener) -
addPropertyChangeListener
public void addPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener) -
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener listener) -
removePropertyChangeListener
public void removePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener) -
firePropertyChange
public void firePropertyChange(java.lang.String propertyName, java.lang.Object oldValue, java.lang.Object newValue) -
getModel
-