Package org.nuiton.validator.bean.list
Class BeanListValidator<O>
- java.lang.Object
-
- org.nuiton.validator.bean.AbstractValidator<O>
-
- org.nuiton.validator.bean.list.BeanListValidator<O>
-
public class BeanListValidator<O> extends AbstractValidator<O>
To validate a list of beans. Each bean of the list will be associated with aBeanListValidator.NuitonValidatorContext.- Since:
- 2.5.2
- Author:
- Tony Chemit - chemit@codelutin.com
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBeanListValidator.NuitonValidatorContext<O>
-
Field Summary
Fields Modifier and Type Field Description protected Map<O,BeanListValidator.NuitonValidatorContext<O>>contextsContext for each bean registred.protected NuitonValidator<O>delegateThe delegate validator used to validate the bean.-
Fields inherited from class org.nuiton.validator.bean.AbstractValidator
canValidate, changed, CHANGED_PROPERTY, CONTEXT_PROPERTY, l, listenerList, pcs, SCOPES_PROPERTY, valid, VALID_PROPERTY, validatorProvider
-
-
Constructor Summary
Constructors Constructor Description BeanListValidator(NuitonValidatorProvider validatorProvider, Class<O> beanClass, String context)BeanListValidator(NuitonValidatorProvider validatorProvider, Class<O> beanClass, String context, NuitonValidatorScope... scopes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAllBeans(Collection<O> beansToAdd)voidaddBean(O bean)Add a bean to validate.voidaddBeanListValidatorListener(BeanListValidatorListener listener)<T> Tconvert(O bean, String fieldName, String value, Class<T> valueClass)Convert a value.voiddoValidate()protected voiddoValidate(O bean)protected voidfireFieldChanged(BeanListValidatorEvent evt)BeanListValidatorListener[]getBeanListValidatorListeners()Set<O>getBeans()BeanListValidator.NuitonValidatorContext<O>getContext(O bean)protected NuitonValidator<O>getDelegate()NuitonValidatorScopegetHighestScope(String field)booleanhasErrors()booleanhasFatalErrors()booleanhasInfos()booleanhasWarnings()booleanisValid(String fieldName)protected booleanisValid0()protected voidmergeMessages(BeanListValidator.NuitonValidatorContext<O> context, NuitonValidatorResult newMessages)static <O> BeanListValidator<O>newValidator(Class<O> type, String context, NuitonValidatorScope... scopes)Obtain a newBeanListValidatorfor the given parameters.static <O> BeanListValidator<O>newValidator(String providerName, Class<O> type, String context, NuitonValidatorScope... scopes)Obtain a newBeanListValidatorfor the given parameters.protected voidrebuildDelegateValidator(Class<O> beanType, String context, NuitonValidatorScope... scopes)voidremoveAllBeans()Shortcut method to unregister all previously registred beans from this validator.voidremoveAllBeans(Collection<O> beansToRemove)Remove all the given beans fro this validator.voidremoveBean(O bean)Remove the given bean from the validaotr.voidremoveBeanListValidatorListener(BeanListValidatorListener listener)protected voidvalidate()il faut eviter le code re-intrant (durant une validation, une autre est demandee).protected voidvalidate(O bean)-
Methods inherited from class org.nuiton.validator.bean.AbstractValidator
addPropertyChangeListener, addPropertyChangeListener, containsField, firePropertyChange, getContext, getEffectiveFields, getEffectiveFields, getEffectiveScopes, getModel, getScopes, getType, isCanValidate, isChanged, isValid, removePropertyChangeListener, removePropertyChangeListener, setCanValidate, setChanged, setContext, setScopes, setValid
-
-
-
-
Field Detail
-
contexts
protected final Map<O,BeanListValidator.NuitonValidatorContext<O>> contexts
Context for each bean registred.- Since:
- 2.5.2
-
delegate
protected NuitonValidator<O> delegate
The delegate validator used to validate the bean.- Since:
- 2.5.2
-
-
Constructor Detail
-
BeanListValidator
public BeanListValidator(NuitonValidatorProvider validatorProvider, Class<O> beanClass, String context)
-
BeanListValidator
public BeanListValidator(NuitonValidatorProvider validatorProvider, Class<O> beanClass, String context, NuitonValidatorScope... scopes)
-
-
Method Detail
-
newValidator
public static <O> BeanListValidator<O> newValidator(Class<O> type, String context, NuitonValidatorScope... scopes) throws NullPointerException
Obtain a newBeanListValidatorfor the given parameters. Note: It will use the default provider ofNuitonValidator- Type Parameters:
O- type of bean to validate- Parameters:
type- type of bean to validatecontext- context of validationscopes- authorized scopes (ifnull, will use all scopes)- Returns:
- the new instanciated
BeanListValidator. - Throws:
NullPointerException- if type isnull- See Also:
NuitonValidatorFactory.getDefaultProviderName()
-
newValidator
public static <O> BeanListValidator<O> newValidator(String providerName, Class<O> type, String context, NuitonValidatorScope... scopes) throws NullPointerException
Obtain a newBeanListValidatorfor the given parameters. Note: It will use the provider ofNuitonValidatordefined by theproviderName.- Type Parameters:
O- type of bean to validate- Parameters:
providerName- name ofNuitonValidatorto usetype- type of bean to validatecontext- context of validationscopes- authorized scopes (ifnull, will use all scopes)- Returns:
- the new instanciated
BeanListValidator. - Throws:
NullPointerException- if type isnull- See Also:
NuitonValidatorFactory.getProvider(String)
-
addBean
public void addBean(O bean)
Add a bean to validate. The bean can not be null, nor registered twice in the validator.- Parameters:
bean- the bean to attach (can not benull).
-
addAllBeans
public void addAllBeans(Collection<O> beansToAdd)
-
removeBean
public void removeBean(O bean)
Remove the given bean from the validaotr. The bean can not benull, nor not has been previously registred in this validator.- Parameters:
bean- the bean to unregister
-
removeAllBeans
public void removeAllBeans(Collection<O> beansToRemove)
Remove all the given beans fro this validator. Like in methodremoveBean(Object), each bean must be notnulland has been previously registred in this validator.- Parameters:
beansToRemove- beans to remove from this validator
-
removeAllBeans
public void removeAllBeans()
Shortcut method to unregister all previously registred beans from this validator.
-
hasFatalErrors
public boolean hasFatalErrors()
- Specified by:
hasFatalErrorsin classAbstractValidator<O>
-
hasErrors
public boolean hasErrors()
- Specified by:
hasErrorsin classAbstractValidator<O>
-
hasWarnings
public boolean hasWarnings()
- Specified by:
hasWarningsin classAbstractValidator<O>
-
hasInfos
public boolean hasInfos()
- Specified by:
hasInfosin classAbstractValidator<O>
-
isValid
public boolean isValid(String fieldName)
- Specified by:
isValidin classAbstractValidator<O>
-
getHighestScope
public NuitonValidatorScope getHighestScope(String field)
- Specified by:
getHighestScopein classAbstractValidator<O>
-
doValidate
public void doValidate()
- Specified by:
doValidatein classAbstractValidator<O>
-
convert
public <T> T convert(O bean, String fieldName, String value, Class<T> valueClass)
Convert a value. If an error occurs, then add an error in validator.- Specified by:
convertin classAbstractValidator<O>- Type Parameters:
T- the type of conversion- Parameters:
fieldName- the name of the bean propertyvalue- the value to convertvalueClass- the type of converted value- Returns:
- the converted value, or null if conversion was not ok
-
addBeanListValidatorListener
public void addBeanListValidatorListener(BeanListValidatorListener listener)
-
removeBeanListValidatorListener
public void removeBeanListValidatorListener(BeanListValidatorListener listener)
-
getBeanListValidatorListeners
public BeanListValidatorListener[] getBeanListValidatorListeners()
-
doValidate
protected void doValidate(O bean)
- Specified by:
doValidatein classAbstractValidator<O>
-
getDelegate
protected NuitonValidator<O> getDelegate()
- Specified by:
getDelegatein classAbstractValidator<O>
-
rebuildDelegateValidator
protected void rebuildDelegateValidator(Class<O> beanType, String context, NuitonValidatorScope... scopes)
- Specified by:
rebuildDelegateValidatorin classAbstractValidator<O>
-
validate
protected void validate()
il faut eviter le code re-intrant (durant une validation, une autre est demandee). Pour cela on fait la validation dans un thread, et tant que la premiere validation n'est pas fini, on ne repond pas aux solicitations. Cette method est public pour permettre de force une validation par programmation, ce qui est utile par exemple si le bean ne supporte pas lesPropertyChangeListenerNote: la methode est protected et on utilise la methodedoValidate()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).
-
validate
protected void validate(O bean)
-
isValid0
protected boolean isValid0()
-
mergeMessages
protected void mergeMessages(BeanListValidator.NuitonValidatorContext<O> context, NuitonValidatorResult newMessages)
-
fireFieldChanged
protected void fireFieldChanged(BeanListValidatorEvent evt)
-
getContext
public BeanListValidator.NuitonValidatorContext<O> getContext(O bean)
-
-