001/*
002 * Copyright 2002-2020 the original author or authors.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.context.annotation;
018
019import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
020import org.springframework.beans.factory.support.BeanDefinitionRegistry;
021import org.springframework.core.env.Environment;
022import org.springframework.core.io.ResourceLoader;
023import org.springframework.lang.Nullable;
024
025/**
026 * Context information for use by {@link Condition} implementations.
027 *
028 * @author Phillip Webb
029 * @author Juergen Hoeller
030 * @since 4.0
031 */
032public interface ConditionContext {
033
034        /**
035         * Return the {@link BeanDefinitionRegistry} that will hold the bean definition
036         * should the condition match.
037         * @throws IllegalStateException if no registry is available (which is unusual:
038         * only the case with a plain {@link ClassPathScanningCandidateComponentProvider})
039         */
040        BeanDefinitionRegistry getRegistry();
041
042        /**
043         * Return the {@link ConfigurableListableBeanFactory} that will hold the bean
044         * definition should the condition match, or {@code null} if the bean factory is
045         * not available (or not downcastable to {@code ConfigurableListableBeanFactory}).
046         */
047        @Nullable
048        ConfigurableListableBeanFactory getBeanFactory();
049
050        /**
051         * Return the {@link Environment} for which the current application is running.
052         */
053        Environment getEnvironment();
054
055        /**
056         * Return the {@link ResourceLoader} currently being used.
057         */
058        ResourceLoader getResourceLoader();
059
060        /**
061         * Return the {@link ClassLoader} that should be used to load additional classes
062         * (only {@code null} if even the system ClassLoader isn't accessible).
063         * @see org.springframework.util.ClassUtils#forName(String, ClassLoader)
064         */
065        @Nullable
066        ClassLoader getClassLoader();
067
068}