Top Description Inners Fields Constructors Methods
org.hibernate.validator.internal.metadata.aggregated

public Class ExecutableMetaData

extends AbstractConstraintMetaData
Class Inheritance
Static Imports
org.hibernate.validator.internal.util.CollectionHelper.newArrayList, .CollectionHelper.newHashMap, .CollectionHelper.newHashSet

An aggregated view of the constraint related meta data for a given method or constructors and in (case of methods) all the methods in the inheritance hierarchy which it overrides or implements.

Instances are retrieved by creating a Builder and adding all required ConstrainedExecutable objects to it. Instances are read-only after creation.

Identity is solely based on the method's name and parameter types, hence sets and similar collections of this type may only be created in the scope of one Java type.

Author
Gunnar Morling

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class

Field Summary

Modifier and TypeField and Description
private final Set<MetaConstraint<?>>
private final boolean
private final ElementKind
private final List<ParameterMetaData>
private final Class<?>[]
private final ReturnValueMetaData
private final Set<Signature>
signatures

Set of signatures for storing this object in maps etc. Will only contain more than one entry in case this method overrides a super type method with generic parameters, in which case the signature of the super-type and the sub-type method will differ.

private final ValidatableParametersMetaData

Constructor Summary

AccessConstructor and Description
private
ExecutableMetaData(String name, Type returnType, Class<?>[] parameterTypes, ElementKind kind, Set<Signature> signatures, Set<MetaConstraint<?>> returnValueConstraints, Set<MetaConstraint<?>> returnValueContainerElementConstraints, List<ParameterMetaData> parameterMetaDataList, Set<MetaConstraint<?>> crossParameterConstraints, CascadingMetaData cascadingMetaData, boolean isConstrained, boolean isGetter)

Method Summary

Modifier and TypeMethod and Description
public ExecutableDescriptorImpl
asDescriptor(boolean
Whether the bean hosting the represented element has a redefined default group sequence or not.
defaultGroupSequenceRedefined
,
List<Class<?>>
The default group sequence of the bean hosting the represented element.
defaultGroupSequence
)

Implements org.hibernate.validator.internal.metadata.aggregated.ConstraintMetaData.asDescriptor.

Returns this meta data object's corresponding representation in the descriptor model.
public boolean
equals(Object
the reference object with which to compare.
obj
)

Overrides org.hibernate.validator.internal.metadata.aggregated.AbstractConstraintMetaData.equals.

Indicates whether some other object is "equal to" this one.
public Set<MetaConstraint<?>>

Returns:

the cross-parameter constraints declared for the represented method or constructor. May be empty but will never be null.
getCrossParameterConstraints
()

Returns the cross-parameter constraints declared for the represented method or constructor.

public ElementKind
public ParameterMetaData

Returns:

Meta data for the specified parameter. Will never be null.
getParameterMetaData
(int
the index of the parameter
parameterIndex
)

Returns meta data for the specified parameter of the represented executable.

public Class<?>[]
public ReturnValueMetaData
public Set<Signature>

Returns:

The signatures of this meta data object. Will only contain more than one element in case the represented method represents a sub-type method overriding a super-type method using a generic type parameter in its parameters.
getSignatures
()

Returns the signature(s) of the method represented by this meta data object, based on the represented executable's name and its parameter types.

public ValidatableParametersMetaData
public int
private List<ParameterDescriptor>
parametersAsDescriptors(boolean defaultGroupSequenceRedefined, List<Class<?>> defaultGroupSequence)

public String
Inherited from org.hibernate.validator.internal.metadata.aggregated.AbstractConstraintMetaData:
asContainerElementTypeDescriptorsasDescriptorsgetAllConstraintsgetContainerElementsConstraintsgetDirectConstraintsgetNamegetTypeisCascadingisConstrainediterator

Field Detail

crossParameterConstraintsback to summary
private final Set<MetaConstraint<?>> crossParameterConstraints
Annotations
@Immutable
isGetterback to summary
private final boolean isGetter
kindback to summary
private final ElementKind kind
parameterMetaDataListback to summary
private final List<ParameterMetaData> parameterMetaDataList
Annotations
@Immutable
parameterTypesback to summary
private final Class<?>[] parameterTypes
returnValueMetaDataback to summary
private final ReturnValueMetaData returnValueMetaData
signaturesback to summary
private final Set<Signature> signatures

Set of signatures for storing this object in maps etc. Will only contain more than one entry in case this method overrides a super type method with generic parameters, in which case the signature of the super-type and the sub-type method will differ.

validatableParametersMetaDataback to summary
private final ValidatableParametersMetaData validatableParametersMetaData

Constructor Detail

ExecutableMetaDataback to summary
private ExecutableMetaData(String name, Type returnType, Class<?>[] parameterTypes, ElementKind kind, Set<Signature> signatures, Set<MetaConstraint<?>> returnValueConstraints, Set<MetaConstraint<?>> returnValueContainerElementConstraints, List<ParameterMetaData> parameterMetaDataList, Set<MetaConstraint<?>> crossParameterConstraints, CascadingMetaData cascadingMetaData, boolean isConstrained, boolean isGetter)

