Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  * JBoss, Home of Professional Open Source
  * Copyright 2011, Red Hat, Inc. and/or its affiliates, and individual contributors
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * See the License for the specific language governing permissions and
 * limitations under the License.
 package org.hibernate.validator.internal.metadata;
 import java.util.List;
 import static org.hibernate.validator.internal.util.CollectionHelper.newArrayList;
 import static org.hibernate.validator.internal.util.ConcurrentReferenceHashMap.Option.IDENTITY_COMPARISONS;
 import static org.hibernate.validator.internal.util.ConcurrentReferenceHashMap.ReferenceType.SOFT;

This manager is in charge of providing all constraint related meta data required by the validation engine.

Actual retrieval of meta data is delegated to org.hibernate.validator.internal.metadata.provider.MetaDataProvider implementations which load meta-data based e.g. based on annotations or XML.

For performance reasons a cache is used which stores all meta data once loaded for repeated retrieval. Upon initialization this cache is populated with meta data provided by the given eager providers. If the cache doesn't contain the meta data for a requested type it will be retrieved on demand using the annotation based provider.

Gunnar Morling
 public class BeanMetaDataManager {
The default initial capacity for this cache.
 	static final int DEFAULT_INITIAL_CAPACITY = 16;

The default load factor for this cache.
 	static final float DEFAULT_LOAD_FACTOR = 0.75f;

The default concurrency level for this cache.
 	static final int DEFAULT_CONCURRENCY_LEVEL = 16;

Additional metadata providers used for meta data retrieval if the XML and/or programmatic configuration is used.
Helper for builtin constraints and their validator implementations
 	private final ConstraintHelper constraintHelper;

Used to cache the constraint meta data for validated entities
 	public BeanMetaDataManager(ConstraintHelper constraintHelperMetaDataProvider... metaDataProviders) {
 		thisconstraintHelper, Arrays.asListmetaDataProviders ) );

constraintHelper the constraint helper
optionalMetaDataProviders optional meta data provider used on top of the annotation based provider
 	public BeanMetaDataManager(ConstraintHelper constraintHelper,
 							   List<MetaDataProvideroptionalMetaDataProviders) {
 		this. = constraintHelper;
 		this..addAlloptionalMetaDataProviders );
		this..adddefaultProvider );
	public <T> BeanMetaData<T> getBeanMetaData(Class<T> beanClass) {
		// TODO - Avoid usages of Messages class until is resolved (HF)
		Contracts.assertNotNullbeanClass"The bean type cannot be null." );
		BeanMetaData<T> beanMetaData = (BeanMetaData<T>) .getbeanClass );
		// create a new BeanMetaData in case none is cached
		if ( beanMetaData == null ) {
			beanMetaData = createBeanMetaDatabeanClass );
			final BeanMetaData<T> cachedBeanMetaData = (BeanMetaData<T>) .putIfAbsent(
			if ( cachedBeanMetaData != null ) {
				beanMetaData = cachedBeanMetaData;
		return beanMetaData;

Creates a org.hibernate.validator.internal.metadata.aggregated.BeanMetaData containing the meta data from all meta data providers for the given type and its hierarchy.

<T> The type of interest.
clazz The type's class.
A bean meta data object for the given type.
	private <T> BeanMetaDataImpl<T> createBeanMetaData(Class<T> clazz) {
		BeanMetaDataBuilder<T> builder = BeanMetaDataBuilder.getInstanceclazz );
		for ( MetaDataProvider provider :  ) {
			for ( BeanConfiguration<? super T> beanConfiguration : provider.getBeanConfigurationForHierarchyclazz ) ) {
				builder.addbeanConfiguration );

returns the annotation ignores from the non annotation based meta data providers
		for ( MetaDataProvider metaDataProvider :  ) {
			options.mergemetaDataProvider.getAnnotationProcessingOptions() );
		return options;
New to GrepCode? Check out our FAQ X