Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
81e2db2
HV-431 Adding me as developer.
kevinpollet Apr 11, 2011
3d5d391
HV-431 Adding a ConstraintsForProperty class.
kevinpollet Apr 5, 2011
2115f50
HV-431 Making the valid definition for a property contextual.
kevinpollet Apr 5, 2011
dfce65b
HV-431 Adding a ConstraintsForMethod class.
kevinpollet Apr 5, 2011
088a335
HV-431 Adding valid definition for method return and parameter.
kevinpollet Apr 5, 2011
204f188
HV-431 Use the grouping programmatic API approach.
kevinpollet Apr 7, 2011
dd6a547
HV-431 Adding some comments and missing license headers.
kevinpollet Apr 11, 2011
cb9859e
HV-431 Adding ReflectionHelper#getDeclaredMethod().
kevinpollet Apr 10, 2011
1c00033
HV-431 Adding MethodCascadeDef class.
kevinpollet Apr 10, 2011
ee88766
HV-431 Allow programmatic configuration of cascaded method elements (…
kevinpollet Apr 11, 2011
9dd04f6
HV-431 Clean and refactor the programmatic API.
kevinpollet Apr 11, 2011
d87e533
HV-431 Fixing error messages.
kevinpollet Apr 12, 2011
d0e1c19
HV-431 Test cascade of method elements (parameters and return value) …
kevinpollet Apr 12, 2011
f41feec
HV-431 Adding a new method in CollectionHelper allowing to create an …
kevinpollet Apr 13, 2011
b5f15c6
HV-431: Moving merge logic to model types
gunnarmorling Apr 17, 2011
78352e9
HV-431: New approach with separate constraint configuration
gunnarmorling Apr 25, 2011
59c8f6a
HV-431: Refactoring to programmatic method API:
gunnarmorling Apr 26, 2011
004cd2d
HV-431: Removing obsolete constructors from constraint definition types
gunnarmorling Apr 26, 2011
bd323c4
HV-431: Recactoring ConstraintDef et al.:
gunnarmorling Apr 27, 2011
af02a0a
HV-431: Extracting interfaces for context types
gunnarmorling Apr 27, 2011
cc582ce
HV-431: Establishing "context" sub-package
gunnarmorling Apr 27, 2011
c54c415
HV-431: Fixing wrong return types
gunnarmorling Apr 27, 2011
0b96f50
HV-431: Checking parameters of public API, adapting test
gunnarmorling Apr 29, 2011
2b684f3
HV-431: Fixing test failure due to changed invocation checking
gunnarmorling Apr 29, 2011
2a869df
HV-431: Formatting
gunnarmorling Apr 29, 2011
43b06fb
HV-431: Fixing failing test due to accidential removal of constraint …
gunnarmorling Apr 29, 2011
9fdbfee
HV-431: Removing wrong type parameter
gunnarmorling Apr 29, 2011
7ecc327
HV-431: Estabishing ConstraintDef#create() and createGeneric()
gunnarmorling May 29, 2011
773bd29
HV-431: Removing some warnings
gunnarmorling May 29, 2011
be8afb5
HV-431: Removing obsolete type parameter from ParameterMetaConstraint
gunnarmorling May 29, 2011
977e09e
HV-431: Implementing programmatic configuration of parameter constrai…
gunnarmorling May 29, 2011
6d96b15
HV-431: Parametrizing ConfiguredConstraint with its location type
gunnarmorling May 29, 2011
1198fb3
HV-431: Renaming MethodParameterConstraintLocation to ParameterConstr…
gunnarmorling May 29, 2011
2a5e988
HV-431: Simplifying TestUtil
gunnarmorling May 29, 2011
5f2b4bc
HV-431: Adding support for constraints at several parameters
gunnarmorling May 29, 2011
d4c47e4
HV-431: Simplifying test
gunnarmorling May 29, 2011
88ba9f0
HV-431: Adding more tests for parameter constraints
gunnarmorling May 29, 2011
52858c4
HV-431: Renaming meta model classes from Parameter* to Method* in ord…
gunnarmorling May 30, 2011
4d1beb9
HV-431: Simplifying creational contexts, pulling parameter checking o…
gunnarmorling May 30, 2011
11708e4
HV-431: Representing return value constraints with MethodMetaConstraint
gunnarmorling May 30, 2011
85e7a7b
HV-431: Adding some functional bling
gunnarmorling May 30, 2011
a90f38b
HV-431: Adding tests for return value constraints
gunnarmorling May 30, 2011
08cd697
HV-431: Removing redundant type parameter declarations
gunnarmorling May 30, 2011
ba4188a
HV-431: Using simplified collection instantiation at more places
gunnarmorling May 30, 2011
bcfc9d0
HV-431: Using *Location for cascaded definitions
gunnarmorling May 30, 2011
6fdf1ab
HV-431: Fixing errors due to rebase
gunnarmorling Jun 2, 2011
2e3052d
HV-431: Using create() for definition instantiation everywhere
gunnarmorling Jun 2, 2011
bca3ccb
HV-431: Removing (Method)ConstraintDef in favor of (Method)Constraint…
gunnarmorling Jun 2, 2011
5e02adf
HV-431: Removing some warnings, unused imports, unnecessary casts etc.
gunnarmorling Jun 2, 2011
aa5dc93
HV-431: Improving JavaDocs, formatting
gunnarmorling Jun 2, 2011
6cea7fe
HV-431: Adding missing package.html files. Aligning package descripti…
gunnarmorling Jun 4, 2011
92661ff
HV-431: Adding test for addition of annotion and programmatic field/p…
gunnarmorling Jun 4, 2011
625d0f0
HV-431: Unifying creation of validation proxies in test
gunnarmorling Jun 4, 2011
5556554
HV-431: Describing programmatic constraint configuration of method co…
gunnarmorling Jun 4, 2011
0e18708
HV-431: Extracting constraint mapping context from constraint mapping…
gunnarmorling Jun 4, 2011
101693d
HV-431: Parametrizing type creational context with type of bean in or…
gunnarmorling Jun 7, 2011
ab32e0d
HV-431: Renaming mapping context types
gunnarmorling Jun 8, 2011
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 107 additions & 47 deletions hibernate-validator/src/main/docbook/en-US/modules/customoptions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,93 +95,153 @@ validator = factory.unwrap( HibernateValidatorFactory.class )
<title>Programmatic constraint definition</title>

<para>Another addition to the Bean Validation specification is the ability
to configure constraints via a fluent API.This API can be used exclusively
or in combination with annotations and xml. If used in combination
programmatic constraints are additive to constraints configured via the
standard configuration capabilties.</para>
to configure constraints via a fluent API. This API can be used
exclusively or in combination with annotations and xml. If used in
combination programmatic constraints are additive to constraints
configured via the standard configuration capabilities.</para>

<para>The programmatic API is centered around the
<para>The API is centered around the
<classname>ConstraintMapping</classname> class which can be found together
with its supporting classes in the
<package>org.hibernate.validator.cfg</package> package.
<classname>ConstraintMapping</classname> is the entry point to a fluent
API allowing the definition of constraints. <xref lang=""
linkend="example-constraint-mapping" /> shows how the API can be
used.</para>
<package>org.hibernate.validator.cfg</package> package. Starting with the
instantiation of a new <classname>ConstraintMapping</classname>,
constraints can be defined in a fluent manner as shown in <xref lang=""
linkend="example-constraint-mapping" />.</para>

<para><example id="example-constraint-mapping">
<title>Programmatic constraint definition</title>

<programlisting language="" role="">ConstraintMapping mapping = new ConstraintMapping();
mapping.type( Car.class )
.property( "manufacturer", FIELD )
.constraint( NotNullDef.class )
.constraint(
create( NotNullDef.class ) )
.property( "licensePlate", FIELD )
.constraint( NotNullDef.class )
.constraint( SizeDef.class )
.min( 2 )
.max( 14 )
.constraint(
create( NotNullDef.class ) )
.constraint(
create( SizeDef.class )
.min( 2 )
.max( 14 ) )
.property( "seatCount", FIELD )
.constraint( MinDef.class )
.value ( 2 )
.constraint(
create( MinDef.class )
.value ( 2 ) )
.type( RentalCar.class )
.property( "rentalStation", METHOD)
.constraint( NotNullDef.class ); </programlisting>
.property( "rentalStation", METHOD )
.constraint(
create( NotNullDef.class ) ); </programlisting>
</example></para>

<para>As you can see you can configure constraints on multiple classes and
<para>As you can see constraints can be configured on multiple classes and
properties using method chaining. The constraint definition classes
<classname>NotNullDef</classname>, <classname>SizeDef</classname> and
<classname>MinDef</classname> are helper classes which allow to configure
constraint parameters in a type-safe fashion. Definition classes exists
for all built-in constraints in the
<classname>org.hibernate.validator.cfg.defs</classname> package. For a
custom constraint you can either create your own definition class
extending <classname>ConstraintDef</classname> or you can use the
<classname>genericConstraint</classname> method as seen in <xref
constraint parameters in a type-safe fashion. Definition classes exist for
all built-in constraints in the
<classname>org.hibernate.validator.cfg.defs</classname> package. </para>

<tip>
<para>The <methodname>create()</methodname> method (as well as
<methodname>createGeneric()</methodname> introduced in the following) is
a static method defined on
<classname>org.hibernate.validator.cfg.ConstraintDef</classname>. It is
recommended to import this method statically which allows to use it as
shown in <xref lang="" linkend="example-constraint-mapping" />.</para>
</tip>

<para>For custom constraints you can either create your own definition
classes extending <classname>ConstraintDef</classname> or you can use the
<classname>createGeneric()</classname> method as seen in <xref
linkend="example-generic-constraint-mapping" />.</para>

<para><example id="example-generic-constraint-mapping">
<title>Programmatic constraint definition using
<classname>GenericConstraintDef</classname></title>
<methodname>createGeneric()</methodname></title>

<programlisting language="" role="">ConstraintMapping mapping = new ConstraintMapping();
mapping.type( Car.class )
.property( "licensePlate", FIELD )
.genericConstraint( CheckCase.class )
.param( "value", CaseMode.UPPER ); </programlisting>
.constraint(
createGeneric( CheckCase.class )
.param( "value", CaseMode.UPPER ) ); </programlisting>
</example></para>

<para>Last but not least, you can also define cascading constraints as
well as the default group sequence or the default group sequence provider
of an entity.</para>
<para>Not only standard class- and property-level constraints but also
method constraints can be configured using the API. As shown in <xref
lang="" linkend="example-method-constraint-mapping" /> methods are
identified by their name and their parameters (if there are any). Having
selected a method, constraints can be placed on the method's parameters
and/or return value.</para>

<example id="example-method-constraint-mapping">
<title>Programmatic definition of method constraints</title>

<programlisting language="" role="">ConstraintMapping mapping = new ConstraintMapping();
mapping.type( Car.class )
.method( "drive", String.class, Integer.class )
.parameter( 0 )
.constraint(
create( NotNullDef.class ) )
.constraint(
create( MinDef.class )
.value ( 1 ) )
.parameter( 1 )
.constraint(
create( NotNullDef.class ) )
.returnValue()
.constraint(
create( NotNullDef.class ) )
.method( "check" )
.returnValue()
.constraint(
create( NotNullDef.class ) ); </programlisting>
</example>

<para>Using the API it's also possible to mark properties, method
parameters and method return values as cascading (equivalent to annotating
them with <classname>@Valid</classname>). An example can be found in <xref
lang="" linkend="example-cascading-constraints" />.</para>

<para><example>
<title>Cascading constraints and default group redefinition</title>
<para><example id="example-cascading-constraints">
<title>Marking constraints for cascaded validation</title>

<programlisting language="" role="">ConstraintMapping mapping = new ConstraintMapping();
mapping.type( Car.class )
.valid( "driver", FIELD )
.type( RentalCar.class)
.defaultGroupSequence( RentalCar.class, CarChecks.class ); </programlisting>
.property( "manufacturer", FIELD )
.valid()
.property( "licensePlate", METHOD )
.valid()
.method( "drive", String.class, Integer.class )
.parameter( 0 )
.valid()
.parameter( 1 )
.valid()
.returnValue()
.valid()
.type( RentalCar.class )
.property( "rentalStation", METHOD )
.valid();</programlisting>
</example></para>

<para><example>
<title>Cascading constraints and dynamic default group
redefinition</title>
<para>Last but not least you can configure the default group sequence or
the default group sequence provider of a type as shown in <xref lang=""
linkend="example-sequences" />.<example id="example-sequences">
<title>Configuration of default group sequence and default group
sequence provider</title>

<programlisting language="" role="">ConstraintMapping mapping = new ConstraintMapping();
mapping.type( Car.class )
.valid( "driver", FIELD )
.type( RentalCar.class)
.defaultGroupSequence( Car.class, CarChecks.class )
.type( RentalCar.class )
.defaultGroupSequenceProvider( RentalCarGroupSequenceProvider.class ); </programlisting>
</example></para>

<para>Once you have your <classname>ConstraintMapping</classname> you will
have to pass it to the configuration. Since the programmatic configuration
is not part of the official Bean Validation specification you will have to
get hold of the Hibernate Validator specific configuration instance. See
<xref linkend="example-hibernate-specific-config" />.</para>
<para>Once a <classname>ConstraintMapping</classname> is set up it has to
be passed to the configuration. Since the programmatic API is not part of
the official Bean Validation specification you need to get hold of a
<classname>HibernateValidatorConfiguration</classname> instance as shown
in <xref linkend="example-hibernate-specific-config" />.</para>

<para><example id="example-hibernate-specific-config">
<title>Creating a Hibernate Validator specific configuration</title>
Expand Down

This file was deleted.

Loading