Class ValueExtractorResolver

java.lang.Object
org.hibernate.validator.internal.engine.valueextraction.ValueExtractorResolver

public class ValueExtractorResolver extends Object
Contains resolving algorithms for ValueExtractors, and caches for these extractors based on container types.
Author:
Gunnar Morling, Guillaume Smet, Marko Bekhta
  • Method Details

    • getMaximallySpecificValueExtractors

      public Set<ValueExtractorDescriptor> getMaximallySpecificValueExtractors(Class<?> declaredType)
      Used to find all the maximally specific value extractors based on a declared type in the case of value unwrapping.

      There might be several of them as there might be several type parameters.

      Used for container element constraints.

    • getMaximallySpecificAndContainerElementCompliantValueExtractor

      public ValueExtractorDescriptor getMaximallySpecificAndContainerElementCompliantValueExtractor(Class<?> declaredType, TypeVariable<?> typeParameter)
      Used to find the maximally specific and container element compliant value extractor based on the declared type and the type parameter.

      Used for container element constraints.

      Throws:
      ConstraintDeclarationException - if more than 2 maximally specific container-element-compliant value extractors are found
    • getMaximallySpecificAndRuntimeContainerElementCompliantValueExtractor

      public ValueExtractorDescriptor getMaximallySpecificAndRuntimeContainerElementCompliantValueExtractor(Type declaredType, TypeVariable<?> typeParameter, Class<?> runtimeType, Collection<ValueExtractorDescriptor> valueExtractorCandidates)
      Used to find the maximally specific and container element compliant value extractor based on the runtime type.

      The maximally specific one is chosen among the candidates passed to this method.

      Used for cascading validation.

      Throws:
      ConstraintDeclarationException - if more than 2 maximally specific container-element-compliant value extractors are found
      See Also:
    • getMaximallySpecificValueExtractorForAllContainerElements

      public ValueExtractorDescriptor getMaximallySpecificValueExtractorForAllContainerElements(Class<?> runtimeType, Set<ValueExtractorDescriptor> potentialValueExtractorDescriptors)
      Used to determine if the passed runtime type is a container and if so return a corresponding maximally specific value extractor.

      Obviously, it only works if there's only one value extractor corresponding to the runtime type as we don't precise any type parameter.

      There is a special case: when the passed type is assignable to a Map, the MapValueExtractor will be returned. This is required by the Bean Validation specification.

      Used for cascading validation when the @Valid annotation is placed on the whole container.

      Throws:
      ConstraintDeclarationException - if more than 2 maximally specific container-element-compliant value extractors are found
    • getValueExtractorCandidatesForCascadedValidation

      public Set<ValueExtractorDescriptor> getValueExtractorCandidatesForCascadedValidation(Type declaredType, TypeVariable<?> typeParameter)
      Used to determine the value extractor candidates valid for a declared type and type variable.

      The effective value extractor will be narrowed from these candidates using the runtime type.

      Used to optimize the choice of the value extractor in the case of cascading validation.

    • getValueExtractorCandidatesForContainerDetectionOfGlobalCascadedValidation

      public Set<ValueExtractorDescriptor> getValueExtractorCandidatesForContainerDetectionOfGlobalCascadedValidation(Type enclosingType)
      Used to determine the possible value extractors that can be applied to a declared type.

      Used when building cascading metadata in CascadingMetaDataBuilder to decide if it should be promoted to ContainerCascadingMetaData with cascaded constrained type arguments.

      An example could be when we need to upgrade BV 1.1 style @Valid private List<SomeBean> list; to private List<@Valid SomeBean> list;

      Searches only for maximally specific value extractors based on a type.

      Types that are assignable to Map are handled as a special case - key value extractor is ignored for them.

    • getPotentialValueExtractorCandidatesForCascadedValidation

      public Set<ValueExtractorDescriptor> getPotentialValueExtractorCandidatesForCascadedValidation(Type declaredType)
      Used to determine the value extractors which potentially could be applied to the runtime type of a given declared type.

      An example could be when there's a declaration like private PotentiallyContainerAtRuntime<@Valid Bean>; and there's no value extractor present for PotentiallyContainerAtRuntime but there's one available for Container extends PotentiallyContainerAtRuntime.

      Returned set of extractors is used to determine if at runtime a value extractor can be applied to a runtime type, and if PotentiallyContainerCascadingMetaData should be promoted to ContainerCascadingMetaData.

      Returns:
      a set of ValueExtractorDescriptors that possibly might be applied to a declaredType at a runtime.
    • clear

      public void clear()