|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.dellroad.stuff.validation.ValidationContext<T>
public class ValidationContext<T>
Provides additional context for ConstraintValidator implementations.
ValidationContext gives ConstraintValidator implementations access to the root object
being validated. This breaks the usual principle of locality for validation (i.e., that validation of a specific bean
proceeds unaware of that bean's parents) but it can make custom validators more convenient to implement.
Subclasses are encouraged to provide additional application-specific information.
Validation must be performed via validate() for this class to work.
| Constructor Summary | |
|---|---|
ValidationContext(T root)
Construct a new validation context configured to validate the given root object. |
|
| Method Summary | ||
|---|---|---|
static
|
getCurrentContext(Class<T> type)
Get the ValidationContext associated with the current thread, cast to the desired type. |
|
static Object |
getCurrentRoot()
Convenience method to get the root object being validated by the current thread. |
|
T |
getRoot()
Get the root object associated with this instance. |
|
Set<ConstraintViolation<T>> |
validate()
Validate this instance's root object. |
|
Set<ConstraintViolation<T>> |
validate(Validator validator)
Validate this instance's root object using the given Validator, making the context
available to the current thread during the validation process via getCurrentContext(java.lang.Class. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ValidationContext(T root)
root - root object to be validated
IllegalArgumentException - if root is null| Method Detail |
|---|
public final T getRoot()
public Set<ConstraintViolation<T>> validate()
validate(Validation.buildDefaultValidatorFactory().getValidator())
- Throws:
IllegalStateException- if this method is invoked re-entrantly
public Set<ConstraintViolation<T>> validate(Validator validator)
Validator, making the context
available to the current thread during the validation process via getCurrentContext(java.lang.Class) .
IllegalStateException - if this method is invoked re-entrantlypublic static <T extends ValidationContext<?>> T getCurrentContext(Class<T> type)
ValidationContext associated with the current thread, cast to the desired type.
This method is only valid during invocations of validate().
type - required type
ValidationContext
IllegalStateException - if validate() is not currently executing
ClassCastException - if the current ValidationContext is not of type typepublic static Object getCurrentRoot()
validate().
Subclasses may want to override to narrow the return type.
IllegalStateException - if validate() is not currently executing
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||