/** * Runs the validator resolution algorithm. * * @param validatedValueType The type of the value to be validated (the type of the member/class the constraint was placed on). * * @return The class of a matching validator. */ private <A extends Annotation> ConstraintValidatorDescriptor<A> findMatchingValidatorDescriptor(ConstraintDescriptorImpl<A> descriptor, Type validatedValueType) { Map<Type, ConstraintValidatorDescriptor<A>> availableValidatorDescriptors = TypeHelper.getValidatorTypes( descriptor.getAnnotationType(), descriptor.getMatchingConstraintValidatorDescriptors() ); List<Type> discoveredSuitableTypes = findSuitableValidatorTypes( validatedValueType, availableValidatorDescriptors.keySet() ); resolveAssignableTypes( discoveredSuitableTypes ); if ( discoveredSuitableTypes.size() == 0 ) { return null; } if ( discoveredSuitableTypes.size() > 1 ) { throw LOG.getMoreThanOneValidatorFoundForTypeException( validatedValueType, discoveredSuitableTypes ); } Type suitableType = discoveredSuitableTypes.get( 0 ); return availableValidatorDescriptors.get( suitableType ); }
/** * Runs the validator resolution algorithm. * * @param validatedValueType The type of the value to be validated (the type of the member/class the constraint was placed on). * * @return The class of a matching validator. */ private <A extends Annotation> Class<? extends ConstraintValidator<A, ?>> findMatchingValidatorClass(ConstraintDescriptorImpl<A> descriptor, Type validatedValueType) { Map<Type, Class<? extends ConstraintValidator<A, ?>>> availableValidatorTypes = TypeHelper.getValidatorsTypes( descriptor.getAnnotationType(), descriptor.getMatchingConstraintValidatorClasses() ); List<Type> discoveredSuitableTypes = findSuitableValidatorTypes( validatedValueType, availableValidatorTypes ); resolveAssignableTypes( discoveredSuitableTypes ); if ( discoveredSuitableTypes.size() == 0 ) { return null; } if ( discoveredSuitableTypes.size() > 1 ) { throw LOG.getMoreThanOneValidatorFoundForTypeException( validatedValueType, discoveredSuitableTypes ); } Type suitableType = discoveredSuitableTypes.get( 0 ); return availableValidatorTypes.get( suitableType ); }