private void throwExceptionForNullValidator(Type validatedValueType, String path) { if ( descriptor.getConstraintType() == ConstraintDescriptorImpl.ConstraintType.CROSS_PARAMETER ) { throw log.getValidatorForCrossParameterConstraintMustEitherValidateObjectOrObjectArrayException( descriptor.getAnnotationType() ); } else { String className = validatedValueType.toString(); if ( validatedValueType instanceof Class ) { Class<?> clazz = (Class<?>) validatedValueType; if ( clazz.isArray() ) { className = clazz.getComponentType().toString() + "[]"; } else { className = clazz.getName(); } } throw log.getNoValidatorFoundForTypeException( descriptor.getAnnotationType(), className, path ); } }
private ValidationException getExceptionForNullValidator(Type validatedValueType, String path) { if ( descriptor.getConstraintType() == ConstraintDescriptorImpl.ConstraintType.CROSS_PARAMETER ) { return LOG.getValidatorForCrossParameterConstraintMustEitherValidateObjectOrObjectArrayException( descriptor.getAnnotationType() ); } else { String className = validatedValueType.toString(); if ( validatedValueType instanceof Class ) { Class<?> clazz = (Class<?>) validatedValueType; if ( clazz.isArray() ) { className = clazz.getComponentType().toString() + "[]"; } else { className = clazz.getName(); } } return LOG.getNoValidatorFoundForTypeException( descriptor.getAnnotationType(), className, path ); } }
public Map<Type, Class<? extends ConstraintValidator<T, ?>>> getAvailableValidatorTypes() { Map<Type, Class<? extends ConstraintValidator<T, ?>>> availableValidatorTypes = TypeHelper.getValidatorsTypes( getAnnotationType(), getMatchingConstraintValidatorClasses() ); return availableValidatorTypes; }
/** * 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 ); }
.put("field", "") .put("reason", ((ConstraintDescriptorImpl<?>) cv.getConstraintDescriptor()) .getAnnotationType().getSimpleName()) .put("msg", cv.getMessage())) );
.put("field", "") .put("reason", ((ConstraintDescriptorImpl<?>) cv.getConstraintDescriptor()) .getAnnotationType().getSimpleName()) .put("msg", cv.getMessage())) );
.put("field", "") .put("reason", ((ConstraintDescriptorImpl<?>) cv.getConstraintDescriptor()) .getAnnotationType().getSimpleName()) .put("msg", cv.getMessage())) );
throw log.getConstraintValidatorExistsForWrapperAndWrappedValueException( valueContext.getPropertyPath(), descriptor.getAnnotationType(), validatedValueUnwrapper.getClass() ); descriptor.getAnnotationType(), validatedValueType.toString(), valueContext.getPropertyPath().toString()