Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* 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
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.hibernate.validator.internal.cfg.context;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.hibernate.validator.internal.metadata.core.AnnotationProcessingOptionsImpl;
import org.hibernate.validator.internal.metadata.location.BeanConstraintLocation;
import org.hibernate.validator.internal.metadata.location.ExecutableConstraintLocation;
import org.hibernate.validator.spi.group.DefaultGroupSequenceProvider;
import static org.hibernate.validator.internal.util.CollectionHelper.newHashMap;
import static org.hibernate.validator.internal.util.CollectionHelper.newHashSet;
/**
* Context which collects constraints, cascades etc. configured via the programmatic API.
*
* @author Hardy Ferentschik
* @author Gunnar Morling
* @author Kevin Pollet (C) 2011 SERLI
*/
public class ConstraintMappingContext {
private final Map, Set>> constraintConfig;
private final Map, Set>> methodConstraintConfig;
private final Map, Set> cascadeConfig;
private final Map, Set> methodCascadeConfig;
private final Set> configuredClasses;
private final Map, List>> defaultGroupSequences;
private final Map, Class>> defaultGroupSequenceProviders;
private final AnnotationProcessingOptionsImpl annotationProcessingOptions;
public ConstraintMappingContext() {
this.constraintConfig = newHashMap();
this.methodConstraintConfig = newHashMap();
this.cascadeConfig = newHashMap();
this.methodCascadeConfig = newHashMap();
this.configuredClasses = newHashSet();
this.defaultGroupSequences = newHashMap();
this.defaultGroupSequenceProviders = newHashMap();
this.annotationProcessingOptions = new AnnotationProcessingOptionsImpl();
}
/**
* Returns all constraint definitions registered with this mapping.
*
* @return A map with this mapping's constraint definitions. Each key in
* this map represents a bean type, for which the constraint
* definitions in the associated map value are configured.
*/
public final Map, Set>> getConstraintConfig() {
return constraintConfig;
}
public Map, Set>> getMethodConstraintConfig() {
return methodConstraintConfig;
}
public final Map, Set> getCascadeConfig() {
return cascadeConfig;
}
public final Map, Set> getMethodCascadeConfig() {
return methodCascadeConfig;
}
public final Collection> getConfiguredClasses() {
return configuredClasses;
}
public final List> getDefaultSequence(Class beanType) {
return defaultGroupSequences.get( beanType );
}
public final AnnotationProcessingOptionsImpl getAnnotationProcessingOptions() {
return annotationProcessingOptions;
}
/**
* Returns the class of the default group sequence provider defined
* for the given bean type.
*
* @param beanType The bean type.
*
* @return The default group sequence provider defined class or {@code null} if none.
*/
@SuppressWarnings( "unchecked" )
public final Class> getDefaultGroupSequenceProvider(Class beanType) {
return (Class>) defaultGroupSequenceProviders.get( beanType );
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append( "ConstraintMapping" );
sb.append( "{cascadeConfig=" ).append( cascadeConfig );
sb.append( ", methodCascadeConfig=" ).append( methodCascadeConfig );
sb.append( ", constraintConfig=" ).append( constraintConfig );
sb.append( ", configuredClasses=" ).append( configuredClasses );
sb.append( ", defaultGroupSequences=" ).append( defaultGroupSequences );
sb.append( '}' );
return sb.toString();
}
public final void addCascadeConfig(BeanConstraintLocation cascade) {
Class beanClass = cascade.getBeanClass();
configuredClasses.add( beanClass );
if ( cascadeConfig.containsKey( beanClass ) ) {
cascadeConfig.get( beanClass ).add( cascade );
}
else {
Set cascadeList = newHashSet();
cascadeList.add( cascade );
cascadeConfig.put( beanClass, cascadeList );
}
}
public final void addMethodCascadeConfig(ExecutableConstraintLocation cascade) {
Class beanClass = cascade.getBeanClass();
configuredClasses.add( beanClass );
if ( methodCascadeConfig.containsKey( beanClass ) ) {
methodCascadeConfig.get( beanClass ).add( cascade );
}
else {
Set cascadeList = newHashSet();
cascadeList.add( cascade );
methodCascadeConfig.put( beanClass, cascadeList );
}
}
public final void addDefaultGroupSequence(Class beanClass, List> defaultGroupSequence) {
configuredClasses.add( beanClass );
defaultGroupSequences.put( beanClass, defaultGroupSequence );
}
public final void addDefaultGroupSequenceProvider(Class beanClass, Class> defaultGroupSequenceProviderClass) {
configuredClasses.add( beanClass );
defaultGroupSequenceProviders.put( beanClass, defaultGroupSequenceProviderClass );
}
public final void addConstraintConfig(ConfiguredConstraint constraint) {
Class beanClass = constraint.getLocation().getBeanClass();
configuredClasses.add( beanClass );
if ( constraintConfig.containsKey( beanClass ) ) {
constraintConfig.get( beanClass ).add( constraint );
}
else {
Set> definitionList = newHashSet();
definitionList.add( constraint );
constraintConfig.put( beanClass, definitionList );
}
}
public final void addMethodConstraintConfig(ConfiguredConstraint constraint) {
Class beanClass = constraint.getLocation().getBeanClass();
configuredClasses.add( beanClass );
if ( methodConstraintConfig.containsKey( beanClass ) ) {
methodConstraintConfig.get( beanClass ).add( constraint );
}
else {
Set> definitionList = newHashSet();
definitionList.add( constraint );
methodConstraintConfig.put( beanClass, definitionList );
}
}
}