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 ); } }
private void addMatchingDescriptorsForGroup(Class<?> group, Set<ConstraintDescriptor<?>> matchingDescriptors) { for ( ConstraintDescriptorImpl<?> descriptor : constraintDescriptors ) { if ( definedInSet.contains( descriptor.getDefinedOn() ) && elementTypes.contains( descriptor.getElementType() ) && descriptor.getGroups().contains( group ) ) { matchingDescriptors.add( descriptor ); } } }
private <A extends Annotation> ConstraintDescriptorImpl<A> buildConstraintDescriptor(Member member, A annotation, ElementType type) { return new ConstraintDescriptorImpl<A>( constraintHelper, member, annotation, type ); }
public Map<Type, Class<? extends ConstraintValidator<T, ?>>> getAvailableValidatorTypes() { Map<Type, Class<? extends ConstraintValidator<T, ?>>> availableValidatorTypes = TypeHelper.getValidatorsTypes( getAnnotationType(), getMatchingConstraintValidatorClasses() ); return availableValidatorTypes; }
this.attributes = buildAnnotationParameterMap( annotation ); this.groups = buildGroupSet( implicitGroup ); this.payloads = buildPayloadSet( annotation ); this.constraintType = determineConstraintType( annotation.annotationType(), member, externalConstraintType ); this.composingConstraints = parseComposingConstraints( member, constraintHelper, constraintType ); this.compositionType = parseCompositionType( constraintHelper ); validateComposingConstraintTypes();
this.groups = buildGroupSet( annotationDescriptor, implicitGroup ); this.payloads = buildPayloadSet( annotationDescriptor ); this.valueUnwrapping = determineValueUnwrapping( this.payloads, member, annotationDescriptor.getType() ); this.validationAppliesTo = determineValidationAppliesTo( annotationDescriptor ); this.constraintType = determineConstraintType( annotationDescriptor.getType(), member, externalConstraintType ); this.composingConstraints = parseComposingConstraints( constraintHelper, member, constraintType ); this.compositionType = parseCompositionType( constraintHelper ); validateComposingConstraintTypes();
private void findMatchingDescriptors(Set<ConstraintDescriptor<?>> matchingDescriptors) { if ( !groups.isEmpty() ) { ValidationOrder validationOrder = new ValidationOrderGenerator().getValidationOrder( groups ); Iterator<Group> groupIterator = validationOrder.getGroupIterator(); while ( groupIterator.hasNext() ) { Group g = groupIterator.next(); addMatchingDescriptorsForGroup( g.getDefiningClass(), matchingDescriptors ); } } else { for ( ConstraintDescriptorImpl<?> descriptor : constraintDescriptors ) { if ( definedInSet.contains( descriptor.getDefinedOn() ) && elementTypes.contains( descriptor.getElementType() ) ) { matchingDescriptors.add( descriptor ); } } } } }
.put("field", "") .put("reason", ((ConstraintDescriptorImpl<?>) cv.getConstraintDescriptor()) .getAnnotationType().getSimpleName()) .put("msg", cv.getMessage())) );
/** * 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 ); }
if (cdi1.getElementType() != null ? !cdi1.getElementType().equals(cdi2.getElementType()) : cdi2.getElementType() != null) { return false;
annotationType, run( GetAnnotationAttributes.action( constraintAnnotation ) ) ); annotationDescriptorBuilder.setPayload( payloads.toArray( new Class<?>[payloads.size()] ) ); if ( annotationDescriptorBuilder.hasAttribute( ConstraintHelper.VALIDATION_APPLIES_TO ) ) { ConstraintTarget validationAppliesTo = getValidationAppliesTo(); return new ConstraintDescriptorImpl<>( constraintHelper, member, annotationDescriptorBuilder.build(), elementType, null, definedOn, constraintType );
private <A extends Annotation> MetaConstraint<A> adaptOriginAndImplicitGroup(MetaConstraint<A> constraint) { ConstraintOrigin definedIn = definedIn( beanClass, constraint.getLocation().getDeclaringClass() ); if ( definedIn == ConstraintOrigin.DEFINED_LOCALLY ) { return constraint; } Class<?> constraintClass = constraint.getLocation().getDeclaringClass(); ConstraintDescriptorImpl<A> descriptor = new ConstraintDescriptorImpl<A>( constraintHelper, constraint.getLocation().getMember(), constraint.getDescriptor().getAnnotation(), constraint.getElementType(), constraintClass.isInterface() ? constraintClass : null, definedIn, constraint.getDescriptor().getConstraintType() ); return new MetaConstraint<A>( descriptor, constraint.getLocation() ); }
annotationType, buildAnnotationParameterMap( constraintAnnotation ) ); annotationDescriptor.setValue( ConstraintHelper.PAYLOAD, payloads.toArray( new Class<?>[payloads.size()] ) ); if ( annotationDescriptor.getElements().containsKey( ConstraintHelper.VALIDATION_APPLIES_TO ) ) { ConstraintTarget validationAppliesTo = getValidationAppliesTo(); return new ConstraintDescriptorImpl<U>( constraintHelper, member, annotationProxy, elementType, null, definedOn, constraintType );
private <A extends Annotation> MetaConstraint<A> adaptOriginAndImplicitGroup(MetaConstraint<A> constraint) { ConstraintOrigin definedIn = definedIn( beanClass, constraint.getLocation().getDeclaringClass() ); if ( definedIn == ConstraintOrigin.DEFINED_LOCALLY ) { return constraint; } Class<?> constraintClass = constraint.getLocation().getDeclaringClass(); ConstraintDescriptorImpl<A> descriptor = new ConstraintDescriptorImpl<>( constraintHelper, constraint.getLocation().getMember(), constraint.getDescriptor().getAnnotationDescriptor(), constraint.getElementType(), constraintClass.isInterface() ? constraintClass : null, definedIn, constraint.getDescriptor().getConstraintType() ); return MetaConstraints.create( typeResolutionHelper, valueExtractorManager, descriptor, constraint.getLocation() ); }
private Map<ClassIndexWrapper, Map<String, Object>> parseOverrideParameters() { Map<ClassIndexWrapper, Map<String, Object>> overrideParameters = newHashMap(); final Method[] methods = run( GetDeclaredMethods.action( annotationType ) ); for ( Method m : methods ) { if ( m.getAnnotation( OverridesAttribute.class ) != null ) { addOverrideAttributes( overrideParameters, m, m.getAnnotation( OverridesAttribute.class ) ); } else if ( m.getAnnotation( OverridesAttribute.List.class ) != null ) { addOverrideAttributes( overrideParameters, m, m.getAnnotation( OverridesAttribute.List.class ).value() ); } } return overrideParameters; }
private Set<ConstraintDescriptorImpl<?>> parseComposingConstraints(Member member, ConstraintHelper constraintHelper, ConstraintType constraintType) { Set<ConstraintDescriptorImpl<?>> composingConstraintsSet = newHashSet(); Map<ClassIndexWrapper, Map<String, Object>> overrideParameters = parseOverrideParameters(); ConstraintDescriptorImpl<?> descriptor = createComposingConstraintDescriptor( member, overrideParameters, int index = 0; for ( Annotation constraintAnnotation : multiValueConstraints ) { ConstraintDescriptorImpl<?> descriptor = createComposingConstraintDescriptor( member, overrideParameters,
private void addOverrideAttributes(Map<ClassIndexWrapper, Map<String, Object>> overrideParameters, Method m, OverridesAttribute... attributes) { Object value = run( GetAnnotationParameter.action( annotation, m.getName(), Object.class ) ); for ( OverridesAttribute overridesAttribute : attributes ) { ensureAttributeIsOverridable( m, overridesAttribute ); ClassIndexWrapper wrapper = new ClassIndexWrapper( overridesAttribute.constraint(), overridesAttribute.constraintIndex() ); Map<String, Object> map = overrideParameters.get( wrapper ); if ( map == null ) { map = newHashMap(); overrideParameters.put( wrapper, map ); } map.put( overridesAttribute.name(), value ); } }
private void addOverrideAttributes(Map<ClassIndexWrapper, Map<String, Object>> overrideParameters, Method m, OverridesAttribute... attributes) { Object value = annotationDescriptor.getAttribute( m.getName() ); for ( OverridesAttribute overridesAttribute : attributes ) { String overridesAttributeName = overridesAttribute.name().length() > 0 ? overridesAttribute.name() : m.getName(); ensureAttributeIsOverridable( m, overridesAttribute, overridesAttributeName ); ClassIndexWrapper wrapper = new ClassIndexWrapper( overridesAttribute.constraint(), overridesAttribute.constraintIndex() ); Map<String, Object> map = overrideParameters.get( wrapper ); if ( map == null ) { map = newHashMap(); overrideParameters.put( wrapper, map ); } map.put( overridesAttributeName, value ); } }
private void findMatchingDescriptors(Set<ConstraintDescriptor<?>> matchingDescriptors) { if ( !groups.isEmpty() ) { ValidationOrder validationOrder = new ValidationOrderGenerator().getValidationOrder( groups ); Iterator<Group> groupIterator = validationOrder.getGroupIterator(); while ( groupIterator.hasNext() ) { Group g = groupIterator.next(); addMatchingDescriptorsForGroup( g.getDefiningClass(), matchingDescriptors ); } } else { for ( ConstraintDescriptorImpl<?> descriptor : constraintDescriptors ) { if ( definedInSet.contains( descriptor.getDefinedOn() ) && elementTypes.contains( descriptor.getElementType() ) ) { matchingDescriptors.add( descriptor ); } } } } }
.put("field", "") .put("reason", ((ConstraintDescriptorImpl<?>) cv.getConstraintDescriptor()) .getAnnotationType().getSimpleName()) .put("msg", cv.getMessage())) );