Method Detail

asDescriptorback to summary
public ExecutableDescriptorImpl asDescriptor(boolean defaultGroupSequenceRedefined, List<Class<?>> defaultGroupSequence)

Implements org.hibernate.validator.internal.metadata.aggregated.ConstraintMetaData.asDescriptor.

Doc from org.hibernate.validator.internal.metadata.aggregated.ConstraintMetaData.asDescriptor.

Returns this meta data object's corresponding representation in the descriptor model.

Parameters
defaultGroupSequenceRedefined:boolean

Whether the bean hosting the represented element has a redefined default group sequence or not.

defaultGroupSequence:List<Class<?>>

The default group sequence of the bean hosting the represented element.

Returns:ExecutableDescriptorImpl

This meta data object's corresponding descriptor model representation. Implementations should return a specific sub type of ElementDescriptor.

Annotations
@Override
equalsback to summary
public boolean equals(Object obj)

Overrides org.hibernate.validator.internal.metadata.aggregated.AbstractConstraintMetaData.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
obj: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
getCrossParameterConstraintsback to summary
public Set<MetaConstraint<?>> getCrossParameterConstraints()

Returns the cross-parameter constraints declared for the represented method or constructor.

Returns:Set<MetaConstraint<?>>

the cross-parameter constraints declared for the represented method or constructor. May be empty but will never be null.

getKindback to summary
public ElementKind getKind()

Implements org.hibernate.validator.internal.metadata.aggregated.ConstraintMetaData.getKind.

Doc from org.hibernate.validator.internal.metadata.aggregated.ConstraintMetaData.getKind.

Returns the kind of this meta data object.

Returns:ElementKind

The kind of this meta data object.

Annotations
@Override
getParameterMetaDataback to summary
public ParameterMetaData getParameterMetaData(int parameterIndex)

Returns meta data for the specified parameter of the represented executable.

Parameters
parameterIndex:int

the index of the parameter

Returns:ParameterMetaData

Meta data for the specified parameter. Will never be null.

getParameterTypesback to summary
public Class<?>[] getParameterTypes()
getReturnValueMetaDataback to summary
public ReturnValueMetaData getReturnValueMetaData()
getSignaturesback to summary
public Set<Signature> getSignatures()

Returns the signature(s) of the method represented by this meta data object, based on the represented executable's name and its parameter types.

Returns:Set<Signature>

The signatures of this meta data object. Will only contain more than one element in case the represented method represents a sub-type method overriding a super-type method using a generic type parameter in its parameters.

getValidatableParametersMetaDataback to summary
public ValidatableParametersMetaData getValidatableParametersMetaData()
hashCodeback to summary
public int hashCode()

Overrides org.hibernate.validator.internal.metadata.aggregated.AbstractConstraintMetaData.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
parametersAsDescriptorsback to summary
private List<ParameterDescriptor> parametersAsDescriptors(boolean defaultGroupSequenceRedefined, List<Class<?>> defaultGroupSequence)
toStringback to summary
public String toString()

Overrides org.hibernate.validator.internal.metadata.aggregated.AbstractConstraintMetaData.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
org.hibernate.validator.internal.metadata.aggregated back to summary

public Class ExecutableMetaData.Builder

extends MetaDataBuilder
Class Inheritance

Creates new ExecutableMetaData instances.
Authors
Gunnar Morling, Kevin Pollet <[email protected]> (C) 2011 SERLI

Field Summary

Modifier and TypeField and Description
private Callable
private CascadingMetaDataBuilder
private final Set<ConstrainedExecutable>
private final Set<MetaConstraint<?>>
private final ExecutableHelper
private final Map<Class<?>, ConstrainedExecutable>
executablesByDeclaringType

Holds a merged representation of the configurations for one method from the hierarchy contributed by the different meta data providers.

private boolean
private final ConstrainedElement.ConstrainedElementKind
kind

Either CONSTRUCTOR, METHOD or GETTER.

private final ExecutableParameterNameProvider
private final Set<MethodConfigurationRule>
private final Set<Signature>
Inherited from org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder:
constraintCreationContext

Constructor Summary

AccessConstructor and Description
public
Builder(Class<?> beanClass, ConstrainedExecutable constrainedExecutable, ConstraintCreationContext constraintCreationContext, ExecutableHelper executableHelper, ExecutableParameterNameProvider parameterNameProvider, MethodValidationConfiguration methodValidationConfiguration)

Method Summary

Modifier and TypeMethod and Description
public boolean
accepts(ConstrainedElement
The element to check.
constrainedElement
)

Implements abstract org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder.accepts.

Whether this builder allows to add the given element or not.
public final void
add(ConstrainedElement
The element to add.
constrainedElement
)

Overrides org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder.add.

