public class BeanValidationContext<T extends ValidationListener> extends Object implements ValidationContext<T>
Validation
and the BeanValidator do their jobs.
Used to bundle BeanValidationContext and ValidationListener
together | Modifier and Type | Field and Description |
|---|---|
protected Map |
validatedObjects
set of objects already validated to avoid endless loops.
|
| Modifier | Constructor and Description |
|---|---|
|
BeanValidationContext(T listener)
Create a new BeanValidationContext instance.
|
protected |
BeanValidationContext(T listener,
Map validatedMap)
Create a new BeanValidationContext instance.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
collectValidated()
Avoid recursion by recording the current state of this context as having been validated.
|
AccessStrategy |
getAccess()
Get the current access strategy.
|
Object |
getBean()
Get the bean.
|
T |
getListener()
Get the
ValidationListener. |
FeaturesCapable |
getMeta()
Depending on whether we have a metaProperty or not,
this returns the metaProperty or otherwise the metaBean.
|
MetaBean |
getMetaBean()
Get the model meta-bean.
|
MetaProperty |
getMetaProperty()
Get the model meta-property.
|
String |
getPropertyName()
Convenience method to access metaProperty.name
|
Object |
getPropertyValue()
Get the cached value or access it somehow (via field or method)
you should prefer getPropertyValue(AccessStrategy) instead of this method |
Object |
getPropertyValue(AccessStrategy access)
Get the value by using the given access strategy.
|
boolean |
isFixed()
Learn whether the current property value is "fixed."
|
boolean |
isValidated(Object object)
Learn whether a particular object has been validated.
|
void |
moveDown(MetaProperty prop,
AccessStrategy access)
Step deeper into association at 'prop'
|
void |
moveDown(String prop) |
void |
moveUp(Object bean,
MetaBean aMetaBean)
Step out from a validation of associated objects.
|
void |
resetValidated()
Clear map of validated objects (invoke when you want to 'reuse' the
context for different validations)
|
void |
setBean(Object bean)
Set the bean.
|
void |
setBean(Object aBean,
MetaBean aMetaBean)
Set the current bean/metabean.
|
void |
setCurrentIndex(Integer index)
Set the index of the object currently validated into the context.
|
void |
setCurrentKey(Object key)
set the key of the object in a map currently validated into the context.
|
void |
setFixed(boolean fixed)
Potentially declare the current property value as being "fixed."
If
true, the context will reuse any not-UNKNOWN
propertyValue regardless of the AccessStrategy by which it is requested. |
void |
setFixedValue(Object value)
Set the property value, fixed.
|
void |
setListener(T listener)
Set the listener.
|
void |
setMetaBean(MetaBean metaBean)
Set the model meta-bean.
|
void |
setMetaProperty(MetaProperty metaProperty)
Set the current meta-property.
|
void |
setPropertyValue(Object propertyValue)
Set the current property value.
|
String |
toString() |
void |
unknownValue()
Drop cached value, marking the internal cachedValue as
UNKNOWN. |
protected Map validatedObjects
public BeanValidationContext(T listener)
listener - public T getListener()
ValidationListener.getListener in interface ValidationContext<T extends ValidationListener>public void setListener(T listener)
listener - Tpublic boolean collectValidated()
collectValidated in interface ValidationContext<T extends ValidationListener>public boolean isValidated(Object object)
object - public void resetValidated()
public void setBean(Object aBean, MetaBean aMetaBean)
setBean in interface ValidationContext<T extends ValidationListener>public Object getPropertyValue()
getPropertyValue in interface ValidationContext<T extends ValidationListener>IllegalArgumentException - - error accessing attribute (config error, reflection problem)IllegalStateException - - when no property is currently set in the context (application logic bug)public Object getPropertyValue(AccessStrategy access) throws IllegalArgumentException, IllegalStateException
getPropertyValue in interface ValidationContext<T extends ValidationListener>ObjectIllegalArgumentExceptionIllegalStateExceptionpublic String getPropertyName()
getPropertyName in interface ValidationContext<T extends ValidationListener>public void setPropertyValue(Object propertyValue)
propertyValue - public void setFixedValue(Object value)
value - public boolean isFixed()
public void setFixed(boolean fixed)
true, the context will reuse any not-UNKNOWN
propertyValue regardless of the AccessStrategy by which it is requested.fixed - public FeaturesCapable getMeta()
public void unknownValue()
UNKNOWN.
This forces the BeanValidationContext to recompute the value
the next time it is accessed.
Use this method inside tests or when the propertyValue has been
changed during validation.public MetaBean getMetaBean()
getMetaBean in interface ValidationContext<T extends ValidationListener>MetaBeanpublic Object getBean()
getBean in interface ValidationContext<T extends ValidationListener>Objectpublic MetaProperty getMetaProperty()
getMetaProperty in interface ValidationContext<T extends ValidationListener>MetaPropertypublic void setMetaBean(MetaBean metaBean)
setMetaBean in interface ValidationContext<T extends ValidationListener>public void setBean(Object bean)
setBean in interface ValidationContext<T extends ValidationListener>public void setMetaProperty(MetaProperty metaProperty)
setMetaProperty in interface ValidationContext<T extends ValidationListener>public void moveDown(MetaProperty prop, AccessStrategy access)
moveDown in interface ValidationContext<T extends ValidationListener>public void moveDown(String prop)
moveDown in interface ValidationContext<T extends ValidationListener>public void moveUp(Object bean, MetaBean aMetaBean)
moveUp in interface ValidationContext<T extends ValidationListener>public void setCurrentIndex(Integer index)
setCurrentIndex in interface ValidationContext<T extends ValidationListener>public void setCurrentKey(Object key)
setCurrentKey in interface ValidationContext<T extends ValidationListener>public AccessStrategy getAccess()
getAccess in interface ValidationContext<T extends ValidationListener>AccessStrategyCopyright © 2010–2024 The Apache Software Foundation. All rights reserved.