Top Description Inners Methods
org.hibernate.validator.spi.cfg

public Interface ConstraintMappingContributor

Known Direct Implementers
org.hibernate.validator.internal.engine.ServiceLoaderBasedConstraintMappingContributor
Imports
org.hibernate.validator.cfg.ConstraintMapping

Implementations contribute ConstraintMappings to validator factory.

A constraint mapping contributor can be configured in META-INF/validation.xml, using the property org.hibernate.validator.HibernateValidatorConfiguration#CONSTRAINT_MAPPING_CONTRIBUTORS, thus allowing to set up constraints to be validated by default validators dynamically via the API for programmatic constraint declaration.

Implementations must have a no-args constructor.

One or more mappings can be added as shown in the following:

public static class MyConstraintMappingContributor implements ConstraintMappingContributor {

    public void createConstraintMappings(ConstraintMappingBuilder builder) {
        builder.addConstraintMapping()
            .type( Marathon.class )
                .property( "name", METHOD )
                    .constraint( new NotNullDef() )
                .property( "numberOfHelpers", FIELD )
                    .constraint( new MinDef().value( 1 ) );

        builder.addConstraintMapping()
            .type( Runner.class )
                .property( "paidEntryFee", FIELD )
                    .constraint( new AssertTrueDef() );
    }
}

Author
Gunnar Morling
See Also
org.hibernate.validator.HibernateValidatorConfiguration#CONSTRAINT_MAPPING_CONTRIBUTORS

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static interface
ConstraintMappingContributor.ConstraintMappingBuilder

A builder for adding constraint mappings.

Method Summary

Modifier and TypeMethod and Description
public void
createConstraintMappings(ConstraintMappingContributor.ConstraintMappingBuilder
A builder for adding one or more constraint mappings
builder
)

Callback invoked during validator factory creation.

Method Detail

createConstraintMappingsback to summary
public void createConstraintMappings(ConstraintMappingContributor.ConstraintMappingBuilder builder)

Callback invoked during validator factory creation. Any constraint mapping configured via the passed builder will be added to the mappings of the factory.

Parameters
builder:ConstraintMappingContributor.ConstraintMappingBuilder

A builder for adding one or more constraint mappings

org.hibernate.validator.spi.cfg back to summary

public Interface ConstraintMappingContributor.ConstraintMappingBuilder

Known Direct Implementers
org.hibernate.validator.internal.engine.ValidatorFactoryConfigurationHelper.DefaultConstraintMappingBuilder

A builder for adding constraint mappings.

Method Summary

Modifier and TypeMethod and Description
public ConstraintMapping

Returns:

The constraint mapping for further configuration via the fluent API.
addConstraintMapping
()

Adds a new constraint mapping.

Method Detail

addConstraintMappingback to summary
public ConstraintMapping addConstraintMapping()

Adds a new constraint mapping.

Returns:ConstraintMapping

The constraint mapping for further configuration via the fluent API.