Adds the given element to this builder.
private void
addToExecutablesByDeclaringType(ConstrainedExecutable
The executable to merge.
executable
)

Merges the given executable with the metadata contributed by other providers for the same executable in the hierarchy.

private void
assertCorrectnessOfConfiguration()

Checks the configuration of this method for correctness as per the rules outlined in the Bean Validation specification, section 4.5.5 ("Method constraints in inheritance hierarchies").

public ExecutableMetaData
build()

Implements abstract org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder.build.

Creates a new, read-only ConstraintMetaData object with all constraint information related to the method or property represented by this builder.
private List<ParameterMetaData>

Returns:

The parameter meta data for this builder's executable.
findParameterMetaData
()

Finds the one executable from the underlying hierarchy with parameter constraints.

private boolean
private boolean
private boolean
overrides(Callable first, Callable other)

Inherited from org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder:
adaptConstraintsadaptOriginsAndImplicitGroupsgetBeanClassgetContainerElementConstraintsgetDirectConstraintsisCascading

Field Detail

callableback to summary
private Callable callable
cascadingMetaDataBuilderback to summary
private CascadingMetaDataBuilder cascadingMetaDataBuilder
constrainedExecutablesback to summary
private final Set<ConstrainedExecutable> constrainedExecutables
crossParameterConstraintsback to summary
private final Set<MetaConstraint<?>> crossParameterConstraints
executableHelperback to summary
private final ExecutableHelper executableHelper
executablesByDeclaringTypeback to summary
private final Map<Class<?>, ConstrainedExecutable> executablesByDeclaringType

Holds a merged representation of the configurations for one method from the hierarchy contributed by the different meta data providers. Used to check for violations of the Liskov substitution principle by e.g. adding parameter constraints in sub type methods.

isConstrainedback to summary
private boolean isConstrained
kindback to summary
private final ConstrainedElement.ConstrainedElementKind kind

Either CONSTRUCTOR, METHOD or GETTER.

parameterNameProviderback to summary
private final ExecutableParameterNameProvider parameterNameProvider
rulesback to summary
private final Set<MethodConfigurationRule> rules
signaturesback to summary
private final Set<Signature> signatures

Constructor Detail

Builderback to summary
public Builder(Class<?> beanClass, ConstrainedExecutable constrainedExecutable, ConstraintCreationContext constraintCreationContext, ExecutableHelper executableHelper, ExecutableParameterNameProvider parameterNameProvider, MethodValidationConfiguration methodValidationConfiguration)

Method Detail

acceptsback to summary
public boolean accepts(ConstrainedElement constrainedElement)

Implements abstract org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder.accepts.

Doc from org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder.accepts.

Whether this builder allows to add the given element or not. This is the case if the specified element relates to the same property or method with which this builder was instantiated.

Parameters
constrainedElement:ConstrainedElement

The element to check.

Returns:boolean

true if the given element can be added to this builder, false otherwise.

Annotations
@Override
addback to summary
public final void add(ConstrainedElement constrainedElement)

Overrides org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder.add.

Doc from org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder.add.

Adds the given element to this builder. It must be checked with accepts(ConstrainedElement) before, whether this is allowed or not.

Parameters
constrainedElement:ConstrainedElement

The element to add.

Annotations
@Override
addToExecutablesByDeclaringTypeback to summary
private void addToExecutablesByDeclaringType(ConstrainedExecutable executable)

Merges the given executable with the metadata contributed by other providers for the same executable in the hierarchy.

Parameters
executable:ConstrainedExecutable

The executable to merge.

assertCorrectnessOfConfigurationback to summary
private void assertCorrectnessOfConfiguration()

Checks the configuration of this method for correctness as per the rules outlined in the Bean Validation specification, section 4.5.5 ("Method constraints in inheritance hierarchies").

In particular, overriding methods in sub-types may not add parameter constraints and the return value of an overriding method may not be marked as cascaded if the return value is marked as cascaded already on the overridden method.

Exceptions
ConstraintDeclarationException:
In case any of the rules mandated by the specification are violated.
buildback to summary
public ExecutableMetaData build()

Implements abstract org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder.build.

Doc from org.hibernate.validator.internal.metadata.aggregated.MetaDataBuilder.build.

Creates a new, read-only ConstraintMetaData object with all constraint information related to the method or property represented by this builder.

Returns:ExecutableMetaData

A ConstraintMetaData object.

Annotations
@Override
findParameterMetaDataback to summary
private List<ParameterMetaData> findParameterMetaData()

Finds the one executable from the underlying hierarchy with parameter constraints. If no executable in the hierarchy is parameter constrained, the parameter meta data from this builder's base executable is returned.

Returns:List<ParameterMetaData>

The parameter meta data for this builder's executable.

isConstructorback to summary
private boolean isConstructor(Callable callable)
isResolvedToSameMethodInHierarchyback to summary
private boolean isResolvedToSameMethodInHierarchy(Callable first, Callable other)
overridesback to summary
private boolean overrides(Callable first, Callable other)