public class SimpleBeanValidator<O> extends AbstractValidator<O>
context.
A such validator is also a JavaBean and you can listen his states
modifications via the classic java bean api.
Note: The SimpleBeanValidator should never be used for
validation in a service approch since it needs to keep a reference to the
bean to validate.SimpleBeanValidatorListener| Modifier and Type | Class and Description |
|---|---|
protected static class |
SimpleBeanValidator.NuitonValidatorContext<O> |
| Modifier and Type | Field and Description |
|---|---|
static String |
BEAN_PROPERTY
Name of the bounded property
bean. |
protected SimpleBeanValidator.NuitonValidatorContext<O> |
context
Context of the registred bean to validate.
|
protected SimpleBeanValidator<?> |
parentValidator
To chain to another validator (acting as parent of this one).
|
canValidate, changed, CHANGED_PROPERTY, CONTEXT_PROPERTY, l, listenerList, pcs, SCOPES_PROPERTY, valid, VALID_PROPERTY, validatorProvider| Constructor and Description |
|---|
SimpleBeanValidator(NuitonValidatorProvider validatorProvider,
Class<O> beanClass,
String context) |
SimpleBeanValidator(NuitonValidatorProvider validatorProvider,
Class<O> beanClass,
String context,
NuitonValidatorScope... scopes) |
| Modifier and Type | Method and Description |
|---|---|
void |
addSimpleBeanValidatorListener(SimpleBeanValidatorListener listener) |
<T> T |
convert(O bean,
String fieldName,
String value,
Class<T> valueClass) |
<T> T |
convert(String fieldName,
String value,
Class<T> valueClass)
Convert a value.
|
void |
doValidate() |
protected void |
doValidate(O bean) |
protected void |
fireFieldChanged(SimpleBeanValidatorEvent evt) |
O |
getBean()
Obtain the actual bean attached to the validator.
|
protected NuitonValidator<O> |
getDelegate() |
NuitonValidatorScope |
getHighestScope(String field) |
SimpleBeanValidator<?> |
getParentValidator() |
SimpleBeanValidatorListener[] |
getSimpleBeanValidatorListeners() |
boolean |
hasErrors() |
boolean |
hasFatalErrors() |
boolean |
hasInfos() |
boolean |
hasWarnings() |
boolean |
isValid(String fieldName) |
protected void |
mergeMessages(NuitonValidatorResult newMessages) |
static <O> SimpleBeanValidator<O> |
newValidator(Class<O> type,
String context,
NuitonValidatorScope... scopes)
Obtain a new
SimpleBeanValidator for the given parameters. |
static <O> SimpleBeanValidator<O> |
newValidator(String providerName,
Class<O> type,
String context,
NuitonValidatorScope... scopes)
Obtain a new
SimpleBeanValidator for the given parameters. |
protected void |
rebuildDelegateValidator(Class<O> beanType,
String context,
NuitonValidatorScope... scopes) |
void |
removeSimpleBeanValidatorListener(SimpleBeanValidatorListener listener) |
void |
setBean(O bean)
Change the attached bean.
|
void |
setParentValidator(SimpleBeanValidator<?> parentValidator) |
protected void |
validate()
il faut eviter le code re-intrant (durant une validation, une autre est
demandee).
|
addPropertyChangeListener, addPropertyChangeListener, containsField, firePropertyChange, getContext, getEffectiveFields, getEffectiveFields, getEffectiveScopes, getModel, getScopes, getType, isCanValidate, isChanged, isValid, removePropertyChangeListener, removePropertyChangeListener, setCanValidate, setChanged, setContext, setScopes, setValidpublic static final String BEAN_PROPERTY
bean.getBean(),
setBean(Object),
Constant Field Valuesprotected final SimpleBeanValidator.NuitonValidatorContext<O> context
protected SimpleBeanValidator<?> parentValidator
public SimpleBeanValidator(NuitonValidatorProvider validatorProvider, Class<O> beanClass, String context)
public SimpleBeanValidator(NuitonValidatorProvider validatorProvider, Class<O> beanClass, String context, NuitonValidatorScope... scopes)
public static <O> SimpleBeanValidator<O> newValidator(Class<O> type, String context, NuitonValidatorScope... scopes) throws NullPointerException
SimpleBeanValidator for the given parameters.
Note: It will use the default provider of NuitonValidatorO - type of bean to validatetype - type of bean to validatecontext - context of validationscopes - authorized scopes (if null, will use all scopes)SimpleBeanValidator.NullPointerException - if type is nullNuitonValidatorFactory.getDefaultProviderName()public static <O> SimpleBeanValidator<O> newValidator(String providerName, Class<O> type, String context, NuitonValidatorScope... scopes) throws NullPointerException
SimpleBeanValidator for the given parameters.
Note: It will use the provider of NuitonValidator
defined by the providerName.O - type of bean to validateproviderName - name of NuitonValidator to usetype - type of bean to validatecontext - context of validationscopes - authorized scopes (if null, will use all scopes)SimpleBeanValidator.NullPointerException - if type is nullNuitonValidatorFactory.getProvider(String)public O getBean()
null if no bean
is attachedpublic void setBean(O bean)
AbstractNuitonValidatorContext.messages will be reset.bean - the bean to attach (can be null to reset the
validator).public SimpleBeanValidator<?> getParentValidator()
public void setParentValidator(SimpleBeanValidator<?> parentValidator)
public boolean hasFatalErrors()
hasFatalErrors in class AbstractValidator<O>public boolean hasErrors()
hasErrors in class AbstractValidator<O>public boolean hasWarnings()
hasWarnings in class AbstractValidator<O>public boolean hasInfos()
hasInfos in class AbstractValidator<O>public boolean isValid(String fieldName)
isValid in class AbstractValidator<O>public NuitonValidatorScope getHighestScope(String field)
getHighestScope in class AbstractValidator<O>public <T> T convert(O bean, String fieldName, String value, Class<T> valueClass)
convert in class AbstractValidator<O>public void doValidate()
doValidate in class AbstractValidator<O>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 valuepublic void addSimpleBeanValidatorListener(SimpleBeanValidatorListener listener)
public void removeSimpleBeanValidatorListener(SimpleBeanValidatorListener listener)
public SimpleBeanValidatorListener[] getSimpleBeanValidatorListeners()
protected void doValidate(O bean)
doValidate in class AbstractValidator<O>protected NuitonValidator<O> getDelegate()
getDelegate in class AbstractValidator<O>protected void rebuildDelegateValidator(Class<O> beanType, String context, NuitonValidatorScope... scopes)
rebuildDelegateValidator in class AbstractValidator<O>protected 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).protected void fireFieldChanged(SimpleBeanValidatorEvent evt)
protected void mergeMessages(NuitonValidatorResult newMessages)
Copyright © 2013 CodeLutin. All rights reserved.