Interface ConstraintLocation

All Known Implementing Classes:
AbstractPropertyConstraintLocation, FieldConstraintLocation, GetterConstraintLocation, ParameterConstraintLocation, TypeArgumentConstraintLocation

public interface ConstraintLocation
Represents 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
  • Method Details

    • 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 null when 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 a AbstractPropertyConstraintLocation but an object array for a ParameterConstraintLocation.
    • getKind

      Returns the nature of the constraint location.