Search in sources :

Example 6 with ExecutableType

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

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

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

the class GeneralValidatorImpl method getExecutableTypesOnMethodInInterfaces.

protected List<ExecutableType[]> getExecutableTypesOnMethodInInterfaces(Class<?> clazz, Method method) {
    List<ExecutableType[]> typesList = new ArrayList<ExecutableType[]>();
    Class<?>[] interfaces = clazz.getInterfaces();
    for (int i = 0; i < interfaces.length; i++) {
        Method interfaceMethod = getSuperMethod(method, interfaces[i]);
        if (interfaceMethod != null) {
            ExecutableType[] types = getExecutableTypesOnMethod(interfaceMethod);
            if (types != null) {
                typesList.add(types);
            }
        }
        List<ExecutableType[]> superList = getExecutableTypesOnMethodInInterfaces(interfaces[i], method);
        if (superList.size() > 0) {
            typesList.addAll(superList);
        }
    }
    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) Constraint(jakarta.validation.Constraint)

Example 9 with ExecutableType

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