Class AbstractConfigurationImpl<T extends BaseHibernateValidatorConfiguration<T>>
- All Implemented Interfaces:
Configuration<T>
,ConfigurationState
,BaseHibernateValidatorConfiguration<T>
- Direct Known Subclasses:
ConfigurationImpl
,PredefinedScopeConfigurationImpl
Configuration
implementation.- Author:
- Emmanuel Bernard, Hardy Ferentschik, Gunnar Morling, Kevin Pollet <kevin.pollet@serli.com> (C) 2011 SERLI, Chris Beckey <cbeckey@paypal.com>, Guillaume Smet
-
Field Summary
Fields inherited from interface org.hibernate.validator.BaseHibernateValidatorConfiguration
ALLOW_MULTIPLE_CASCADED_VALIDATION_ON_RESULT, ALLOW_PARALLEL_METHODS_DEFINE_PARAMETER_CONSTRAINTS, ALLOW_PARAMETER_CONSTRAINT_OVERRIDE, CONSTRAINT_EXPRESSION_LANGUAGE_FEATURE_LEVEL, CONSTRAINT_MAPPING_CONTRIBUTOR, CONSTRAINT_MAPPING_CONTRIBUTORS, CUSTOM_VIOLATION_EXPRESSION_LANGUAGE_FEATURE_LEVEL, ENABLE_TRAVERSABLE_RESOLVER_RESULT_CACHE, FAIL_FAST, GETTER_PROPERTY_SELECTION_STRATEGY_CLASSNAME, LOCALE_RESOLVER_CLASSNAME, PROPERTY_NODE_NAME_PROVIDER_CLASSNAME, SCRIPT_EVALUATOR_FACTORY_CLASSNAME, SHOW_VALIDATED_VALUE_IN_TRACE_LOGS, TEMPORAL_VALIDATION_TOLERANCE
-
Constructor Summary
ModifierConstructorDescriptionprotected
protected
AbstractConfigurationImpl
(ValidationProvider<?> provider) -
Method Summary
Modifier and TypeMethodDescriptionfinal T
addMapping
(InputStream stream) final T
addMapping
(ConstraintMapping mapping) Adds the specifiedConstraintMapping
instance to the configuration.final T
addProperty
(String name, String value) addValueExtractor
(ValueExtractor<?> extractor) allowMultipleCascadedValidationOnReturnValues
(boolean allow) Define whether more than one constraint on a return value may be marked for cascading validation are allowed.allowOverridingMethodAlterParameterConstraint
(boolean allow) Define whether overriding methods that override constraints should throw aConstraintDefinitionException
.allowParallelMethodsDefineParameterConstraints
(boolean allow) Define whether parallel methods that define constraints should throw aConstraintDefinitionException
.beanMetaDataClassNormalizer
(BeanMetaDataClassNormalizer beanMetaDataClassNormalizer) final ValidatorFactory
clockProvider
(ClockProvider clockProvider) constraintExpressionLanguageFeatureLevel
(ExpressionLanguageFeatureLevel expressionLanguageFeatureLevel) Allows setting the Expression Language feature level for message interpolation of constraint messages.final T
constraintValidatorFactory
(ConstraintValidatorFactory constraintValidatorFactory) constraintValidatorPayload
(Object constraintValidatorPayload) Allows to set a payload which will be passed to the constraint validators.final DefaultConstraintMapping
Creates a new constraint mapping which can be used to programmatically configure the constraints for given types.customViolationExpressionLanguageFeatureLevel
(ExpressionLanguageFeatureLevel expressionLanguageFeatureLevel) Allows setting the Expression Language feature level for message interpolation of custom violation messages.defaultLocale
(Locale defaultLocale) Allows setting the default locale used to interpolate the constraint violation messages.final T
enableTraversableResolverResultCache
(boolean enabled) Define whether the per validation call caching ofTraversableResolver
results is enabled.externalClassLoader
(ClassLoader externalClassLoader) Sets the class loader to be used for loading user-provided resources: XML descriptors (META-INF/validation.xml
as well as XML constraint mappings) classes specified by name in XML descriptors (e.g.final T
failFast
(boolean failFast) En- or disables the fail fast mode.final MessageInterpolator
final ResourceBundleLocator
Returns theResourceBundleLocator
used by thedefault message interpolator
to load user-provided resource bundles.final TraversableResolver
Set<ValueExtractor<?>>
Returns the defaultValueExtractor
implementations as per the specification.final boolean
final Set<InputStream>
final MessageInterpolator
final Set<DefaultConstraintMapping>
final boolean
getterPropertySelectionStrategy
(GetterPropertySelectionStrategy getterPropertySelectionStrategy) Allows to set a getter property selection strategy defining the rules determining if a method is a getter or not.final TraversableResolver
Set<ValueExtractor<?>>
final T
boolean
boolean
boolean
final boolean
final boolean
localeResolver
(LocaleResolver localeResolver) Allows setting a locale resolver, defining how the locale will be resolved when interpolating the message of a constraint violation.Allows setting the list of the locales supported by this ValidatorFactory.final T
messageInterpolator
(MessageInterpolator interpolator) parameterNameProvider
(ParameterNameProvider parameterNameProvider) protected abstract boolean
propertyNodeNameProvider
(PropertyNodeNameProvider propertyNodeNameProvider) Allows to set a property node name provider, defining how the name of a property node will be resolved when constructing a property path as the one returned byConstraintViolation.getPropertyPath()
.scriptEvaluatorFactory
(ScriptEvaluatorFactory scriptEvaluatorFactory) Allows to specify a customScriptEvaluatorFactory
responsible for creatingScriptEvaluator
s used to evaluate script expressions forScriptAssert
andParameterScriptAssert
constraints.showValidatedValuesInTraceLogs
(boolean enabled) Allows setting the logging configuration that would include validated values in trace level logs.temporalValidationTolerance
(Duration temporalValidationTolerance) Allows to set the acceptable margin of error when comparing date/time in temporal constraints such asPast
/PastOrPresent
andFuture
/FutureOrPresent
.protected T
thisAsT()
final T
traversableResolver
(TraversableResolver resolver) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.hibernate.validator.BaseHibernateValidatorConfiguration
locales
-
Constructor Details
-
AbstractConfigurationImpl
-
AbstractConfigurationImpl
-
-
Method Details
-
ignoreXmlConfiguration
- Specified by:
ignoreXmlConfiguration
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
messageInterpolator
- Specified by:
messageInterpolator
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
traversableResolver
- Specified by:
traversableResolver
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
enableTraversableResolverResultCache
Description copied from interface:BaseHibernateValidatorConfiguration
Define whether the per validation call caching ofTraversableResolver
results is enabled. The default value istrue
, i.e. the caching is enabled.This behavior was initially introduced to cache the
JPATraversableResolver
results but the map lookups it introduces can be counterproductive when theTraversableResolver
calls are very fast.- Specified by:
enableTraversableResolverResultCache
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
enabled
- flag determining whether per validation call caching is enabled forTraversableResolver
results.- Returns:
this
following the chaining method pattern
-
isTraversableResolverResultCacheEnabled
public final boolean isTraversableResolverResultCacheEnabled() -
constraintValidatorFactory
- Specified by:
constraintValidatorFactory
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
parameterNameProvider
- Specified by:
parameterNameProvider
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
clockProvider
- Specified by:
clockProvider
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
propertyNodeNameProvider
Description copied from interface:BaseHibernateValidatorConfiguration
Allows to set a property node name provider, defining how the name of a property node will be resolved when constructing a property path as the one returned byConstraintViolation.getPropertyPath()
.- Specified by:
propertyNodeNameProvider
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
propertyNodeNameProvider
- thePropertyNodeNameProvider
to be used- Returns:
this
following the chaining method pattern
-
localeResolver
Description copied from interface:BaseHibernateValidatorConfiguration
Allows setting a locale resolver, defining how the locale will be resolved when interpolating the message of a constraint violation.- Specified by:
localeResolver
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
localeResolver
- theLocaleResolver
to be used- Returns:
this
following the chaining method pattern
-
addValueExtractor
- Specified by:
addValueExtractor
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
addMapping
- Specified by:
addMapping
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
failFast
Description copied from interface:BaseHibernateValidatorConfiguration
En- or disables the fail fast mode. When fail fast is enabled the validation will stop on the first constraint violation detected.- Specified by:
failFast
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
failFast
-true
to enable fail fast,false
otherwise.- Returns:
this
following the chaining method pattern
-
allowOverridingMethodAlterParameterConstraint
Description copied from interface:BaseHibernateValidatorConfiguration
Define whether overriding methods that override constraints should throw aConstraintDefinitionException
. The default value isfalse
, i.e. do not allow.See Section 4.5.5 of the JSR 380 specification, specifically
"In sub types (be it sub classes/interfaces or interface implementations), no parameter constraints may be declared on overridden or implemented methods, nor may parameters be marked for cascaded validation. This would pose a strengthening of preconditions to be fulfilled by the caller."
- Specified by:
allowOverridingMethodAlterParameterConstraint
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
allow
- flag determining whether validation will allow overriding to alter parameter constraints.- Returns:
this
following the chaining method pattern
-
isAllowOverridingMethodAlterParameterConstraint
public boolean isAllowOverridingMethodAlterParameterConstraint() -
allowMultipleCascadedValidationOnReturnValues
Description copied from interface:BaseHibernateValidatorConfiguration
Define whether more than one constraint on a return value may be marked for cascading validation are allowed. The default value isfalse
, i.e. do not allow.See Section 4.5.5 of the JSR 380 specification, specifically
"One must not mark a method return value for cascaded validation more than once in a line of a class hierarchy. In other words, overriding methods on sub types (be it sub classes/interfaces or interface implementations) cannot mark the return value for cascaded validation if the return value has already been marked on the overridden method of the super type or interface."
- Specified by:
allowMultipleCascadedValidationOnReturnValues
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
allow
- flag determining whether validation will allow multiple cascaded validation on return values.- Returns:
this
following the chaining method pattern
-
isAllowMultipleCascadedValidationOnReturnValues
public boolean isAllowMultipleCascadedValidationOnReturnValues() -
allowParallelMethodsDefineParameterConstraints
Description copied from interface:BaseHibernateValidatorConfiguration
Define whether parallel methods that define constraints should throw aConstraintDefinitionException
. The default value isfalse
, i.e. do not allow.See Section 4.5.5 of the JSR 380 specification, specifically
"If a sub type overrides/implements a method originally defined in several parallel types of the hierarchy (e.g. two interfaces not extending each other, or a class and an interface not implemented by said class), no parameter constraints may be declared for that method at all nor parameters be marked for cascaded validation. This again is to avoid an unexpected strengthening of preconditions to be fulfilled by the caller."
- Specified by:
allowParallelMethodsDefineParameterConstraints
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
allow
- flag determining whether validation will allow parameter constraints in parallel hierarchies- Returns:
this
following the chaining method pattern
-
scriptEvaluatorFactory
Description copied from interface:BaseHibernateValidatorConfiguration
Allows to specify a customScriptEvaluatorFactory
responsible for creatingScriptEvaluator
s used to evaluate script expressions forScriptAssert
andParameterScriptAssert
constraints.- Specified by:
scriptEvaluatorFactory
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
scriptEvaluatorFactory
- theScriptEvaluatorFactory
to be used- Returns:
this
following the chaining method pattern
-
temporalValidationTolerance
Description copied from interface:BaseHibernateValidatorConfiguration
Allows to set the acceptable margin of error when comparing date/time in temporal constraints such asPast
/PastOrPresent
andFuture
/FutureOrPresent
.- Specified by:
temporalValidationTolerance
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
temporalValidationTolerance
- the acceptable tolerance- Returns:
this
following the chaining method pattern
-
constraintValidatorPayload
Description copied from interface:BaseHibernateValidatorConfiguration
Allows to set a payload which will be passed to the constraint validators. If the method is called multiple times, only the payload passed last will be propagated.- Specified by:
constraintValidatorPayload
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
constraintValidatorPayload
- the payload passed to constraint validators- Returns:
this
following the chaining method pattern
-
getterPropertySelectionStrategy
public T getterPropertySelectionStrategy(GetterPropertySelectionStrategy getterPropertySelectionStrategy) Description copied from interface:BaseHibernateValidatorConfiguration
Allows to set a getter property selection strategy defining the rules determining if a method is a getter or not.- Specified by:
getterPropertySelectionStrategy
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
getterPropertySelectionStrategy
- theGetterPropertySelectionStrategy
to be used- Returns:
this
following the chaining method pattern
-
locales
Description copied from interface:BaseHibernateValidatorConfiguration
Allows setting the list of the locales supported by this ValidatorFactory.Can be used for advanced locale resolution and/or to force the initialization of the resource bundles at bootstrap.
If not set, defaults to a singleton containing
Locale.getDefault()
.- Specified by:
locales
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
defaultLocale
Description copied from interface:BaseHibernateValidatorConfiguration
Allows setting the default locale used to interpolate the constraint violation messages.If not set, defaults to the system locale obtained via
Locale.getDefault()
.- Specified by:
defaultLocale
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
isAllowParallelMethodsDefineParameterConstraints
public boolean isAllowParallelMethodsDefineParameterConstraints() -
getMethodValidationConfiguration
-
createConstraintMapping
Description copied from interface:BaseHibernateValidatorConfiguration
Creates a new constraint mapping which can be used to programmatically configure the constraints for given types. After the mapping has been set up, it must be added to this configuration viaBaseHibernateValidatorConfiguration.addMapping(ConstraintMapping)
.- Specified by:
createConstraintMapping
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Returns:
- A new constraint mapping.
-
addMapping
Description copied from interface:BaseHibernateValidatorConfiguration
Adds the specifiedConstraintMapping
instance to the configuration. Constraints configured inmapping
will be added to the constraints configured via annotations and/or xml.- Specified by:
addMapping
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
mapping
-ConstraintMapping
instance containing programmatic configured constraints- Returns:
this
following the chaining method pattern
-
addProperty
- Specified by:
addProperty
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
externalClassLoader
Description copied from interface:BaseHibernateValidatorConfiguration
Sets the class loader to be used for loading user-provided resources:- XML descriptors (
META-INF/validation.xml
as well as XML constraint mappings) - classes specified by name in XML descriptors (e.g. custom message interpolators etc.)
- the
ValidationMessages
resource bundle
- Specified by:
externalClassLoader
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
externalClassLoader
- The class loader for loading user-provided resources.- Returns:
this
following the chaining method pattern
- XML descriptors (
-
buildValidatorFactory
- Specified by:
buildValidatorFactory
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
isIgnoreXmlConfiguration
public final boolean isIgnoreXmlConfiguration()- Specified by:
isIgnoreXmlConfiguration
in interfaceConfigurationState
-
getMessageInterpolator
- Specified by:
getMessageInterpolator
in interfaceConfigurationState
-
getMappingStreams
- Specified by:
getMappingStreams
in interfaceConfigurationState
-
getFailFast
public final boolean getFailFast() -
getConstraintValidatorFactory
- Specified by:
getConstraintValidatorFactory
in interfaceConfigurationState
-
getTraversableResolver
- Specified by:
getTraversableResolver
in interfaceConfigurationState
-
getBootstrapConfiguration
- Specified by:
getBootstrapConfiguration
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
getParameterNameProvider
- Specified by:
getParameterNameProvider
in interfaceConfigurationState
-
getClockProvider
- Specified by:
getClockProvider
in interfaceConfigurationState
-
getPropertyNodeNameProvider
-
getLocaleResolver
-
getScriptEvaluatorFactory
-
getTemporalValidationTolerance
-
getConstraintValidatorPayload
-
getGetterPropertySelectionStrategy
-
getValueExtractors
- Specified by:
getValueExtractors
in interfaceConfigurationState
-
getProperties
- Specified by:
getProperties
in interfaceConfigurationState
-
getExternalClassLoader
-
getDefaultMessageInterpolator
- Specified by:
getDefaultMessageInterpolator
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
getDefaultTraversableResolver
- Specified by:
getDefaultTraversableResolver
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
getDefaultConstraintValidatorFactory
- Specified by:
getDefaultConstraintValidatorFactory
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
getDefaultResourceBundleLocator
Description copied from interface:BaseHibernateValidatorConfiguration
Returns the
ResourceBundleLocator
used by thedefault message interpolator
to load user-provided resource bundles. In conformance with the specification this default locator retrieves the bundle "ValidationMessages".This locator can be used as delegate for custom locators when setting a customized
ResourceBundleMessageInterpolator
:HibernateValidatorConfiguration configure = Validation.byProvider(HibernateValidator.class).configure(); ResourceBundleLocator defaultResourceBundleLocator = configure.getDefaultBundleLocator(); ResourceBundleLocator myResourceBundleLocator = new MyResourceBundleLocator(defaultResourceBundleLocator); configure.messageInterpolator( new ResourceBundleMessageInterpolator(myResourceBundleLocator));
- Specified by:
getDefaultResourceBundleLocator
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Returns:
- The default
ResourceBundleLocator
. Never null.
-
getDefaultParameterNameProvider
- Specified by:
getDefaultParameterNameProvider
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
getDefaultClockProvider
- Specified by:
getDefaultClockProvider
in interfaceConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
getDefaultValueExtractors
Description copied from interface:BaseHibernateValidatorConfiguration
Returns the defaultValueExtractor
implementations as per the specification.- Specified by:
getDefaultValueExtractors
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Returns:
- the default
ValueExtractor
implementations compliant with the specification
-
beanMetaDataClassNormalizer
- Specified by:
beanMetaDataClassNormalizer
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
-
getBeanMetaDataClassNormalizer
-
constraintExpressionLanguageFeatureLevel
public T constraintExpressionLanguageFeatureLevel(ExpressionLanguageFeatureLevel expressionLanguageFeatureLevel) Description copied from interface:BaseHibernateValidatorConfiguration
Allows setting the Expression Language feature level for message interpolation of constraint messages.This is the feature level used for messages hardcoded inside the constraint declaration.
If you are creating custom constraint violations, Expression Language support needs to be explicitly enabled and use the safest feature level by default if enabled.
- Specified by:
constraintExpressionLanguageFeatureLevel
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
expressionLanguageFeatureLevel
- theExpressionLanguageFeatureLevel
to be used- Returns:
this
following the chaining method pattern
-
getConstraintExpressionLanguageFeatureLevel
-
customViolationExpressionLanguageFeatureLevel
public T customViolationExpressionLanguageFeatureLevel(ExpressionLanguageFeatureLevel expressionLanguageFeatureLevel) Description copied from interface:BaseHibernateValidatorConfiguration
Allows setting the Expression Language feature level for message interpolation of custom violation messages.This is the feature level used for messages of custom violations created by the
ConstraintValidatorContext
.- Specified by:
customViolationExpressionLanguageFeatureLevel
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
expressionLanguageFeatureLevel
- theExpressionLanguageFeatureLevel
to be used- Returns:
this
following the chaining method pattern
-
getCustomViolationExpressionLanguageFeatureLevel
-
showValidatedValuesInTraceLogs
Description copied from interface:BaseHibernateValidatorConfiguration
Allows setting the logging configuration that would include validated values in trace level logs.By default, values will not be printed to the logs as they might contain sensitive data.
- Specified by:
showValidatedValuesInTraceLogs
in interfaceBaseHibernateValidatorConfiguration<T extends BaseHibernateValidatorConfiguration<T>>
- Parameters:
enabled
- flag determining whether validated values will be printed out into trace level logs or not.- Returns:
this
following the chaining method pattern
-
getShowValidatedValuesInTraceLogs
public final boolean getShowValidatedValuesInTraceLogs() -
getProgrammaticMappings
-
preloadResourceBundles
protected abstract boolean preloadResourceBundles() -
thisAsT
-