Top Description Inners Fields Constructors Methods
org.hibernate.validator.internal.engine.valueextraction

public Class ValueExtractorResolver

extends Object
Class Inheritance
Imports
java.lang.invoke.MethodHandles, java.lang.reflect.Type, .TypeVariable, java.util.Collection, .Collections, .HashSet, .Iterator, .Map, .Objects, .Set, java.util.concurrent.ConcurrentHashMap, java.util.stream.Collectors, jakarta.validation.ConstraintDeclarationException, jakarta.validation.valueextraction.ValueExtractor, org.hibernate.validator.internal.metadata.aggregated.CascadingMetaDataBuilder, .ContainerCascadingMetaData, .PotentiallyContainerCascadingMetaData, org.hibernate.validator.internal.util.CollectionHelper, .Contracts, .ReflectionHelper, .TypeHelper, .TypeVariableBindings, .TypeVariables, org.hibernate.validator.internal.util.logging.Log, .LoggerFactory, org.hibernate.validator.internal.util.stereotypes.Immutable

Contains resolving algorithms for ValueExtractors, and caches for these extractors based on container types.
Authors
Gunnar Morling, Guillaume Smet, Marko Bekhta

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final Log
private final Set<Class<?>>
private final ConcurrentHashMap<Class<?>, Set<ValueExtractorDescriptor>>
private final ConcurrentHashMap<ValueExtractorResolver.ValueExtractorCacheKey, Set<ValueExtractorDescriptor>>
private final Set<ValueExtractorDescriptor>

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private TypeVariable<?>
bind(TypeVariable<?> typeParameter, Map<TypeVariable<?>, TypeVariable<?>> bindings)

private boolean
checkValueExtractorTypeCompatibility(TypeVariable<?> typeParameter, boolean isInternal, Class<?> erasedDeclaredType, ValueExtractorDescriptor extractorDescriptor)

public void
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.

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.

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.

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.

private Set<ValueExtractorDescriptor>
private Set<ValueExtractorDescriptor>
getPotentiallyRuntimeTypeCompliantAndContainerElementCompliantValueExtractors(Type declaredType, TypeVariable<?> typeParameter)

Returns the set of potentially type-compliant and container-element-compliant value extractors or an empty set if none was found.

public Set<ValueExtractorDescriptor>

Returns:

a set of ValueExtractorDescriptors that possibly might be applied to a declaredType at a runtime.
getPotentialValueExtractorCandidatesForCascadedValidation
(Type declaredType)

Used to determine the value extractors which potentially could be applied to the runtime type of a given declared type.

private Set<ValueExtractorDescriptor>
private Set<ValueExtractorDescriptor>

Returns:

a set of runtime compliant value extractors based on a runtime type. If there are no available value extractors an empty set will be returned which means the type is not a container.
getRuntimeCompliantValueExtractors
(Class<?> runtimeType, Set<ValueExtractorDescriptor> potentialValueExtractorDescriptors)

private ValueExtractorDescriptor
getUniqueValueExtractorOrThrowException(Class<?> runtimeType, Set<ValueExtractorDescriptor> maximallySpecificContainerElementCompliantValueExtractors)

public Set<ValueExtractorDescriptor>
getValueExtractorCandidatesForCascadedValidation(Type declaredType, TypeVariable<?> typeParameter)

Used to determine the value extractor candidates valid for a declared type and type variable.

public Set<ValueExtractorDescriptor>
getValueExtractorCandidatesForContainerDetectionOfGlobalCascadedValidation(Type enclosingType)

Used to determine the possible value extractors that can be applied to a declared type.

private boolean
validateValueExtractorCompatibility(boolean isInternal, Class<?> typeForBinding, Class<?> typeToBind, TypeVariable<?> typeParameterForBinding, TypeVariable<?> typeParameterToCompare)

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

LOGback to summary
private static final Log LOG
nonContainerTypesback to summary
private final Set<Class<?>> nonContainerTypes
possibleValueExtractorsByRuntimeTypeback to summary
private final ConcurrentHashMap<Class<?>, Set<ValueExtractorDescriptor>> possibleValueExtractorsByRuntimeType
possibleValueExtractorsByRuntimeTypeAndTypeParameterback to summary
private final ConcurrentHashMap<ValueExtractorResolver.ValueExtractorCacheKey, Set<ValueExtractorDescriptor>> possibleValueExtractorsByRuntimeTypeAndTypeParameter
registeredValueExtractorsback to summary
private final Set<ValueExtractorDescriptor> registeredValueExtractors
Annotations
@Immutable

Constructor Detail

ValueExtractorResolverback to summary
pack-priv ValueExtractorResolver(Set<ValueExtractorDescriptor> valueExtractors)

Method Detail

bindback to summary
private TypeVariable<?> bind(TypeVariable<?> typeParameter, Map<TypeVariable<?>, TypeVariable<?>> bindings)
checkValueExtractorTypeCompatibilityback to summary
private boolean checkValueExtractorTypeCompatibility(TypeVariable<?> typeParameter, boolean isInternal, Class<?> erasedDeclaredType, ValueExtractorDescriptor extractorDescriptor)
clearback to summary
public void clear()
getMaximallySpecificAndContainerElementCompliantValueExtractorback to summary
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.

