Search in sources :

Example 1 with ExecutableType

use of jakarta.validation.executable.ExecutableType 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 ExecutableType

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

the class GeneralValidatorImpl method getExecutableTypesOnMethodInHierarchy.

protected List<ExecutableType[]> getExecutableTypesOnMethodInHierarchy(Method method) {
    Class<?> clazz = method.getDeclaringClass();
    List<ExecutableType[]> typesList = new ArrayList<ExecutableType[]>();
    while (clazz != null) {
        // We start by examining the method itself.
        Method superMethod = getSuperMethod(method, clazz);
        if (superMethod != null) {
            ExecutableType[] types = getExecutableTypesOnMethod(superMethod);
            if (types != null) {
                typesList.add(types);
            }
        }
        typesList.addAll(getExecutableTypesOnMethodInInterfaces(clazz, method));
        clazz = clazz.getSuperclass();
    }
    return typesList;
}
Also used : ExecutableType(jakarta.validation.executable.ExecutableType) ArrayList(java.util.ArrayList) RawMethod(com.fasterxml.classmate.members.RawMethod) Method(java.lang.reflect.Method) ResolvedMethod(com.fasterxml.classmate.members.ResolvedMethod)

Example 3 with ExecutableType

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

the class AbstractValidatorContextResolver method getContext.

public GeneralValidatorCDI getContext(Class<?> type) {
    try {
        BootstrapConfiguration bootstrapConfiguration = getConfig();
        boolean isExecutableValidationEnabled = bootstrapConfiguration.isExecutableValidationEnabled();
        Set<ExecutableType> defaultValidatedExecutableTypes = bootstrapConfiguration.getDefaultValidatedExecutableTypes();
        return new GeneralValidatorImpl(getValidatorFactory(), isExecutableValidationEnabled, defaultValidatedExecutableTypes);
    } catch (Exception e) {
        throw new ValidationException(Messages.MESSAGES.unableToLoadValidationSupport(), e);
    }
}
Also used : ExecutableType(jakarta.validation.executable.ExecutableType) ValidationException(jakarta.validation.ValidationException) BootstrapConfiguration(jakarta.validation.BootstrapConfiguration) NamingException(javax.naming.NamingException) ValidationException(jakarta.validation.ValidationException)

Example 4 with ExecutableType

use of jakarta.validation.executable.ExecutableType 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 5 with ExecutableType

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

the class ValidationExtension method determineConstrainedMethods.

private <T> void determineConstrainedMethods(AnnotatedType<T> type, BeanDescriptor beanDescriptor, Set<AnnotatedCallable<? super T>> callables) {
    List<Method> overriddenAndImplementedMethods = InheritedMethodsHelper.getAllMethods(type.getJavaClass());
    for (AnnotatedMethod<? super T> annotatedMethod : type.getMethods()) {
        Method method = annotatedMethod.getJavaMember();
        Optional<String> correspondingProperty = getterPropertySelectionStrategyHelper.getProperty(method);
        // obtain @ValidateOnExecution from the top-most method in the hierarchy
        Method methodForExecutableTypeRetrieval = replaceWithOverriddenOrInterfaceMethod(method, overriddenAndImplementedMethods);
        EnumSet<ExecutableType> classLevelExecutableTypes = executableTypesDefinedOnType(methodForExecutableTypeRetrieval.getDeclaringClass());
        EnumSet<ExecutableType> memberLevelExecutableType = executableTypesDefinedOnMethod(methodForExecutableTypeRetrieval, correspondingProperty.isPresent());
        ExecutableType currentExecutableType = correspondingProperty.isPresent() ? ExecutableType.GETTER_METHODS : ExecutableType.NON_GETTER_METHODS;
        // validation occurs
        if (veto(classLevelExecutableTypes, memberLevelExecutableType, currentExecutableType)) {
            continue;
        }
        boolean needsValidation;
        if (correspondingProperty.isPresent()) {
            needsValidation = isGetterConstrained(beanDescriptor, method, correspondingProperty.get());
        } else {
            needsValidation = isNonGetterConstrained(beanDescriptor, method);
        }
        if (needsValidation) {
            callables.add(annotatedMethod);
        }
    }
}
Also used : ExecutableType(jakarta.validation.executable.ExecutableType) Method(java.lang.reflect.Method) AnnotatedMethod(jakarta.enterprise.inject.spi.AnnotatedMethod)

Aggregations

ExecutableType (jakarta.validation.executable.ExecutableType)9 ValidateOnExecution (jakarta.validation.executable.ValidateOnExecution)5 Method (java.lang.reflect.Method)3 RawMethod (com.fasterxml.classmate.members.RawMethod)2 ResolvedMethod (com.fasterxml.classmate.members.ResolvedMethod)2 Constraint (jakarta.validation.Constraint)2 ValidationException (jakarta.validation.ValidationException)2 ArrayList (java.util.ArrayList)2 AnnotatedMethod (jakarta.enterprise.inject.spi.AnnotatedMethod)1 BootstrapConfiguration (jakarta.validation.BootstrapConfiguration)1 NamingException (javax.naming.NamingException)1