public Map<Type, Class<? extends ConstraintValidator<T, ?>>> getAvailableValidatorTypes() { Map<Type, Class<? extends ConstraintValidator<T, ?>>> availableValidatorTypes = TypeHelper.getValidatorsTypes( getAnnotationType(), getMatchingConstraintValidatorClasses() ); return availableValidatorTypes; }
private <T> boolean mainConstraintNeedsEvaluation(ValidationContext<T> executionContext, Set<ConstraintViolation<T>> constraintViolations) { // we are dealing with a composing constraint with no validator for the main constraint if ( !descriptor.getComposingConstraints().isEmpty() && descriptor.getMatchingConstraintValidatorClasses() .isEmpty() ) { return false; } // report as single violation and there is already a violation if ( descriptor.isReportAsSingleViolation() && descriptor.getCompositionType() == AND && !constraintViolations.isEmpty() ) { return false; } // explicit fail fast mode if ( executionContext.isFailFastModeEnabled() && !constraintViolations.isEmpty() ) { return false; } return true; }
/** * 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 ); }