All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.micronaut.validation.validator.ExecutableMethodValidator Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2017-2020 original authors
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.micronaut.validation.validator;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.beans.BeanIntrospection;
import io.micronaut.core.type.Argument;
import io.micronaut.core.type.MutableArgumentValue;
import io.micronaut.inject.ExecutableMethod;

import javax.validation.ConstraintViolation;
import javax.validation.ConstraintViolationException;
import javax.validation.executable.ExecutableValidator;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Set;

/**
 * Extended version of {@link ExecutableValidator} that operates on {@link io.micronaut.inject.ExecutableMethod} instances.
 *
 * @author graemerocher
 * @since 1.2
 */
public interface ExecutableMethodValidator extends ExecutableValidator  {


    /**
     * Create a new valid instance.
     *
     * @param type The type
     * @param arguments The arguments
     * @param  the generic type
     * @return The instance
     * @throws ConstraintViolationException If a valid instance couldn't be constructed
     * @throws IllegalArgumentException If an argument is invalid
     */
    @NonNull  T createValid(@NonNull Class type, Object... arguments) throws ConstraintViolationException;

    /**
     * Validate the parameter values of the given {@link ExecutableMethod}.
     * @param object The object
     * @param method The method
     * @param parameterValues The values
     * @param groups The groups
     * @param  The object type
     * @return The constraint violations.
     */
    @NonNull  Set> validateParameters(
            @NonNull T object,
            @NonNull ExecutableMethod method,
            @NonNull Object[] parameterValues,
            @Nullable Class... groups);

    /**
     * Validate the parameter values of the given {@link ExecutableMethod}.
     * @param object The object
     * @param method The method
     * @param argumentValues The values
     * @param groups The groups
     * @param  The object type
     * @return The constraint violations.
     */
    @NonNull  Set> validateParameters(
            @NonNull T object,
            @NonNull ExecutableMethod method,
            @NonNull Collection> argumentValues,
            @Nullable Class... groups);

    /**
     * Validates the return value of a {@link ExecutableMethod}.
     * @param object The object
     * @param executableMethod The method
     * @param returnValue The return value
     * @param groups The groups
     * @param  The object type
     * @return A set of contstraint violations
     */
    @NonNull  Set> validateReturnValue(
            @NonNull T object,
            @NonNull ExecutableMethod executableMethod,
            @Nullable Object returnValue,
            @Nullable Class... groups);

    /**
     * Validates parameters for the given introspection and values.
     * @param introspection The introspection
     * @param parameterValues The parameter values
     * @param groups The groups
     * @param  The bean type.
     * @return The constraint violations
     */
    @NonNull
     Set> validateConstructorParameters(
            @NonNull BeanIntrospection introspection,
            @NonNull Object[] parameterValues,
            @Nullable Class... groups);

    /**
     * Validates arguments for the given bean type and constructor arguments.
     * @param beanType The bean type
     * @param constructorArguments The constructor arguments
     * @param parameterValues The parameter values
     * @param groups The validation groups
     * @param  The generic type of the bean
     * @return A set of constraint violations, if any
     */
     Set> validateConstructorParameters(
            @NonNull Class beanType,
            @NonNull Argument[] constructorArguments,
            @NonNull Object[] parameterValues,
            @Nullable Class[] groups
    );

    @Override
    @NonNull  Set> validateParameters(@NonNull T object, @NonNull Method method, @NonNull Object[] parameterValues, @Nullable Class... groups);

    @Override
    @NonNull  Set> validateReturnValue(@NonNull T object, @NonNull Method method, @Nullable Object returnValue, @Nullable Class... groups);

    @Override
    @NonNull  Set> validateConstructorParameters(@NonNull Constructor constructor, @NonNull Object[] parameterValues, @Nullable Class... groups);

    @Override
    @NonNull  Set> validateConstructorReturnValue(@NonNull Constructor constructor, @NonNull T createdObject, @Nullable Class... groups);
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy