Search in sources :

Example 1 with AssertFalse

use of javax.validation.constraints.AssertFalse in project minijax by minijax.

the class MinijaxConstraintDescriptor method build.

@SuppressWarnings("unchecked")
public static <T extends Annotation> MinijaxConstraintDescriptor<T> build(final AnnotatedType annotatedType, final T annotation) {
    final Constraint constraint = annotation.annotationType().getAnnotation(Constraint.class);
    if (constraint == null) {
        return null;
    }
    final Class<?> valueClass = ReflectionUtils.getRawType(annotatedType);
    final Class<?> annotationClass = annotation.annotationType();
    if (constraint.validatedBy().length > 0) {
        return buildDeclaredValidator(annotation, constraint.validatedBy()[0]);
    } else if (annotationClass == AssertFalse.class) {
        return (MinijaxConstraintDescriptor<T>) buildAssertFalseValidator((AssertFalse) annotation, valueClass);
    } else if (annotationClass == AssertTrue.class) {
        return (MinijaxConstraintDescriptor<T>) buildAssertTrueValidator((AssertTrue) annotation, valueClass);
    } else if (annotationClass == Max.class) {
        return (MinijaxConstraintDescriptor<T>) buildMaxValidator((Max) annotation, valueClass);
    } else if (annotationClass == Min.class) {
        return (MinijaxConstraintDescriptor<T>) buildMinValidator((Min) annotation, valueClass);
    } else if (annotationClass == NotBlank.class) {
        return (MinijaxConstraintDescriptor<T>) buildNotBlankValidator((NotBlank) annotation, valueClass);
    } else if (annotationClass == NotEmpty.class) {
        return (MinijaxConstraintDescriptor<T>) buildNotEmptyValidator((NotEmpty) annotation, valueClass);
    } else if (annotationClass == NotNull.class) {
        return (MinijaxConstraintDescriptor<T>) buildNotNullValidator((NotNull) annotation);
    } else if (annotationClass == Pattern.class) {
        return (MinijaxConstraintDescriptor<T>) buildPatternValidator((Pattern) annotation, valueClass);
    } else if (annotationClass == Size.class) {
        return (MinijaxConstraintDescriptor<T>) buildSizeValidator((Size) annotation, valueClass);
    } else {
        throw new ValidationException("Unrecognized constraint annotation: " + annotation);
    }
}
Also used : Pattern(javax.validation.constraints.Pattern) ValidationException(javax.validation.ValidationException) Constraint(javax.validation.Constraint) Max(javax.validation.constraints.Max) Size(javax.validation.constraints.Size) AssertTrue(javax.validation.constraints.AssertTrue) NotNull(javax.validation.constraints.NotNull) Min(javax.validation.constraints.Min) NotBlank(javax.validation.constraints.NotBlank) AssertFalse(javax.validation.constraints.AssertFalse) NotEmpty(javax.validation.constraints.NotEmpty)

Aggregations

Constraint (javax.validation.Constraint)1 ValidationException (javax.validation.ValidationException)1 AssertFalse (javax.validation.constraints.AssertFalse)1 AssertTrue (javax.validation.constraints.AssertTrue)1 Max (javax.validation.constraints.Max)1 Min (javax.validation.constraints.Min)1 NotBlank (javax.validation.constraints.NotBlank)1 NotEmpty (javax.validation.constraints.NotEmpty)1 NotNull (javax.validation.constraints.NotNull)1 Pattern (javax.validation.constraints.Pattern)1 Size (javax.validation.constraints.Size)1