public class ConfigurationImpl extends Object implements HibernateValidatorConfiguration, ConfigurationState
Configuration implementation.ALLOW_MULTIPLE_CASCADED_VALIDATION_ON_RESULT, ALLOW_PARALLEL_METHODS_DEFINE_PARAMETER_CONSTRAINTS, ALLOW_PARAMETER_CONSTRAINT_OVERRIDE, CONSTRAINT_MAPPING_CONTRIBUTOR, CONSTRAINT_MAPPING_CONTRIBUTORS, FAIL_FAST, TIME_PROVIDER, VALIDATED_VALUE_HANDLERS| Constructor and Description |
|---|
ConfigurationImpl(BootstrapState state) |
ConfigurationImpl(ValidationProvider<?> provider) |
| Modifier and Type | Method and Description |
|---|---|
HibernateValidatorConfiguration |
addMapping(ConstraintMapping mapping)
Adds the specified
ConstraintMapping instance to the configuration. |
HibernateValidatorConfiguration |
addMapping(InputStream stream)
Add a stream describing constraint mapping in the Bean Validation XML
format.
|
HibernateValidatorConfiguration |
addProperty(String name,
String value)
Adds a provider specific property.
|
HibernateValidatorConfiguration |
addValidatedValueHandler(ValidatedValueUnwrapper<?> handler)
Registers the given validated value unwrapper with the bootstrapped validator factory.
|
HibernateValidatorConfiguration |
allowMultipleCascadedValidationOnReturnValues(boolean allow)
Define whether more than one constraint on a return value may be marked for cascading validation are allowed.
|
HibernateValidatorConfiguration |
allowOverridingMethodAlterParameterConstraint(boolean allow)
Define whether overriding methods that override constraints should throw a
ConstraintDefinitionException. |
HibernateValidatorConfiguration |
allowParallelMethodsDefineParameterConstraints(boolean allow)
Define whether parallel methods that define constraints should throw a
ConstraintDefinitionException. |
ValidatorFactory |
buildValidatorFactory()
Build a
ValidatorFactory implementation. |
ConfigurationImpl |
constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
Defines the constraint validator factory.
|
DefaultConstraintMapping |
createConstraintMapping()
Creates a new constraint mapping which can be used to programmatically configure the constraints for given types.
|
HibernateValidatorConfiguration |
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. |
HibernateValidatorConfiguration |
failFast(boolean failFast)
En- or disables the fail fast mode.
|
BootstrapConfiguration |
getBootstrapConfiguration()
Returns configuration information stored in the
META-INF/validation.xml file. |
ConstraintValidatorFactory |
getConstraintValidatorFactory()
Returns the constraint validator factory of this configuration.
|
ConstraintValidatorFactory |
getDefaultConstraintValidatorFactory()
Returns an implementation of the
ConstraintValidatorFactory interface
following the default ConstraintValidatorFactory defined in the
specification:
uses the public no-arg constructor of the ConstraintValidator
|
MessageInterpolator |
getDefaultMessageInterpolator()
Returns an implementation of the
MessageInterpolator interface
following the default MessageInterpolator defined in the
specification:
use the ValidationMessages resource bundle to load keys
use Locale.getDefault()
|
ParameterNameProvider |
getDefaultParameterNameProvider()
Returns an implementation of the
ParameterNameProvider
interface following the default ParameterNameProvider
defined in the specification:
returns the actual parameter names as provided in the validated
executable’s definition, if the class file of the executable contains
parameter name information
otherwise returns names in the form arg<PARAMETER_INDEX>,
where PARAMETER_INDEX starts at 0 for the first parameter,
e.g. |
ResourceBundleLocator |
getDefaultResourceBundleLocator()
Returns the
ResourceBundleLocator used by the
default message
interpolator to load user-provided resource bundles. |
TraversableResolver |
getDefaultTraversableResolver()
Returns an implementation of the
TraversableResolver interface
following the default TraversableResolver defined in the
specification:
if Java Persistence is available in the runtime environment,
a property is considered reachable if Java Persistence considers
the property as loaded
if Java Persistence is not available in the runtime environment,
all properties are considered reachable
all properties are considered cascadable.
|
ClassLoader |
getExternalClassLoader() |
boolean |
getFailFast() |
Set<InputStream> |
getMappingStreams()
Returns a set of configuration streams.
|
MessageInterpolator |
getMessageInterpolator()
Returns the message interpolator of this configuration.
|
MethodValidationConfiguration |
getMethodValidationConfiguration() |
ParameterNameProvider |
getParameterNameProvider()
Returns the parameter name provider for this configuration.
|
Set<DefaultConstraintMapping> |
getProgrammaticMappings() |
Map<String,String> |
getProperties()
Returns a map of non type-safe custom properties.
|
ConstraintMappingContributor |
getServiceLoaderBasedConstraintMappingContributor() |
TimeProvider |
getTimeProvider() |
TraversableResolver |
getTraversableResolver()
Returns the traversable resolver for this configuration.
|
List<ValidatedValueUnwrapper<?>> |
getValidatedValueHandlers() |
HibernateValidatorConfiguration |
ignoreXmlConfiguration()
Ignores data from the
META-INF/validation.xml file if this
method is called. |
boolean |
isAllowMultipleCascadedValidationOnReturnValues() |
boolean |
isAllowOverridingMethodAlterParameterConstraint() |
boolean |
isAllowParallelMethodsDefineParameterConstraints() |
boolean |
isIgnoreXmlConfiguration()
Returns
true if Configuration.ignoreXmlConfiguration() has been
called. |
ConfigurationImpl |
messageInterpolator(MessageInterpolator interpolator)
Defines the message interpolator used.
|
HibernateValidatorConfiguration |
parameterNameProvider(ParameterNameProvider parameterNameProvider)
Defines the parameter name provider.
|
HibernateValidatorConfiguration |
timeProvider(TimeProvider timeProvider)
Registers the given time provider with the bootstrapped validator factory.
|
ConfigurationImpl |
traversableResolver(TraversableResolver resolver)
Defines the traversable resolver used.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitaddValueExtractor, clockProvider, getDefaultClockProvidergetClockProvider, getValueExtractorspublic ConfigurationImpl(BootstrapState state)
public ConfigurationImpl(ValidationProvider<?> provider)
public final HibernateValidatorConfiguration ignoreXmlConfiguration()
ConfigurationMETA-INF/validation.xml file if this
method is called.
This method is typically useful for containers that parse
META-INF/validation.xml themselves and pass the information
via the Configuration methods.
ignoreXmlConfiguration in interface Configuration<HibernateValidatorConfiguration>this following the chaining method pattern.public final ConfigurationImpl messageInterpolator(MessageInterpolator interpolator)
Configuration
If null is passed, the default message interpolator is used
(defined in XML or the specification default).
messageInterpolator in interface Configuration<HibernateValidatorConfiguration>interpolator - message interpolator implementationthis following the chaining method patternpublic final ConfigurationImpl traversableResolver(TraversableResolver resolver)
Configuration
If null is passed, the default traversable resolver is used
(defined in XML or the specification default).
traversableResolver in interface Configuration<HibernateValidatorConfiguration>resolver - traversable resolver implementationthis following the chaining method patternpublic final ConfigurationImpl constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
Configuration
If null is passed, the default constraint validator factory is used
(defined in XML or the specification default).
constraintValidatorFactory in interface Configuration<HibernateValidatorConfiguration>constraintValidatorFactory - constraint factory implementationthis following the chaining method patternpublic HibernateValidatorConfiguration parameterNameProvider(ParameterNameProvider parameterNameProvider)
Configuration
If null is passed, the default parameter name provider is used
(defined in XML or the specification default).
parameterNameProvider in interface Configuration<HibernateValidatorConfiguration>parameterNameProvider - parameter name provider implementationthis following the chaining method pattern.public final HibernateValidatorConfiguration addMapping(InputStream stream)
Configuration
The stream should be closed by the client API after the
ValidatorFactory has been built. The Bean Validation provider
must not close the stream.
addMapping in interface Configuration<HibernateValidatorConfiguration>stream - XML mapping stream; the given stream should support the
mark/reset contract (see InputStream.markSupported());
if it doesn't, it will be wrapped into a stream supporting the
mark/reset contract by the Bean Validation providerthis following the chaining method patternpublic final HibernateValidatorConfiguration failFast(boolean failFast)
HibernateValidatorConfigurationfailFast in interface HibernateValidatorConfigurationfailFast - true to enable fail fast, false otherwise.this following the chaining method patternpublic HibernateValidatorConfiguration allowOverridingMethodAlterParameterConstraint(boolean allow)
HibernateValidatorConfigurationConstraintDefinitionException.
The default value is false, i.e. do not allow.
See Section 4.5.5 of the JSR 349 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."
allowOverridingMethodAlterParameterConstraint in interface HibernateValidatorConfigurationallow - flag determining whether validation will allow overriding to alter parameter constraints.this following the chaining method patternpublic boolean isAllowOverridingMethodAlterParameterConstraint()
public HibernateValidatorConfiguration allowMultipleCascadedValidationOnReturnValues(boolean allow)
HibernateValidatorConfigurationfalse, i.e. do not allow.
See Section 4.5.5 of the JSR 349 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."
allowMultipleCascadedValidationOnReturnValues in interface HibernateValidatorConfigurationallow - flag determining whether validation will allow multiple cascaded validation on return values.this following the chaining method patternpublic boolean isAllowMultipleCascadedValidationOnReturnValues()
public HibernateValidatorConfiguration allowParallelMethodsDefineParameterConstraints(boolean allow)
HibernateValidatorConfigurationConstraintDefinitionException. The
default value is false, i.e. do not allow.
See Section 4.5.5 of the JSR 349 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."
allowParallelMethodsDefineParameterConstraints in interface HibernateValidatorConfigurationallow - flag determining whether validation will allow parameter constraints in parallel hierarchiesthis following the chaining method patternpublic boolean isAllowParallelMethodsDefineParameterConstraints()
public MethodValidationConfiguration getMethodValidationConfiguration()
public final DefaultConstraintMapping createConstraintMapping()
HibernateValidatorConfigurationHibernateValidatorConfiguration.addMapping(ConstraintMapping).createConstraintMapping in interface HibernateValidatorConfigurationpublic final HibernateValidatorConfiguration addMapping(ConstraintMapping mapping)
HibernateValidatorConfigurationConstraintMapping instance to the configuration. Constraints configured in mapping
will be added to the constraints configured via annotations and/or xml.addMapping in interface HibernateValidatorConfigurationmapping - ConstraintMapping instance containing programmatic configured constraintsthis following the chaining method patternpublic final HibernateValidatorConfiguration addProperty(String name, String value)
ConfigurationNote: Using this non type-safe method is generally not recommended.
It is more appropriate to use, if available, the type-safe equivalent provided
by a specific provider via its Configuration subclass.
ValidatorFactory factory = Validation.byProvider(ACMEProvider.class)
.configure()
.providerSpecificProperty(ACMEState.FAST)
.buildValidatorFactory();
This method is typically used by containers parsing META-INF/validation.xml
themselves and injecting the state to the Configuration object.
If a property with a given name is defined both via this method and in the XML configuration, the value set programmatically has priority.
If null is passed as a value, the value defined in XML is used. If no value
is defined in XML, the property is considered unset.
addProperty in interface Configuration<HibernateValidatorConfiguration>name - property namevalue - property valuethis following the chaining method patternpublic HibernateValidatorConfiguration addValidatedValueHandler(ValidatedValueUnwrapper<?> handler)
HibernateValidatorConfigurationUnwrapValidatedValue, the unwrapper will be applied to retrieve the
value to validate.addValidatedValueHandler in interface HibernateValidatorConfigurationhandler - the unwrapper to registerthis following the chaining method patternpublic final ConstraintMappingContributor getServiceLoaderBasedConstraintMappingContributor()
public HibernateValidatorConfiguration externalClassLoader(ClassLoader externalClassLoader)
HibernateValidatorConfigurationMETA-INF/validation.xml as well as XML constraint mappings)ValidationMessages resource bundleexternalClassLoader in interface HibernateValidatorConfigurationexternalClassLoader - The class loader for loading user-provided resources.this following the chaining method patternpublic HibernateValidatorConfiguration timeProvider(TimeProvider timeProvider)
HibernateValidatorConfiguration@Future and @Past constraints. By default the current system
time and the current default time zone will be used when validating these constraints.timeProvider in interface HibernateValidatorConfigurationtimeProvider - the time provider to register. Must not be nullthis following the chaining method patternpublic final ValidatorFactory buildValidatorFactory()
ConfigurationValidatorFactory implementation.buildValidatorFactory in interface Configuration<HibernateValidatorConfiguration>ValidatorFactorypublic final boolean isIgnoreXmlConfiguration()
ConfigurationStatetrue if Configuration.ignoreXmlConfiguration() has been
called.
In this case, the ValidatorFactory must ignore
META-INF/validation.xml.
isIgnoreXmlConfiguration in interface ConfigurationStatetrue if META-INF/validation.xml should be ignoredpublic final MessageInterpolator getMessageInterpolator()
ConfigurationStateMessage interpolator is defined in the following decreasing priority:
Configuration programmatic APIMETA-INF/validation.xml provided that
ignoreXmlConfiguration is false. In this case the instance
is created via its no-arg constructor.null if undefined.getMessageInterpolator in interface ConfigurationStatenull if not definedpublic final Set<InputStream> getMappingStreams()
ConfigurationStateThe streams are defined by:
ConfigurationMETA-INF/validation.xml (constraint-mapping element)
Streams represented in the XML configuration and opened by the
Configuration implementation must be closed by the
Configuration implementation after the ValidatorFactory
creation (or if an exception occurs). All streams are guaranteed to
adhere to the mark/reset contract (see InputStream.markSupported()
by the Bean Validation provider.
getMappingStreams in interface ConfigurationStatepublic final boolean getFailFast()
public final ConstraintValidatorFactory getConstraintValidatorFactory()
ConfigurationState
The ConstraintValidatorFactory implementation is defined in the following
decreasing priority:
Configuration programmatic APIMETA-INF/validation.xml provided that
ignoredXmlConfiguration is false. In this case the instance
is created via its no-arg constructor.null if undefined.getConstraintValidatorFactory in interface ConfigurationStatenull if not definedpublic final TraversableResolver getTraversableResolver()
ConfigurationState
TraversableResolver is defined in the following decreasing priority:
Configuration programmatic APIMETA-INF/validation.xml provided that
ignoredXmlConfiguration is false. In this case the
instance is created via its no-arg constructor.null if undefined.getTraversableResolver in interface ConfigurationStatenull if not definedpublic BootstrapConfiguration getBootstrapConfiguration()
ConfigurationMETA-INF/validation.xml file.
Note:
Implementations are encouraged to lazily build this object to delay parsing.
getBootstrapConfiguration in interface Configuration<HibernateValidatorConfiguration>BootstrapConfiguration; this method never
returns null; if there is no META-INF/validation.xml the
different getters of the returned instance will return null
respectively an empty set or mappublic ParameterNameProvider getParameterNameProvider()
ConfigurationState
ParameterNameProvider is defined in the following decreasing priority:
Configuration programmatic APIMETA-INF/validation.xml provided that
ignoreXmlConfiguration is false. In this case the instance
is created via its no-arg constructor.null if undefined.getParameterNameProvider in interface ConfigurationStatenull if not definedpublic List<ValidatedValueUnwrapper<?>> getValidatedValueHandlers()
public TimeProvider getTimeProvider()
public final Map<String,String> getProperties()
ConfigurationStateProperties defined via:
Configuration.addProperty(String, String)META-INF/validation.xml provided that
ignoreXmlConfiguration is false.If a property is defined both programmatically and in XML, the value defined programmatically has priority.
getProperties in interface ConfigurationStateMap whose key is the property key and the value
the property valuepublic ClassLoader getExternalClassLoader()
public final MessageInterpolator getDefaultMessageInterpolator()
ConfigurationMessageInterpolator interface
following the default MessageInterpolator defined in the
specification:
ValidationMessages resource bundle to load keysLocale.getDefault()getDefaultMessageInterpolator in interface Configuration<HibernateValidatorConfiguration>MessageInterpolator implementation compliant with the
specificationpublic final TraversableResolver getDefaultTraversableResolver()
ConfigurationTraversableResolver interface
following the default TraversableResolver defined in the
specification:
getDefaultTraversableResolver in interface Configuration<HibernateValidatorConfiguration>TraversableResolver implementation compliant with the
specificationpublic final ConstraintValidatorFactory getDefaultConstraintValidatorFactory()
ConfigurationConstraintValidatorFactory interface
following the default ConstraintValidatorFactory defined in the
specification:
ConstraintValidatorgetDefaultConstraintValidatorFactory in interface Configuration<HibernateValidatorConfiguration>ConstraintValidatorFactory implementation compliant with the
specificationpublic final ResourceBundleLocator getDefaultResourceBundleLocator()
HibernateValidatorConfiguration
Returns the ResourceBundleLocator used by the
default 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));
getDefaultResourceBundleLocator in interface HibernateValidatorConfigurationResourceBundleLocator. Never null.public ParameterNameProvider getDefaultParameterNameProvider()
ConfigurationParameterNameProvider
interface following the default ParameterNameProvider
defined in the specification:
arg<PARAMETER_INDEX>,
where PARAMETER_INDEX starts at 0 for the first parameter,
e.g. arg0, arg1 etc.getDefaultParameterNameProvider in interface Configuration<HibernateValidatorConfiguration>ParameterNameProvider implementation compliant with
the specificationpublic final Set<DefaultConstraintMapping> getProgrammaticMappings()
Copyright © 2018 JBoss by Red Hat. All rights reserved.