|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.nuiton.validator.bean.BeanValidator<O>
public class BeanValidator<O>
Validator for a javaBean object.
A such validator is designed to validate to keep the validation of a bean, means the bean is attached to the validator (fieldbean.
A such validator is also a JavaBean and you can listen his states
modifications via the classic java bean api.
Note: The BeanValidator should never be used for
validation in a service approch since it needs to keep a reference to the
bean to validate.
BeanValidatorListener| Field Summary | |
|---|---|
protected O |
bean
The bean to validate. |
static String |
BEAN_PROPERTY
Name of the bounded property bean. |
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 property changed. |
static String |
CONTEXT_PROPERTY
Name of the bounded property context. |
protected Map<String,String> |
conversionErrors
map of conversion errors detected by this validator |
protected NuitonValidator<O> |
delegate
The delegate validator used to validate the bean. |
protected PropertyChangeListener |
l
Listener that listens on bean modification. |
protected EventListenerList |
listenerList
A list of event listeners for this validators |
protected static org.apache.commons.logging.Log |
log
Logger. |
protected NuitonValidatorResult |
messages
State of validation (keep all messages of validation for the filled bean). |
protected BeanValidator<?> |
parentValidator
To chain to another validator (acting as parent of this one). |
protected PropertyChangeSupport |
pcs
delegate property change support |
static String |
SCOPES_PROPERTY
Name of the bounded property scopes. |
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 property valid. |
protected NuitonValidatorProvider |
validatorProvider
The provider of delegate validators. |
| Constructor Summary | |
|---|---|
BeanValidator(NuitonValidatorProvider validatorProvider,
Class<O> beanClass,
String context)
|
|
BeanValidator(NuitonValidatorProvider validatorProvider,
Class<O> beanClass,
String context,
NuitonValidatorScope... scopes)
|
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final String BEAN_PROPERTY
bean.
bean,
getBean(),
setBean(Object),
Constant Field Valuespublic static final String CONTEXT_PROPERTY
context.
getContext(),
setContext(String),
Constant Field Valuespublic static final String SCOPES_PROPERTY
scopes.
getScopes(),
setScopes(NuitonValidatorScope...),
Constant Field Valuespublic static final String VALID_PROPERTY
valid.
valid,
isValid(),
setValid(boolean),
Constant Field Valuespublic static final String CHANGED_PROPERTY
changed.
changed,
isChanged(),
setChanged(boolean),
Constant Field Valuesprotected static final org.apache.commons.logging.Log log
protected O bean
protected BeanValidator<?> parentValidator
protected NuitonValidator<O> delegate
protected NuitonValidatorResult messages
protected boolean changed
protected boolean valid
protected boolean canValidate
protected Map<String,String> conversionErrors
protected PropertyChangeListener l
protected PropertyChangeSupport pcs
protected EventListenerList listenerList
protected final NuitonValidatorProvider validatorProvider
NuitonValidatorProvider| Constructor Detail |
|---|
public BeanValidator(NuitonValidatorProvider validatorProvider,
Class<O> beanClass,
String context)
public BeanValidator(NuitonValidatorProvider validatorProvider,
Class<O> beanClass,
String context,
NuitonValidatorScope... scopes)
| Method Detail |
|---|
public boolean isChanged()
changed property value.
Returns true if bean was modified since last
time a bean was attached.
true if bean was modified since last attachement of
a bean.public void setChanged(boolean changed)
changed.
changed - flag to force reset of property changedpublic boolean isCanValidate()
public void setCanValidate(boolean canValidate)
public boolean isValid()
valid property value.
true if attached bean is valid (no error or fatal messages)public void setValid(boolean valid)
valid property.
valid - the new value of the propertypublic O getBean()
null if no bean
is attachedpublic void setBean(O bean)
messages will be reset.
bean - the bean to attach (can be null to reset the
validator).public String getContext()
public void setContext(String context)
public Set<NuitonValidatorScope> getScopes()
public Set<NuitonValidatorScope> getEffectiveScopes()
public Set<String> getEffectiveFields()
public Set<String> getEffectiveFields(NuitonValidatorScope scope)
public void setScopes(NuitonValidatorScope... scopes)
public Class<O> getType()
protected void rebuildDelegateValidator(Class<O> beanType,
String context,
NuitonValidatorScope... scopes)
public BeanValidator<?> getParentValidator()
public void setParentValidator(BeanValidator<?> parentValidator)
public boolean hasFatalErrors()
public boolean hasErrors()
public boolean hasWarnings()
public boolean hasInfos()
public boolean containsField(String fieldName)
fieldName - the name of the searched field
true if validator contaisn this field,
false otherwisepublic boolean isValid(String fieldName)
public NuitonValidatorScope getHighestScope(String field)
public <T> T convert(String fieldName,
String value,
Class<T> valueClass)
T - the type of conversionfieldName - the name of the bean propertyvalue - the value to convertvalueClass - the type of converted value
public void doValidate()
public void validate()
PropertyChangeListener
Note: la methode est protected et on utilise la methode
doValidate() car la méthode ne modifie pas les etats
internes et cela en rend son utilisation delicate (le validateur entre
dans un etat incoherent par rapport aux messages envoyés).
public String toString()
toString in class Objectpublic void addBeanValidatorListener(BeanValidatorListener listener)
public void removeBeanValidatorListener(BeanValidatorListener listener)
public BeanValidatorListener[] getBeanValidatorListeners()
public void addPropertyChangeListener(PropertyChangeListener listener)
public void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
public void removePropertyChangeListener(PropertyChangeListener listener)
public void removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
public void firePropertyChange(String propertyName,
Object oldValue,
Object newValue)
protected BeanValidatorEvent createEvent(String field,
NuitonValidatorScope scope,
String[] toAdd,
String[] toDelete)
protected void fireFieldChanged(String field,
NuitonValidatorScope scope,
String[] toAdd,
String[] toDelete)
protected void fireFieldChanged(BeanValidatorEvent evt)
protected void mergeMessages(NuitonValidatorResult newMessages)
protected void mergeMessages(NuitonValidatorScope scope,
NuitonValidatorResult newMessages,
List<BeanValidatorEvent> events)
protected NuitonValidator<O> getDelegate()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||