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.SimpleBeanValidator
will then used one of this object andBeanListValidator
as many as it contains beans. This object box aNuitonValidator
to 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 O
bean
Bean to validate.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 Map<String,String>
conversionErrors
map of conversion errors detected by this validatorprotected NuitonValidatorResult
messages
State of validation (keep all messages of validation for the filled bean).protected NuitonValidator<O>
validator
Validator.
-
Constructor Summary
Constructors Constructor Description AbstractNuitonValidatorContext()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T> T
convert(String fieldName, String value, Class<T> valueClass)
Convert a value.protected abstract E
createEvent(V source, O bean, String field, NuitonValidatorScope scope, String[] toAdd, String[] toDelete)
O
getBean()
NuitonValidatorScope
getHighestScope(String field)
NuitonValidatorResult
getMessages()
NuitonValidator<O>
getValidator()
boolean
hasErrors()
boolean
hasFatalErrors()
boolean
hasInfos()
boolean
hasWarnings()
boolean
isCanValidate()
boolean
isValid()
boolean
isValid(String fieldName)
List<E>
mergeMessages(V beanValidator, NuitonValidatorResult newMessages)
protected void
mergeMessages(V beanValidator, NuitonValidatorScope scope, NuitonValidatorResult newMessages, List<E> events)
void
setBean(O bean)
void
setCanValidate(boolean canValidate)
void
setValidator(NuitonValidator<O> validator)
NuitonValidatorResult
validate()
-
-
-
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)
-
-