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 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...).protected boolean
changed
State to indicate that validator has changed since the last time bean was setted.static String
CHANGED_PROPERTY
Name of the bounded propertychanged
.static String
CONTEXT_PROPERTY
Name of the bounded propertycontext
.protected PropertyChangeListener
l
Listener that listens on bean modification.protected EventListenerList
listenerList
A list of event listeners for this validatorsprotected PropertyChangeSupport
pcs
delegate property change supportstatic String
SCOPES_PROPERTY
Name of the bounded propertyscopes
.protected boolean
valid
State of the validator (is true if no errors of error scope is found).static String
VALID_PROPERTY
Name of the bounded propertyvalid
.protected NuitonValidatorProvider
validatorProvider
The provider of delegate validators.
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractValidator(NuitonValidatorProvider validatorProvider, Class<O> beanClass)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addPropertyChangeListener(PropertyChangeListener listener)
void
addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
boolean
containsField(String fieldName)
Test a the validator contains the field given his nameabstract <T> T
convert(O bean, String fieldName, String value, Class<T> valueClass)
abstract void
doValidate()
protected abstract void
doValidate(O bean)
void
firePropertyChange(String propertyName, Object oldValue, Object newValue)
String
getContext()
protected abstract NuitonValidator<O>
getDelegate()
Set<String>
getEffectiveFields()
Set<String>
getEffectiveFields(NuitonValidatorScope scope)
Set<NuitonValidatorScope>
getEffectiveScopes()
abstract NuitonValidatorScope
getHighestScope(String field)
protected NuitonValidatorModel<O>
getModel()
Set<NuitonValidatorScope>
getScopes()
Class<O>
getType()
abstract boolean
hasErrors()
abstract boolean
hasFatalErrors()
abstract boolean
hasInfos()
abstract boolean
hasWarnings()
boolean
isCanValidate()
boolean
isChanged()
Obtain thechanged
property value.boolean
isValid()
Obtain thevalid
property value.abstract boolean
isValid(String fieldName)
protected abstract void
rebuildDelegateValidator(Class<O> beanType, String context, NuitonValidatorScope... scopes)
void
removePropertyChangeListener(PropertyChangeListener listener)
void
removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
void
setCanValidate(boolean canValidate)
void
setChanged(boolean changed)
To force the value of the propertychanged
.void
setContext(String context)
void
setScopes(NuitonValidatorScope... scopes)
void
setValid(boolean valid)
Change the value of thevalid
property.
-
-
-
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 thechanged
property value. Returnstrue
if bean was modified since last time a bean was attached.- Returns:
true
if 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 thevalid
property value.- Returns:
true
if attached bean is valid (no error or fatal messages)
-
setValid
public void setValid(boolean valid)
Change the value of thevalid
property.- 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:
true
if validator contaisn this field,false
otherwise
-
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()
-
-