Exceptions
ConstraintDeclarationException:
if more than 2 maximally specific container-element-compliant value extractors are found
getMaximallySpecificAndRuntimeContainerElementCompliantValueExtractorback to summary
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.

Exceptions
ConstraintDeclarationException:
if more than 2 maximally specific container-element-compliant value extractors are found
See Also
ValueExtractorResolver#getMaximallySpecificAndRuntimeContainerElementCompliantValueExtractor(Type, TypeVariable, Class, Collection)
getMaximallySpecificValueExtractorForAllContainerElementsback to summary
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.

Exceptions
ConstraintDeclarationException:
if more than 2 maximally specific container-element-compliant value extractors are found
getMaximallySpecificValueExtractorsback to summary
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.

getMaximallySpecificValueExtractorsback to summary
private Set<ValueExtractorDescriptor> getMaximallySpecificValueExtractors(Set<ValueExtractorDescriptor> possibleValueExtractors)
getPotentiallyRuntimeTypeCompliantAndContainerElementCompliantValueExtractorsback to summary
private Set<ValueExtractorDescriptor> getPotentiallyRuntimeTypeCompliantAndContainerElementCompliantValueExtractors(Type declaredType, TypeVariable<?> typeParameter)

Returns the set of potentially type-compliant and container-element-compliant value extractors or an empty set if none was found.

A value extractor is potentially runtime type compliant if it might be compliant for any runtime type that matches the declared type.

getPotentialValueExtractorCandidatesForCascadedValidationback to summary
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:Set<ValueExtractorDescriptor>

a set of ValueExtractorDescriptors that possibly might be applied to a declaredType at a runtime.

getRuntimeAndContainerElementCompliantValueExtractorsFromPossibleCandidatesback to summary
private Set<ValueExtractorDescriptor> getRuntimeAndContainerElementCompliantValueExtractorsFromPossibleCandidates(Type declaredType, TypeVariable<?> typeParameter, Class<?> runtimeType, Collection<ValueExtractorDescriptor> valueExtractorCandidates)
getRuntimeCompliantValueExtractorsback to summary
private Set<ValueExtractorDescriptor> getRuntimeCompliantValueExtractors(Class<?> runtimeType, Set<ValueExtractorDescriptor> potentialValueExtractorDescriptors)
Returns:Set<ValueExtractorDescriptor>

a set of runtime compliant value extractors based on a runtime type. If there are no available value extractors an empty set will be returned which means the type is not a container.

getUniqueValueExtractorOrThrowExceptionback to summary
private ValueExtractorDescriptor getUniqueValueExtractorOrThrowException(Class<?> runtimeType, Set<ValueExtractorDescriptor> maximallySpecificContainerElementCompliantValueExtractors)
getValueExtractorCandidatesForCascadedValidationback to summary
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.

getValueExtractorCandidatesForContainerDetectionOfGlobalCascadedValidationback to summary
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.

validateValueExtractorCompatibilityback to summary
private boolean validateValueExtractorCompatibility(boolean isInternal, Class<?> typeForBinding, Class<?> typeToBind, TypeVariable<?> typeParameterForBinding, TypeVariable<?> typeParameterToCompare)
org.hibernate.validator.internal.engine.valueextraction back to summary

private Class ValueExtractorResolver.ValueExtractorCacheKey

extends Object
Class Inheritance
  • java.lang.Object
  • org.hibernate.validator.internal.engine.valueextraction.ValueExtractorResolver.ValueExtractorCacheKey

Field Summary

Modifier and TypeField and Description
private int
private Class<?>
private TypeVariable<?>

Constructor Summary

AccessConstructor and Description
pack-priv
ValueExtractorCacheKey(Class<?> type, TypeVariable<?> typeParameter)

Method Summary

Modifier and TypeMethod and Description
private int
public boolean
equals(Object
the reference object with which to compare.
o
)

Overrides java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.
public int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
Inherited from java.lang.Object:
clonefinalizegetClassnotifynotifyAlltoStringwaitwaitwait

Field Detail

hashCodeback to summary
private int hashCode
typeback to summary
private Class<?> type
typeParameterback to summary
private TypeVariable<?> typeParameter

Constructor Detail

ValueExtractorCacheKeyback to summary
pack-priv ValueExtractorCacheKey(Class<?> type, TypeVariable<?> typeParameter)

Method Detail

buildHashCodeback to summary
private int buildHashCode()
equalsback to summary
public boolean equals(Object o)

Overrides java.lang.Object.equals.

Doc from java.lang.Object.equals.

Indicates whether some other object is "equal to" this one.

The equals method implements an equivalence relation on non-null object references:

  • It is reflexive: for any non-null reference value x, x.equals(x) should return true.
  • It is symmetric: for any non-null reference values x and y, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any non-null reference values x, y, and z, if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.
  • It is consistent: for any non-null reference values x and y, multiple invocations of x.equals(y) consistently return true or consistently return false, provided no information used in equals comparisons on the objects is modified.
  • For any non-null reference value x, x.equals(null) should return false.

An equivalence relation partitions the elements it operates on into equivalence classes; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

Parameters
o:Object

the reference object with which to compare.

Returns:boolean

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
hashCodeback to summary
public int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override