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

io.micronaut.context.condition.ConditionContext Maven / Gradle / Ivy

There is a newer version: 4.7.5
Show 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.context.condition;

import io.micronaut.context.BeanContext;
import io.micronaut.context.BeanLocator;
import io.micronaut.context.BeanResolutionContext;
import io.micronaut.core.annotation.AnnotationMetadataProvider;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.value.PropertyResolver;

import java.util.Collections;
import java.util.List;

/**
 * The ConditionContext passed to a {@link Condition}.
 *
 * @param  The type
 * @author Graeme Rocher
 * @since 1.0
 */
public interface ConditionContext extends BeanLocator, PropertyResolver {

    /**
     * The component for which the condition is being evaluated.
     *
     * @return Either a {@link io.micronaut.inject.BeanDefinition} or a {@link io.micronaut.inject.BeanConfiguration}
     */
    T getComponent();

    /**
     * @return The bean context
     */
    BeanContext getBeanContext();

    /**
     * @return The resolution context
     */
    BeanResolutionContext getBeanResolutionContext();

    /**
     * Fail the condition with the given message.
     *
     * @param failure The failure
     * @return The {@link ConditionContext}
     */
    ConditionContext fail(@NonNull Failure failure);

    /**
     * Fail the condition with the given message.
     *
     * @param failure The failure
     * @return The {@link ConditionContext}
     */
    default ConditionContext fail(@NonNull String failure) {
        return fail(Failure.simple(failure));
    }

    /**
     * @return A list of failures for the condition
     */
    default List getFailures() {
        return Collections.emptyList();
    }

    /**
     * @return Whether there are any failures
     */
    default boolean isFailing() {
        return !getFailures().isEmpty();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy