Interface Configuration<T extends Configuration<T>>
-
- Type Parameters:
T- the type of a provider-specific specialization of this contract
public interface Configuration<T extends Configuration<T>>Receives configuration information, selects the appropriate Jakarta Bean Validation provider and builds the appropriateValidatorFactory.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 theConfigurationmethods.The
ValidationProviderResolveris specified at configuration time (seeValidationProvider). If none is explicitly requested, the defaultValidationProviderResolveris used.The provider is selected in the following way:
- if a specific provider is requested programmatically using
Validation.byProvider(Class), find the first provider implementing the provider class requested and use it - if a specific provider is requested in
META-INF/validation.xml, find the first provider implementing the provider class requested and use it - otherwise, use the first provider returned by the
ValidationProviderResolver
Implementations are not meant to be thread-safe.
- Author:
- Emmanuel Bernard, Gunnar Morling, Hardy Ferentschik, Guillaume Smet
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description TaddMapping(InputStream stream)Add a stream describing constraint mapping in the Jakarta Bean Validation XML format.TaddProperty(String name, String value)Adds a provider specific property.TaddValueExtractor(ValueExtractor<?> extractor)Adds a value extractor.ValidatorFactorybuildValidatorFactory()Build aValidatorFactoryimplementation.TclockProvider(ClockProvider clockProvider)Defines the clock provider.TconstraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)Defines the constraint validator factory.BootstrapConfigurationgetBootstrapConfiguration()Returns configuration information stored in theMETA-INF/validation.xmlfile.ClockProvidergetDefaultClockProvider()Returns an implementation of theClockProviderinterface following the defaultClockProviderdefined in the specification: returns a clock representing the current system time and default time zone.ConstraintValidatorFactorygetDefaultConstraintValidatorFactory()Returns an implementation of theConstraintValidatorFactoryinterface following the defaultConstraintValidatorFactorydefined in the specification: uses the public no-arg constructor of theConstraintValidatorMessageInterpolatorgetDefaultMessageInterpolator()Returns an implementation of theMessageInterpolatorinterface following the defaultMessageInterpolatordefined in the specification: use theValidationMessagesresource bundle to load keys useLocale.getDefault()ParameterNameProvidergetDefaultParameterNameProvider()Returns an implementation of theParameterNameProviderinterface following the defaultParameterNameProviderdefined 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 formarg<PARAMETER_INDEX>, wherePARAMETER_INDEXstarts at 0 for the first parameter, e.g.TraversableResolvergetDefaultTraversableResolver()Returns an implementation of theTraversableResolverinterface following the defaultTraversableResolverdefined 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.TignoreXmlConfiguration()Ignores data from theMETA-INF/validation.xmlfile if this method is called.TmessageInterpolator(MessageInterpolator interpolator)Defines the message interpolator used.TparameterNameProvider(ParameterNameProvider parameterNameProvider)Defines the parameter name provider.TtraversableResolver(TraversableResolver resolver)Defines the traversable resolver used.
-
-
-
Method Detail
-
ignoreXmlConfiguration
T ignoreXmlConfiguration()
Ignores data from theMETA-INF/validation.xmlfile if this method is called.This method is typically useful for containers that parse
META-INF/validation.xmlthemselves and pass the information via theConfigurationmethods.- Returns:
thisfollowing the chaining method pattern.
-
messageInterpolator
T messageInterpolator(MessageInterpolator interpolator)
Defines the message interpolator used. Has priority over the configuration based message interpolator.If
nullis passed, the default message interpolator is used (defined in XML or the specification default).- Parameters:
interpolator- message interpolator implementation- Returns:
thisfollowing the chaining method pattern
-
traversableResolver
T traversableResolver(TraversableResolver resolver)
Defines the traversable resolver used. Has priority over the configuration based traversable resolver.If
nullis passed, the default traversable resolver is used (defined in XML or the specification default).- Parameters:
resolver- traversable resolver implementation- Returns:
thisfollowing the chaining method pattern
-
constraintValidatorFactory
T constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)
Defines the constraint validator factory. Has priority over the configuration based constraint factory.If
nullis passed, the default constraint validator factory is used (defined in XML or the specification default).- Parameters:
constraintValidatorFactory- constraint factory implementation- Returns:
thisfollowing the chaining method pattern
-
parameterNameProvider
T parameterNameProvider(ParameterNameProvider parameterNameProvider)
Defines the parameter name provider. Has priority over the configuration based provider.If
nullis passed, the default parameter name provider is used (defined in XML or the specification default).- Parameters:
parameterNameProvider- parameter name provider implementation- Returns:
thisfollowing the chaining method pattern.- Since:
- 1.1
-
clockProvider
T clockProvider(ClockProvider clockProvider)
Defines the clock provider. Has priority over the configuration based provider.If
nullis passed, the default clock provider is used (defined in XML or the specification default).- Parameters:
clockProvider- clock provider implementation- Returns:
thisfollowing the chaining method pattern.- Since:
- 2.0
-
addValueExtractor
T addValueExtractor(ValueExtractor<?> extractor)
Adds a value extractor. Has priority over any extractor for the same type and type parameter detected through the service loader or given in the XML configuration.- Parameters:
extractor- value extractor implementation- Returns:
thisfollowing the chaining method pattern.- Throws:
ValueExtractorDeclarationException- if more than one extractor for the same type and type parameter is added- Since:
- 2.0
-
addMapping
T addMapping(InputStream stream)
Add a stream describing constraint mapping in the Jakarta Bean Validation XML format.The stream should be closed by the client API after the
ValidatorFactoryhas been built. The Jakarta Bean Validation provider must not close the stream.- Parameters:
stream- XML mapping stream; the given stream should support the mark/reset contract (seeInputStream.markSupported()); if it doesn't, it will be wrapped into a stream supporting the mark/reset contract by the Jakarta Bean Validation provider- Returns:
thisfollowing the chaining method pattern- Throws:
IllegalArgumentException- ifstreamis null
-
addProperty
T addProperty(String name, String value)
Adds a provider specific property. This property is equivalent to XML configuration properties. If the underlying provider does not know how to handle the property, it must silently ignore it.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
Configurationsubclass.ValidatorFactory factory = Validation.byProvider(ACMEProvider.class) .configure() .providerSpecificProperty(ACMEState.FAST) .buildValidatorFactory();This method is typically used by containers parsingMETA-INF/validation.xmlthemselves and injecting the state to theConfigurationobject.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
nullis passed as a value, the value defined in XML is used. If no value is defined in XML, the property is considered unset.- Parameters:
name- property namevalue- property value- Returns:
thisfollowing the chaining method pattern- Throws:
IllegalArgumentException- ifnameis null
-
getDefaultMessageInterpolator
MessageInterpolator getDefaultMessageInterpolator()
Returns an implementation of theMessageInterpolatorinterface following the defaultMessageInterpolatordefined in the specification:- use the
ValidationMessagesresource bundle to load keys - use
Locale.getDefault()
- Returns:
- default
MessageInterpolatorimplementation compliant with the specification
- use the
-
getDefaultTraversableResolver
TraversableResolver getDefaultTraversableResolver()
Returns an implementation of theTraversableResolverinterface following the defaultTraversableResolverdefined 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.
- Returns:
- default
TraversableResolverimplementation compliant with the specification
-
getDefaultConstraintValidatorFactory
ConstraintValidatorFactory getDefaultConstraintValidatorFactory()
Returns an implementation of theConstraintValidatorFactoryinterface following the defaultConstraintValidatorFactorydefined in the specification:- uses the public no-arg constructor of the
ConstraintValidator
- Returns:
- default
ConstraintValidatorFactoryimplementation compliant with the specification
- uses the public no-arg constructor of the
-
getDefaultParameterNameProvider
ParameterNameProvider getDefaultParameterNameProvider()
Returns an implementation of theParameterNameProviderinterface following the defaultParameterNameProviderdefined 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>, wherePARAMETER_INDEXstarts at 0 for the first parameter, e.g.arg0,arg1etc.
- Returns:
- default
ParameterNameProviderimplementation compliant with the specification - Since:
- 1.1
-
getDefaultClockProvider
ClockProvider getDefaultClockProvider()
Returns an implementation of theClockProviderinterface following the defaultClockProviderdefined in the specification:- returns a clock representing the current system time and default time zone.
- Returns:
- default
ClockProviderimplementation compliant with the specification - Since:
- 2.0
-
getBootstrapConfiguration
BootstrapConfiguration getBootstrapConfiguration()
Returns configuration information stored in theMETA-INF/validation.xmlfile.Note:
Implementations are encouraged to lazily build this object to delay parsing.- Returns:
- returns an instance of
BootstrapConfiguration; this method never returnsnull; if there is noMETA-INF/validation.xmlthe different getters of the returned instance will returnnullrespectively an empty set or map - Since:
- 1.1
-
buildValidatorFactory
ValidatorFactory buildValidatorFactory()
Build aValidatorFactoryimplementation.- Returns:
- the
ValidatorFactory - Throws:
ValidationException- if theValidatorFactorycannot be built
-
-