Skip to content

Commit 5701f4c

Browse files
committed
[jakartaee/validation#257] Support ConstraintValidator declaration via service loader [BVAL-645]
1 parent 50cd090 commit 5701f4c

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

sources/_constraint-declaration-validation.adoc

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1791,9 +1791,33 @@ When the {spec-name-bv} provider is about to perform a cascaded validation of th
17911791
* `elementType`: [classname]`ElementType.FIELD`. The [varname]`country` property is annotated on its field.
17921792

17931793

1794-
[[constraintdeclarationvalidationprocess-validationroutine-typevalidatorresolution]]
1794+
[[constraintdeclarationvalidationprocess-validationroutine-validatorresolution]]
1795+
==== ConstraintValidator resolution
1796+
1797+
[[constraintdeclarationvalidationprocess-validationroutine-register-validators]]
1798+
===== Registering ConstraintValidator implementations
1799+
1800+
Constraint validators can be registered with the validation engine in the following ways:
1801+
1802+
* Provided by the validation engine itself (see <<builtinconstraints,Built-in constraints>>)
1803+
* [tck-testable]#Via the Java https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/ServiceLoader.html[service loader] mechanism;
1804+
for this the file _META-INF/services/jakarta.validation.ConstraintValidator_ must be provided#,
1805+
with the fully-qualified name(s) of one or more constraint validator implementations as its contents.
1806+
* [tck-testable]#Provided in the `validatedBy()` attribute of the `@jakarta.validation.Constraint` annotation#.
1807+
* [tck-testable]#Through XML mapping# (see <<xml-mapping-constraintdeclarationinxml>>).
1808+
1809+
[tck-testable]#If multiple constraint validators for the exactly same constraint and target type are registered via one of the above methods,
1810+
a `jakarta.validation.ValidationException` is thrown,#
1811+
[tck-testable]#unless the constraint validator configuration source allows specifying that it overrides any previously defined constraint validators
1812+
for the particular constraint (e.g. <<xml-mapping-constraintdeclarationinxml-classleveloverriding>>/<<xml-mapping-constraintdeclarationinxml-constructorleveloverriding>>/<<xml-mapping-constraintdeclarationinxml-fieldleveloverriding>>/<<xml-mapping-constraintdeclarationinxml-methodleveloverriding>>/<<xml-mapping-constraintdeclarationinxml-propertyleveloverriding>>).#
17951813

1796-
==== ConstraintValidator resolution algorithm
1814+
[NOTE]
1815+
====
1816+
{spec-name-bv} providers may have other means to register and/or override constraint validators.
1817+
====
1818+
1819+
[[constraintdeclarationvalidationprocess-validationroutine-typevalidatorresolution]]
1820+
===== ConstraintValidator resolution algorithm
17971821

17981822
A constraint is associated to one or more [classname]`ConstraintValidator` implementations. Each [classname]`ConstraintValidator<A, T>` accepts the type [classname]`T`. The [classname]`ConstraintValidator` executed depends on the type hosting the constraint. For a given constraint evaluation, a single [classname]`ConstraintValidator` is considered.
17991823

@@ -1909,7 +1933,7 @@ Exactly one value extractor must be identified when processing a container eleme
19091933
Value extractors can be registered with the validation engine in the following ways (in increasing order of priority):
19101934

19111935
* Provided by the validation engine itself (see <<valueextractordefinition-builtinvalueextractors>>)
1912-
* [tck-testable]#Via the Java https://docs.oracle.com/javase/8/docs/api/java/util/ServiceLoader.html[service loader] mechanism; for this the file _META-INF/services/jakarta.validation.valueextraction.ValueExtractor_ must be provided#,
1936+
* [tck-testable]#Via the Java https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/util/ServiceLoader.html[service loader] mechanism; for this the file _META-INF/services/jakarta.validation.valueextraction.ValueExtractor_ must be provided#,
19131937
with the fully-qualified name(s) of one or more extractor implementations as its contents.
19141938
It is undefined which value extractor will be selected if multiple extractors for the same type and type parameter are registered via the service loader mechanism.
19151939
* [tck-testable]#By specifying the fully-qualified class name of one or several extractors in `META-INF/validation.xml`# (see <<validationapi-bootstrapping-xmlconfiguration>>). Not more than one extractor for the same type and type parameter may be given.

0 commit comments

Comments
 (0)