Interface ConstraintLocation
-
- All Known Implementing Classes:
AbstractPropertyConstraintLocation,FieldConstraintLocation,GetterConstraintLocation,ParameterConstraintLocation,TypeArgumentConstraintLocation
public interface ConstraintLocationRepresents the location (e.g. a bean, field or method parameter) of a constraint and provides logic related to it, e.g. for appending the location to a given property path.Note that while the validation engine works on the aggregated meta-model (which e.g. provides a unified view for properties, be them represented via fields or getter methods) most of the time, in some situations the physical element which hosts a constraint is relevant. This includes
- retrieval of property values to be validated (either field or getter access)
- constraint validator resolution; a field and the corresponding getter method may have different types, causing potentially different validators to kick in for the constraints declared on either element
- determination of a constraint's scope (locally defined or up in the hierarchy)
- Author:
- Hardy Ferentschik, Gunnar Morling
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classConstraintLocation.ConstraintLocationKind
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description voidappendTo(ExecutableParameterNameProvider parameterNameProvider, PathImpl path)Appends a node representing this location to the given property path.static ConstraintLocationforClass(Class<?> declaringClass)static ConstraintLocationforCrossParameter(Callable callable)static ConstraintLocationforField(Field field)static ConstraintLocationforGetter(Getter getter)static ConstraintLocationforParameter(Callable callable, int index)static ConstraintLocationforReturnValue(Callable callable)static ConstraintLocationforTypeArgument(ConstraintLocation delegate, TypeVariable<?> typeParameter, Type typeOfAnnotatedElement)ConstrainablegetConstrainable()Returns the member represented by this location.Class<?>getDeclaringClass()Returns the class hosting this location.ConstraintLocation.ConstraintLocationKindgetKind()Returns the nature of the constraint location.TypegetTypeForValidatorResolution()Returns the type to be used when resolving constraint validators for constraints at this location.ObjectgetValue(Object parent)Obtains the value of this location from the parent.
-
-
-
Method Detail
-
forClass
static ConstraintLocation forClass(Class<?> declaringClass)
-
forField
static ConstraintLocation forField(Field field)
-
forGetter
static ConstraintLocation forGetter(Getter getter)
-
forTypeArgument
static ConstraintLocation forTypeArgument(ConstraintLocation delegate, TypeVariable<?> typeParameter, Type typeOfAnnotatedElement)
-
forReturnValue
static ConstraintLocation forReturnValue(Callable callable)
-
forCrossParameter
static ConstraintLocation forCrossParameter(Callable callable)
-
forParameter
static ConstraintLocation forParameter(Callable callable, int index)
-
getDeclaringClass
Class<?> getDeclaringClass()
Returns the class hosting this location.
-
getConstrainable
Constrainable getConstrainable()
Returns the member represented by this location.- Returns:
- the member represented by this location. Will be
nullwhen this location represents a type.
-
getTypeForValidatorResolution
Type getTypeForValidatorResolution()
Returns the type to be used when resolving constraint validators for constraints at this location. Note that this is not always the same type as the type of the element described by this location; E.g. the wrapper type will is used for constraint validator resolution, if a constraint is declared in an element with a primitive type.- Returns:
- The type to be used when resolving constraint validators for constraints at this location
-
appendTo
void appendTo(ExecutableParameterNameProvider parameterNameProvider, PathImpl path)
Appends a node representing this location to the given property path.
-
getValue
Object getValue(Object parent)
Obtains the value of this location from the parent. The type of the passed parent depends on the location type, e.g. a bean would be passed for aAbstractPropertyConstraintLocationbut an object array for aParameterConstraintLocation.
-
getKind
ConstraintLocation.ConstraintLocationKind getKind()
Returns the nature of the constraint location.
-
-