T
- the type of a provider-specific specialization of this contractpublic interface Configuration<T extends Configuration<T>>
ValidatorFactory
.
Usage:
//provided by one of the Validation bootstrap methods Configuration<?> configuration = ValidatorFactory = configuration .messageInterpolator( new CustomMessageInterpolator() ) .buildValidatorFactory();
By default, the configuration information is retrieved from
META-INF/validation.xml
.
It is possible to override the configuration retrieved from the XML file
by using one or more of the Configuration
methods.
The ValidationProviderResolver
is specified at configuration time
(see ValidationProvider
).
If none is explicitly requested, the default ValidationProviderResolver
is used.
The provider is selected in the following way:
Validation.byProvider(Class)
, find the first provider implementing
the provider class requested and use itMETA-INF/validation.xml
,
find the first provider implementing the provider class requested and use itValidationProviderResolver
Implementations are not meant to be thread-safe.
Modifier and Type | Method and Description |
---|---|
T |
addMapping(InputStream stream)
Add a stream describing constraint mapping in the Jakarta Bean Validation XML
format.
|
T |
addProperty(String name,
String value)
Adds a provider specific property.
|
T |
addValueExtractor(ValueExtractor<?> extractor)
Adds a value extractor.
|
ValidatorFactory |
buildValidatorFactory()
Build a
ValidatorFactory implementation. |
T |
clockProvider(ClockProvider clockProvider)
Defines the clock provider.
|
T |
constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
Defines the constraint validator factory.
|
BootstrapConfiguration |
getBootstrapConfiguration()
Returns configuration information stored in the
META-INF/validation.xml file. |
ClockProvider |
getDefaultClockProvider()
Returns an implementation of the
ClockProvider
interface following the default ClockProvider
defined in the specification:
returns a clock representing the current system time and default time
zone.
|
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. |
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.
|
T |
ignoreXmlConfiguration()
Ignores data from the
META-INF/validation.xml file if this
method is called. |
T |
messageInterpolator(MessageInterpolator interpolator)
Defines the message interpolator used.
|
T |
parameterNameProvider(ParameterNameProvider parameterNameProvider)
Defines the parameter name provider.
|
T |
traversableResolver(TraversableResolver resolver)
Defines the traversable resolver used.
|
T ignoreXmlConfiguration()
META-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.
this
following the chaining method pattern.T messageInterpolator(MessageInterpolator interpolator)
If null
is passed, the default message interpolator is used
(defined in XML or the specification default).
interpolator
- message interpolator implementationthis
following the chaining method patternT traversableResolver(TraversableResolver resolver)
If null
is passed, the default traversable resolver is used
(defined in XML or the specification default).
resolver
- traversable resolver implementationthis
following the chaining method patternT constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
If null
is passed, the default constraint validator factory is used
(defined in XML or the specification default).
constraintValidatorFactory
- constraint factory implementationthis
following the chaining method patternT parameterNameProvider(ParameterNameProvider parameterNameProvider)
If null
is passed, the default parameter name provider is used
(defined in XML or the specification default).
parameterNameProvider
- parameter name provider implementationthis
following the chaining method pattern.T clockProvider(ClockProvider clockProvider)
If null
is passed, the default clock provider is used
(defined in XML or the specification default).
clockProvider
- clock provider implementationthis
following the chaining method pattern.T addValueExtractor(ValueExtractor<?> extractor)
extractor
- value extractor implementationthis
following the chaining method pattern.ValueExtractorDeclarationException
- if more than one extractor for
the same type and type parameter is addedT addMapping(InputStream stream)
The stream should be closed by the client API after the
ValidatorFactory
has been built. The Jakarta Bean Validation provider
must not close the stream.
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 Jakarta Bean Validation providerthis
following the chaining method patternIllegalArgumentException
- if stream
is nullT addProperty(String name, String value)
Note: 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.
name
- property namevalue
- property valuethis
following the chaining method patternIllegalArgumentException
- if name
is nullMessageInterpolator getDefaultMessageInterpolator()
MessageInterpolator
interface
following the default MessageInterpolator
defined in the
specification:
ValidationMessages
resource bundle to load keysLocale.getDefault()
MessageInterpolator
implementation compliant with the
specificationTraversableResolver getDefaultTraversableResolver()
TraversableResolver
interface
following the default TraversableResolver
defined in the
specification:
TraversableResolver
implementation compliant with the
specificationConstraintValidatorFactory getDefaultConstraintValidatorFactory()
ConstraintValidatorFactory
interface
following the default ConstraintValidatorFactory
defined in the
specification:
ConstraintValidator
ConstraintValidatorFactory
implementation compliant with the
specificationParameterNameProvider getDefaultParameterNameProvider()
ParameterNameProvider
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.ParameterNameProvider
implementation compliant with
the specificationClockProvider getDefaultClockProvider()
ClockProvider
interface following the default ClockProvider
defined in the specification:
ClockProvider
implementation compliant with
the specificationBootstrapConfiguration getBootstrapConfiguration()
META-INF/validation.xml
file.
Note:
Implementations are encouraged to lazily build this object to delay parsing.
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 mapValidatorFactory buildValidatorFactory()
ValidatorFactory
implementation.ValidatorFactory
ValidationException
- if the ValidatorFactory
cannot be builtCopyright © 2018,2020 Eclipse Foundation.
Use is subject to license terms.