org.hibernate.validator.metadata
Class BeanMetaDataImpl<T>

java.lang.Object
  extended by org.hibernate.validator.metadata.BeanMetaDataImpl<T>
All Implemented Interfaces:
BeanMetaData<T>

public final class BeanMetaDataImpl<T>
extends Object
implements BeanMetaData<T>

This class encapsulates all meta data needed for validation. Implementations of Validator interface can instantiate an instance of this class and delegate the metadata extraction to it.

Author:
Hardy Ferentschik, Gunnar Morling, Kevin Pollet - SERLI - (kevin.pollet@serli.com)

Field Summary
static String DEFAULT_PARAMETER_NAME_PREFIX
          Used as prefix for parameter names, if no explicit names are given.
 
Constructor Summary
BeanMetaDataImpl(Class<T> beanClass, ConstraintHelper constraintHelper, BeanMetaDataCache beanMetaDataCache)
          Constructor used for creating the bean meta data using annotations only
BeanMetaDataImpl(Class<T> beanClass, ConstraintHelper constraintHelper, List<Class<?>> defaultGroupSequence, Class<? extends DefaultGroupSequenceProvider<?>> defaultGroupSequenceProvider, Map<Class<?>,List<BeanMetaConstraint<?>>> constraints, Set<AggregatedMethodMetaData> methodMetaDatas, Set<Member> cascadedMembers, AnnotationIgnores annotationIgnores, BeanMetaDataCache beanMetaDataCache)
          Constructor used when creating a bean meta data instance via the xml or programmatic API.
 
Method Summary
 boolean defaultGroupSequenceIsRedefined()
           
 Set<AggregatedMethodMetaData> getAllMethodMetaData()
          Returns the constraint-related meta data for all the methods of the type represented by this bean meta data.
 Class<T> getBeanClass()
           
 BeanDescriptor getBeanDescriptor()
           
 Set<Member> getCascadedMembers()
           
 List<Class<?>> getClassHierarchy()
           
 Set<PropertyDescriptor> getConstrainedProperties()
           
 List<Class<?>> getDefaultGroupSequence(T beanState)
          Get the composition of the default group sequence.
 Set<BeanMetaConstraint<?>> getDirectMetaConstraints()
           
 Set<BeanMetaConstraint<?>> getMetaConstraints()
           
 Map<Class<?>,List<BeanMetaConstraint<?>>> getMetaConstraintsAsMap()
           
 AggregatedMethodMetaData getMetaDataFor(Method method)
          Returns the constraint-related meta data for the given method of the class represented by this bean meta data.
 PropertyDescriptor getPropertyDescriptor(String property)
          Return PropertyDescriptor for the given property.
 TypeDescriptor getTypeDescriptor()
           
 boolean isPropertyPresent(String name)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_PARAMETER_NAME_PREFIX

public static final String DEFAULT_PARAMETER_NAME_PREFIX
Used as prefix for parameter names, if no explicit names are given.

See Also:
Constant Field Values
Constructor Detail

BeanMetaDataImpl

public BeanMetaDataImpl(Class<T> beanClass,
                        ConstraintHelper constraintHelper,
                        BeanMetaDataCache beanMetaDataCache)
Constructor used for creating the bean meta data using annotations only

Parameters:
beanClass - The bean type for which to create the meta data
constraintHelper - constraint helper
beanMetaDataCache - the cache of already configured meta data instances

BeanMetaDataImpl

public BeanMetaDataImpl(Class<T> beanClass,
                        ConstraintHelper constraintHelper,
                        List<Class<?>> defaultGroupSequence,
                        Class<? extends DefaultGroupSequenceProvider<?>> defaultGroupSequenceProvider,
                        Map<Class<?>,List<BeanMetaConstraint<?>>> constraints,
                        Set<AggregatedMethodMetaData> methodMetaDatas,
                        Set<Member> cascadedMembers,
                        AnnotationIgnores annotationIgnores,
                        BeanMetaDataCache beanMetaDataCache)
Constructor used when creating a bean meta data instance via the xml or programmatic API. In this case additional metadata (the already configured constraints, cascaded members, etc) are passed as well.

Parameters:
beanClass - The bean type for which to create the meta data
constraintHelper - constraint helper
defaultGroupSequence - programmatic/xml configured default group sequence (overrides annotations)
defaultGroupSequenceProvider - programmatic configured default group sequence provider class (overrides annotations)
constraints - programmatic/xml configured constraints
methodMetaDatas - programmatic configured method constraints
cascadedMembers - programmatic/xml configured cascaded members
annotationIgnores - in xml configured ignores for annotations
beanMetaDataCache - the cache of already configured meta data instances
Method Detail

