|
30 | 30 | import javax.validation.ParameterNameProvider;
|
31 | 31 | import javax.validation.TraversableResolver;
|
32 | 32 | import javax.validation.Validation;
|
| 33 | +import javax.validation.ValidationException; |
33 | 34 | import javax.validation.ValidationProviderResolver;
|
34 | 35 | import javax.validation.Validator;
|
35 | 36 | import javax.validation.ValidatorContext;
|
|
64 | 65 | * you will almost always use the default Validator anyway. This can also be injected directly
|
65 | 66 | * into any target dependency of type {@link org.springframework.validation.Validator}!
|
66 | 67 | *
|
67 |
| - * <p><b>As of Spring 5.0, this class requires Bean Validation 1.1, with special support |
| 68 | + * <p><b>As of Spring 5.0, this class requires Bean Validation 1.1+, with special support |
68 | 69 | * for Hibernate Validator 5.x</b> (see {@link #setValidationMessageSource}).
|
| 70 | + * This class is also runtime-compatible with Bean Validation 2.0 and Hibernate Validator 6.0, |
| 71 | + * with one special note: If you'd like to call BV 2.0's {@code getClockProvider()} method, |
| 72 | + * obtain the native {@code ValidatorFactory} through {@code #unwrap(ValidatorFactory.class)} |
| 73 | + * and call the {@code getClockProvider()} method on the returned native reference there. |
69 | 74 | *
|
70 | 75 | * <p>This class is also being used by Spring's MVC configuration namespace, in case of the
|
71 | 76 | * {@code javax.validation} API being present but no explicit Validator having been configured.
|
@@ -293,7 +298,6 @@ public void afterPropertiesSet() {
|
293 | 298 | }
|
294 | 299 |
|
295 | 300 | private void configureParameterNameProviderIfPossible(Configuration<?> configuration) {
|
296 |
| - // TODO: inner class |
297 | 301 | final ParameterNameDiscoverer discoverer = this.parameterNameDiscoverer;
|
298 | 302 | final ParameterNameProvider defaultProvider = configuration.getDefaultParameterNameProvider();
|
299 | 303 | configuration.parameterNameProvider(new ParameterNameProvider() {
|
@@ -359,6 +363,32 @@ public ParameterNameProvider getParameterNameProvider() {
|
359 | 363 | return this.validatorFactory.getParameterNameProvider();
|
360 | 364 | }
|
361 | 365 |
|
| 366 | + // Bean Validation 2.0: currently not implemented here since it would imply |
| 367 | + // a hard dependency on the new javax.validation.ClockProvider interface. |
| 368 | + // To be resolved once Spring Framework requires Bean Validation 2.0+. |
| 369 | + // Obtain the native ValidatorFactory through unwrap(ValidatorFactory.class) |
| 370 | + // instead which will fully support a getClockProvider() call as well. |
| 371 | + /* |
| 372 | + @Override |
| 373 | + public javax.validation.ClockProvider getClockProvider() { |
| 374 | + Assert.notNull(this.validatorFactory, "No target ValidatorFactory set"); |
| 375 | + return this.validatorFactory.getClockProvider(); |
| 376 | + } |
| 377 | + */ |
| 378 | + |
| 379 | + @Override |
| 380 | + public <T> T unwrap(Class<T> type) { |
| 381 | + if (type == null || !ValidatorFactory.class.isAssignableFrom(type)) { |
| 382 | + try { |
| 383 | + return super.unwrap(type); |
| 384 | + } |
| 385 | + catch (ValidationException ex) { |
| 386 | + // ignore - we'll try ValidatorFactory unwrapping next |
| 387 | + } |
| 388 | + } |
| 389 | + return this.validatorFactory.unwrap(type); |
| 390 | + } |
| 391 | + |
362 | 392 | public void close() {
|
363 | 393 | if (this.validatorFactory != null) {
|
364 | 394 | this.validatorFactory.close();
|
|
0 commit comments