Package org.nuiton.validator.bean
Class AbstractNuitonValidatorContext<O,V,E>
- java.lang.Object
-
- org.nuiton.validator.bean.AbstractNuitonValidatorContext<O,V,E>
-
- Type Parameters:
O- type of bean to validateV- type of bean validator usedE- type of event to create
- Direct Known Subclasses:
BeanListValidator.NuitonValidatorContext,SimpleBeanValidator.NuitonValidatorContext
public abstract class AbstractNuitonValidatorContext<O,V,E> extends Object
Defines a context of validation used for a single bean.SimpleBeanValidatorwill then used one of this object andBeanListValidatoras many as it contains beans. This object box aNuitonValidatorto get validation state each time a higher validator requires it. It also offers the way to create events (merge logic- Since:
- 2.5.2
- Author:
- Tony Chemit - chemit@codelutin.com
-
-
Field Summary
Fields Modifier and Type Field Description protected ObeanBean to validate.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 Map<String,String>conversionErrorsmap of conversion errors detected by this validatorprotected NuitonValidatorResultmessagesState of validation (keep all messages of validation for the filled bean).protected NuitonValidator<O>validatorValidator.
-
Constructor Summary
Constructors Constructor Description AbstractNuitonValidatorContext()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T> Tconvert(String fieldName, String value, Class<T> valueClass)Convert a value.protected abstract EcreateEvent(V source, O bean, String field, NuitonValidatorScope scope, String[] toAdd, String[] toDelete)OgetBean()NuitonValidatorScopegetHighestScope(String field)NuitonValidatorResultgetMessages()NuitonValidator<O>getValidator()booleanhasErrors()booleanhasFatalErrors()booleanhasInfos()booleanhasWarnings()booleanisCanValidate()booleanisValid()booleanisValid(String fieldName)List<E>mergeMessages(V beanValidator, NuitonValidatorResult newMessages)protected voidmergeMessages(V beanValidator, NuitonValidatorScope scope, NuitonValidatorResult newMessages, List<E> events)voidsetBean(O bean)voidsetCanValidate(boolean canValidate)voidsetValidator(NuitonValidator<O> validator)NuitonValidatorResultvalidate()
-
-
-
Field Detail
-
bean
protected O bean
Bean to validate.
-
messages
protected NuitonValidatorResult messages
State of validation (keep all messages of validation for the filled bean).
-
validator
protected NuitonValidator<O> validator
Validator.
-
conversionErrors
protected final Map<String,String> conversionErrors
map of conversion errors detected by this validator
-
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...).
-
-
Method Detail
-
createEvent
protected abstract E createEvent(V source, O bean, String field, NuitonValidatorScope scope, String[] toAdd, String[] toDelete)
-
getBean
public O getBean()
-
setBean
public void setBean(O bean)
-
getValidator
public NuitonValidator<O> getValidator()
-
getMessages
public NuitonValidatorResult getMessages()
-
isCanValidate
public boolean isCanValidate()
-
setCanValidate
public void setCanValidate(boolean canValidate)
-
isValid
public boolean isValid()
-
hasFatalErrors
public boolean hasFatalErrors()
-
hasErrors
public boolean hasErrors()
-
hasWarnings
public boolean hasWarnings()
-
hasInfos
public boolean hasInfos()
-
isValid
public boolean isValid(String fieldName)
-
getHighestScope
public NuitonValidatorScope getHighestScope(String field)
-
setValidator
public void setValidator(NuitonValidator<O> validator)
-
validate
public NuitonValidatorResult validate()
-
convert
public <T> T convert(String fieldName, String value, Class<T> valueClass)
Convert a value. If an error occurs, then add an error in validator.- 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
-
mergeMessages
public List<E> mergeMessages(V beanValidator, NuitonValidatorResult newMessages)
-
mergeMessages
protected void mergeMessages(V beanValidator, NuitonValidatorScope scope, NuitonValidatorResult newMessages, List<E> events)
-
-