@@ -142,7 +142,6 @@ public ValidatorFactoryImpl(ConfigurationState configurationState) {
142
142
ClassLoader externalClassLoader = getExternalClassLoader ( configurationState );
143
143
144
144
this .valueExtractorManager = new ValueExtractorManager ( configurationState .getValueExtractors () );
145
- this .getterPropertyMatcher = new DefaultGetterPropertyMatcher ();
146
145
this .beanMetaDataManagers = new ConcurrentHashMap <>();
147
146
this .constraintHelper = new ConstraintHelper ();
148
147
this .typeResolutionHelper = new TypeResolutionHelper ();
@@ -152,6 +151,9 @@ public ValidatorFactoryImpl(ConfigurationState configurationState) {
152
151
if ( configurationState instanceof ConfigurationImpl ) {
153
152
hibernateSpecificConfig = (ConfigurationImpl ) configurationState ;
154
153
}
154
+ Map <String , String > properties = configurationState .getProperties ();
155
+
156
+ this .getterPropertyMatcher = getGetterPropertyMatcher ( hibernateSpecificConfig , properties , externalClassLoader );
155
157
156
158
// HV-302; don't load XmlMappingParser if not necessary
157
159
if ( configurationState .getMappingStreams ().isEmpty () ) {
@@ -167,14 +169,13 @@ public ValidatorFactoryImpl(ConfigurationState configurationState) {
167
169
getConstraintMappings (
168
170
typeResolutionHelper ,
169
171
configurationState ,
172
+ getterPropertyMatcher ,
170
173
externalClassLoader
171
174
)
172
175
);
173
176
174
177
registerCustomConstraintValidators ( constraintMappings , constraintHelper );
175
178
176
- Map <String , String > properties = configurationState .getProperties ();
177
-
178
179
this .methodValidationConfiguration = new MethodValidationConfiguration .Builder ()
179
180
.allowOverridingMethodAlterParameterConstraint (
180
181
getAllowOverridingMethodAlterParameterConstraint ( hibernateSpecificConfig , properties )
@@ -213,7 +214,7 @@ private static ClassLoader getExternalClassLoader(ConfigurationState configurati
213
214
}
214
215
215
216
private static Set <DefaultConstraintMapping > getConstraintMappings (TypeResolutionHelper typeResolutionHelper ,
216
- ConfigurationState configurationState , ClassLoader externalClassLoader ) {
217
+ ConfigurationState configurationState , GetterPropertyMatcher getterPropertyMatcher , ClassLoader externalClassLoader ) {
217
218
Set <DefaultConstraintMapping > constraintMappings = newHashSet ();
218
219
219
220
if ( configurationState instanceof ConfigurationImpl ) {
@@ -229,7 +230,7 @@ private static Set<DefaultConstraintMapping> getConstraintMappings(TypeResolutio
229
230
ConstraintMappingContributor serviceLoaderBasedContributor = new ServiceLoaderBasedConstraintMappingContributor (
230
231
typeResolutionHelper ,
231
232
externalClassLoader != null ? externalClassLoader : run ( GetClassLoader .fromContext () ) );
232
- DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder ( constraintMappings );
233
+ DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder ( getterPropertyMatcher , constraintMappings );
233
234
serviceLoaderBasedContributor .createConstraintMappings ( builder );
234
235
}
235
236
@@ -238,7 +239,7 @@ private static Set<DefaultConstraintMapping> getConstraintMappings(TypeResolutio
238
239
externalClassLoader );
239
240
240
241
for ( ConstraintMappingContributor contributor : contributors ) {
241
- DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder ( constraintMappings );
242
+ DefaultConstraintMappingBuilder builder = new DefaultConstraintMappingBuilder ( getterPropertyMatcher , constraintMappings );
242
243
contributor .createConstraintMappings ( builder );
243
244
}
244
245
@@ -294,6 +295,11 @@ public Duration getTemporalValidationTolerance() {
294
295
return validatorFactoryScopedContext .getTemporalValidationTolerance ();
295
296
}
296
297
298
+ @ Override
299
+ public GetterPropertyMatcher getGetterPropertyMatcher () {
300
+ return getterPropertyMatcher ;
301
+ }
302
+
297
303
public boolean isFailFast () {
298
304
return validatorFactoryScopedContext .isFailFast ();
299
305
}
@@ -555,6 +561,32 @@ private Object getConstraintValidatorPayload(ConfigurationState configurationSta
555
561
return null ;
556
562
}
557
563
564
+ private static GetterPropertyMatcher getGetterPropertyMatcher (ConfigurationImpl hibernateSpecificConfig , Map <String , String > properties , ClassLoader externalClassLoader ) {
565
+ if ( hibernateSpecificConfig .getGetterPropertyMatcher () != null ) {
566
+ LOG .usingGetterPropertyMatcher ( hibernateSpecificConfig .getGetterPropertyMatcher ().getClass () );
567
+ return hibernateSpecificConfig .getGetterPropertyMatcher ();
568
+ }
569
+
570
+ String getterPropertyMatcherFqcn = properties .get ( HibernateValidatorConfiguration .GETTER_PROPERTY_MATCHER_CLASSNAME );
571
+ if ( getterPropertyMatcherFqcn != null ) {
572
+ try {
573
+ @ SuppressWarnings ("unchecked" )
574
+ Class <? extends GetterPropertyMatcher > clazz = (Class <? extends GetterPropertyMatcher >) run (
575
+ LoadClass .action ( getterPropertyMatcherFqcn , externalClassLoader )
576
+ );
577
+ GetterPropertyMatcher getterPropertyMatcher = run ( NewInstance .action ( clazz , "getter property matcher class" ) );
578
+ LOG .usingGetterPropertyMatcher ( clazz );
579
+
580
+ return getterPropertyMatcher ;
581
+ }
582
+ catch (Exception e ) {
583
+ throw LOG .getUnableToInstantiateGetterPropertyMatcherClassException ( getterPropertyMatcherFqcn , e );
584
+ }
585
+ }
586
+
587
+ return new DefaultGetterPropertyMatcher ();
588
+ }
589
+
558
590
private static void registerCustomConstraintValidators (Set <DefaultConstraintMapping > constraintMappings ,
559
591
ConstraintHelper constraintHelper ) {
560
592
Set <Class <?>> definedConstraints = newHashSet ();
@@ -603,16 +635,18 @@ private static <T> T run(PrivilegedAction<T> action) {
603
635
*/
604
636
private static class DefaultConstraintMappingBuilder
605
637
implements ConstraintMappingContributor .ConstraintMappingBuilder {
638
+
639
+ private final GetterPropertyMatcher getterPropertyMatcher ;
606
640
private final Set <DefaultConstraintMapping > mappings ;
607
641
608
- public DefaultConstraintMappingBuilder (Set <DefaultConstraintMapping > mappings ) {
609
- super () ;
642
+ public DefaultConstraintMappingBuilder (GetterPropertyMatcher getterPropertyMatcher , Set <DefaultConstraintMapping > mappings ) {
643
+ this . getterPropertyMatcher = getterPropertyMatcher ;
610
644
this .mappings = mappings ;
611
645
}
612
646
613
647
@ Override
614
648
public ConstraintMapping addConstraintMapping () {
615
- DefaultConstraintMapping mapping = new DefaultConstraintMapping ();
649
+ DefaultConstraintMapping mapping = new DefaultConstraintMapping ( getterPropertyMatcher );
616
650
mappings .add ( mapping );
617
651
return mapping ;
618
652
}
0 commit comments