getBeanClass

public Class<T> getBeanClass()
Specified by:
getBeanClass in interface BeanMetaData<T>
Returns:
the class of the bean.

getBeanDescriptor

public BeanDescriptor getBeanDescriptor()
Specified by:
getBeanDescriptor in interface BeanMetaData<T>
Returns:
an instance of ElementDescriptor describing the bean this meta data applies for.

getTypeDescriptor

public TypeDescriptor getTypeDescriptor()
Specified by:
getTypeDescriptor in interface BeanMetaData<T>
Returns:
An instance of TypeDescriptor describing the bean this meta data applies for.

getCascadedMembers

public Set<Member> getCascadedMembers()
Specified by:
getCascadedMembers in interface BeanMetaData<T>
Returns:
A list of all cascaded methods and fields (methods/fields annotated with @Valid).

getMetaConstraintsAsMap

public Map<Class<?>,List<BeanMetaConstraint<?>>> getMetaConstraintsAsMap()

getMetaConstraints

public Set<BeanMetaConstraint<?>> getMetaConstraints()
Specified by:
getMetaConstraints in interface BeanMetaData<T>
Returns:
A set of MetaConstraint instances encapsulating the information of all the constraints defined on the bean. This collection includes constraints from super classes as well

getDirectMetaConstraints

public Set<BeanMetaConstraint<?>> getDirectMetaConstraints()
Specified by:
getDirectMetaConstraints in interface BeanMetaData<T>
Returns:
A set of MetaConstraint instances encapsulating the information of all the constraints defined on the bean directly (including constraints defined on implemented interfaces). It does not contain constraints from super classes or interfaces implemented by super classes

getMetaDataFor

public AggregatedMethodMetaData getMetaDataFor(Method method)
Description copied from interface: BeanMetaData
Returns the constraint-related meta data for the given method of the class represented by this bean meta data.

Specified by:
getMetaDataFor in interface BeanMetaData<T>
Parameters:
method - The method of interest.
Returns:
An aggregated view on the constraint related meta data from the given method all the methods from super-types which it overrides or implements.

getAllMethodMetaData

public Set<AggregatedMethodMetaData> getAllMethodMetaData()
Description copied from interface: BeanMetaData
Returns the constraint-related meta data for all the methods of the type represented by this bean meta data.

Specified by:
getAllMethodMetaData in interface BeanMetaData<T>
Returns:
A set with constraint-related method meta data. May be empty, but will never be null.

getPropertyDescriptor

public PropertyDescriptor getPropertyDescriptor(String property)
Description copied from interface: BeanMetaData
Return PropertyDescriptor for the given property.

Specified by:
getPropertyDescriptor in interface BeanMetaData<T>
Parameters:
property - the property for which to retrieve the descriptor.
Returns:
Returns the PropertyDescriptor for the given property or null in case the property does not have a descriptor.

isPropertyPresent

public boolean isPropertyPresent(String name)
Specified by:
isPropertyPresent in interface BeanMetaData<T>
Parameters:
name - The name of the property
Returns:
true if the property exists on the object even if the property does not host any constraint nor is cascaded

getDefaultGroupSequence

public List<Class<?>> getDefaultGroupSequence(T beanState)
Description copied from interface: BeanMetaData
Get the composition of the default group sequence.

If the bean state is given in parameter and the bean metadata has a default group sequence provider then the dynamic default group sequence composition is returned. In the other cases the default group sequence redefinition specified by BV is used.

Specified by:
getDefaultGroupSequence in interface BeanMetaData<T>
Parameters:
beanState - the bean state.
Returns:
a list of classes representing the default group sequence.

defaultGroupSequenceIsRedefined

public boolean defaultGroupSequenceIsRedefined()
Specified by:
defaultGroupSequenceIsRedefined in interface BeanMetaData<T>
Returns:
true if the entity redefines the default group sequence, false otherwise.

getConstrainedProperties

public Set<PropertyDescriptor> getConstrainedProperties()
Specified by:
getConstrainedProperties in interface BeanMetaData<T>
Returns:
the property descriptors having at least one constraint defined or which are marked as cascaded (@Valid).

getClassHierarchy

public List<Class<?>> getClassHierarchy()
Specified by:
getClassHierarchy in interface BeanMetaData<T>
Returns:
Returns a list of classes representing the class hierarchy for the entity. The list start with the element itself and goes up the hierarchy chain. Interfaces are not included.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2007-2011 Red Hat Middleware, LLC. All Rights Reserved