Top Description Methods
javax.validation

public Interface Configuration<T extends javax.validation.Configuration<T>>

Type Parameters
<T>
the type of a provider-specific specialization of this contract
Imports
java.io.InputStream, javax.validation.spi.ValidationProvider, javax.validation.valueextraction.ValueExtractor, .ValueExtractorDeclarationException

Receives configuration information, selects the appropriate Bean Validation provider and builds the appropriate 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:

Implementations are not meant to be thread-safe.

Authors
Emmanuel Bernard, Gunnar Morling, Hardy Ferentschik, Guillaume Smet

Method Summary

Modifier and TypeMethod and Description
public T

Returns:

this following the chaining method pattern
addMapping
(InputStream
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 provider
stream
)

Add a stream describing constraint mapping in the Bean Validation XML format.

public T

Returns:

this following the chaining method pattern
addProperty
(String
property name
name
,
String
property value
value
)

Adds a provider specific property.

public T

Returns:

this following the chaining method pattern.
addValueExtractor
(ValueExtractor<?>
value extractor implementation
extractor
)

Adds a value extractor.

public ValidatorFactory

Returns:

the ValidatorFactory
buildValidatorFactory
()

Build a ValidatorFactory implementation.

public T

Returns:

this following the chaining method pattern.
clockProvider
(ClockProvider
clock provider implementation
clockProvider
)

Defines the clock provider.

public T

Returns:

this following the chaining method pattern
constraintValidatorFactory
(ConstraintValidatorFactory
constraint factory implementation
constraintValidatorFactory
)

Defines the constraint validator factory.

public BootstrapConfiguration

Returns:

returns an instance of 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 map
getBootstrapConfiguration
()

Returns configuration information stored in the META-INF/validation.xml file.

public ClockProvider

Returns:

default ClockProvider implementation compliant with the specification
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.
public ConstraintValidatorFactory

Returns:

default ConstraintValidatorFactory implementation compliant with the specification
getDefaultConstraintValidatorFactory
()

Returns an implementation of the ConstraintValidatorFactory interface following the default ConstraintValidatorFactory defined in the specification:

public MessageInterpolator

Returns:

default MessageInterpolator implementation compliant with the specification
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()
public ParameterNameProvider

Returns:

default ParameterNameProvider implementation compliant with the specification
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. arg0, arg1 etc.
public TraversableResolver

Returns:

default TraversableResolver implementation compliant with the specification
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.
public T

Returns:

this following the chaining method pattern.
ignoreXmlConfiguration
()

Ignores data from the META-INF/validation.xml file if this method is called.

public T

Returns:

this following the chaining method pattern
messageInterpolator
(MessageInterpolator
message interpolator implementation
interpolator
)

Defines the message interpolator used.

public T

Returns:

this following the chaining method pattern.
parameterNameProvider
(ParameterNameProvider
parameter name provider implementation
parameterNameProvider
)

Defines the parameter name provider.

public T

Returns:

this following the chaining method pattern
traversableResolver
(TraversableResolver
traversable resolver implementation
resolver
)

Defines the traversable resolver used.

Method Detail

addMappingback to summary
public T addMapping(InputStream stream)

Add a stream describing constraint mapping in the Bean Validation XML format.

The stream should be closed by the client API after the ValidatorFactory has been built. The Bean Validation provider must not close the stream.

Parameters
stream:InputStream

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 provider

Returns:T

this following the chaining method pattern

Exceptions
IllegalArgumentException:
if stream is null
addPropertyback to summary
public 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 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.

Parameters
name:String

property name

value:String

property value

Returns:T

this following the chaining method pattern

Exceptions
IllegalArgumentException:
if name is null
addValueExtractorback to summary
public 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:ValueExtractor<?>

value extractor implementation

Returns:T

this following the chaining method pattern.

Exceptions
ValueExtractorDeclarationException:
if more than one extractor for the same type and type parameter is added
Since
2.0
buildValidatorFactoryback to summary
public ValidatorFactory buildValidatorFactory()

Build a ValidatorFactory implementation.

Returns:ValidatorFactory

the ValidatorFactory

Exceptions
ValidationException:
if the ValidatorFactory cannot be built
clockProviderback to summary
public T clockProvider(ClockProvider clockProvider)

Defines the clock provider. Has priority over the configuration based provider.

If null is passed, the default clock provider is used (defined in XML or the specification default).

Parameters
clockProvider:ClockProvider

clock provider implementation

Returns:T

this following the chaining method pattern.

Since
2.0
constraintValidatorFactoryback to summary
public T constraintValidatorFactory(ConstraintValidatorFactory constraintValidatorFactory)

Defines the constraint validator factory. Has priority over the configuration based constraint factory.

If null is passed, the default constraint validator factory is used (defined in XML or the specification default).

Parameters
constraintValidatorFactory:ConstraintValidatorFactory

constraint factory implementation

Returns:T

this following the chaining method pattern

getBootstrapConfigurationback to summary
public BootstrapConfiguration getBootstrapConfiguration()

Returns configuration information stored in the META-INF/validation.xml file.

Note


Implementations are encouraged to lazily build this object to delay parsing.

Returns:BootstrapConfiguration

returns an instance of 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 map

Since
1.1
getDefaultClockProviderback to summary
public 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.
Returns:ClockProvider

default ClockProvider implementation compliant with the specification

Since
2.0
getDefaultConstraintValidatorFactoryback to summary
public ConstraintValidatorFactory getDefaultConstraintValidatorFactory()

Returns an implementation of the ConstraintValidatorFactory interface following the default ConstraintValidatorFactory defined in the specification:

Returns:ConstraintValidatorFactory

default ConstraintValidatorFactory implementation compliant with the specification

getDefaultMessageInterpolatorback to summary
public 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()
Returns:MessageInterpolator

default MessageInterpolator implementation compliant with the specification

getDefaultParameterNameProviderback to summary
public 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. arg0, arg1 etc.
Returns:ParameterNameProvider

default ParameterNameProvider implementation compliant with the specification

Since
1.1
getDefaultTraversableResolverback to summary
public 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.
Returns:TraversableResolver

default TraversableResolver implementation compliant with the specification

ignoreXmlConfigurationback to summary
public T ignoreXmlConfiguration()

Ignores data from the 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.

Returns:T

this following the chaining method pattern.

messageInterpolatorback to summary
public T messageInterpolator(MessageInterpolator interpolator)

Defines the message interpolator used. Has priority over the configuration based message interpolator.

If null is passed, the default message interpolator is used (defined in XML or the specification default).

Parameters
interpolator:MessageInterpolator

message interpolator implementation

Returns:T

this following the chaining method pattern

parameterNameProviderback to summary
public T parameterNameProvider(ParameterNameProvider parameterNameProvider)

Defines the parameter name provider. Has priority over the configuration based provider.

If null is passed, the default parameter name provider is used (defined in XML or the specification default).

Parameters
parameterNameProvider:ParameterNameProvider

parameter name provider implementation

Returns:T

this following the chaining method pattern.

Since
1.1
traversableResolverback to summary
public T traversableResolver(TraversableResolver resolver)

Defines the traversable resolver used. Has priority over the configuration based traversable resolver.

If null is passed, the default traversable resolver is used (defined in XML or the specification default).

Parameters
resolver:TraversableResolver

traversable resolver implementation

Returns:T

this following the chaining method pattern