Search in sources :

Example 1 with ValidateOnExecution

use of jakarta.validation.executable.ValidateOnExecution in project resteasy by resteasy.

the class GeneralValidatorImpl method getExecutableTypesOnMethod.

protected static ExecutableType[] getExecutableTypesOnMethod(Method method) {
    ValidateOnExecution voe = method.getAnnotation(ValidateOnExecution.class);
    if (voe == null || voe.type().length == 0) {
        return null;
    }
    ExecutableType[] types = voe.type();
    if (types == null || types.length == 0) {
        return null;
    }
    return types;
}
Also used : ExecutableType(jakarta.validation.executable.ExecutableType) ValidateOnExecution(jakarta.validation.executable.ValidateOnExecution)

Example 2 with ValidateOnExecution

use of jakarta.validation.executable.ValidateOnExecution in project hibernate-validator by hibernate.

the class ValidationExtension method executableTypesDefinedOnMethod.

private EnumSet<ExecutableType> executableTypesDefinedOnMethod(Method method, boolean isGetter) {
    ValidateOnExecution validateOnExecutionAnnotation = method.getAnnotation(ValidateOnExecution.class);
    EnumSet<ExecutableType> executableTypes = commonExecutableTypeChecks(validateOnExecutionAnnotation);
    if (executableTypes.contains(ExecutableType.IMPLICIT)) {
        if (isGetter) {
            executableTypes.add(ExecutableType.GETTER_METHODS);
        } else {
            executableTypes.add(ExecutableType.NON_GETTER_METHODS);
        }
    }
    return executableTypes;
}
Also used : ExecutableType(jakarta.validation.executable.ExecutableType) ValidateOnExecution(jakarta.validation.executable.ValidateOnExecution)

Example 3 with ValidateOnExecution

use of jakarta.validation.executable.ValidateOnExecution in project hibernate-validator by hibernate.

the class ValidationExtension method executableTypesDefinedOnType.

private EnumSet<ExecutableType> executableTypesDefinedOnType(Class<?> clazz) {
    ValidateOnExecution validateOnExecutionAnnotation = clazz.getAnnotation(ValidateOnExecution.class);
    EnumSet<ExecutableType> executableTypes = commonExecutableTypeChecks(validateOnExecutionAnnotation);
    if (executableTypes.contains(ExecutableType.IMPLICIT)) {
        return DEFAULT_EXECUTABLE_TYPES;
    }
    return executableTypes;
}
Also used : ExecutableType(jakarta.validation.executable.ExecutableType) ValidateOnExecution(jakarta.validation.executable.ValidateOnExecution)

Example 4 with ValidateOnExecution

use of jakarta.validation.executable.ValidateOnExecution in project hibernate-validator by hibernate.

the class ValidationExtension method executableTypesDefinedOnConstructor.

private EnumSet<ExecutableType> executableTypesDefinedOnConstructor(Constructor<?> constructor) {
    ValidateOnExecution validateOnExecutionAnnotation = constructor.getAnnotation(ValidateOnExecution.class);
    EnumSet<ExecutableType> executableTypes = commonExecutableTypeChecks(validateOnExecutionAnnotation);
    if (executableTypes.contains(ExecutableType.IMPLICIT)) {
        executableTypes.add(ExecutableType.CONSTRUCTORS);
    }
    return executableTypes;
}
Also used : ExecutableType(jakarta.validation.executable.ExecutableType) ValidateOnExecution(jakarta.validation.executable.ValidateOnExecution)

Example 5 with ValidateOnExecution

use of jakarta.validation.executable.ValidateOnExecution in project resteasy by resteasy.

the class GeneralValidatorImpl method isMethodValidatable.

@Override
public boolean isMethodValidatable(Method m) {
    if (!isExecutableValidationEnabled) {
        return false;
    }
    ExecutableType[] types = null;
    List<ExecutableType[]> typesList = getExecutableTypesOnMethodInHierarchy(m);
    if (typesList.size() > 1) {
        throw new ValidationException(Messages.MESSAGES.validateOnExceptionOnMultipleMethod());
    }
    if (typesList.size() == 1) {
        types = typesList.get(0);
    } else {
        ValidateOnExecution voe = m.getDeclaringClass().getAnnotation(ValidateOnExecution.class);
        if (voe == null) {
            types = defaultValidatedExecutableTypes;
        } else {
            if (voe.type().length > 0) {
                types = voe.type();
            } else {
                types = defaultValidatedExecutableTypes;
            }
        }
    }
    boolean isGetterMethod = isGetter(m);
    for (int i = 0; i < types.length; i++) {
        switch(types[i]) {
            case IMPLICIT:
            case ALL:
                return true;
            case NONE:
                continue;
            case NON_GETTER_METHODS:
                if (!isGetterMethod) {
                    return true;
                }
                continue;
            case GETTER_METHODS:
                if (isGetterMethod) {
                    return true;
                }
                continue;
            default:
                continue;
        }
    }
    return false;
}
Also used : ExecutableType(jakarta.validation.executable.ExecutableType) ValidateOnExecution(jakarta.validation.executable.ValidateOnExecution) ValidationException(jakarta.validation.ValidationException) Constraint(jakarta.validation.Constraint)

Aggregations

ExecutableType (jakarta.validation.executable.ExecutableType)5 ValidateOnExecution (jakarta.validation.executable.ValidateOnExecution)5 Constraint (jakarta.validation.Constraint)1 ValidationException (jakarta.validation.ValidationException)1