001/*
002 * Copyright 2012-2017 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 *      http://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.boot.context.annotation;
018
019import java.util.Set;
020
021import org.springframework.beans.factory.Aware;
022import org.springframework.context.ApplicationContext;
023import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
024import org.springframework.context.annotation.ImportSelector;
025import org.springframework.core.type.AnnotationMetadata;
026
027/**
028 * Interface that can be implemented by {@link ImportSelector} and
029 * {@link ImportBeanDefinitionRegistrar} implementations when they can determine imports
030 * early. The {@link ImportSelector} and {@link ImportBeanDefinitionRegistrar} interfaces
031 * are quite flexible which can make it hard to tell exactly what bean definitions they
032 * will add. This interface should be used when an implementation consistently results in
033 * the same imports, given the same source.
034 * <p>
035 * Using {@link DeterminableImports} is particularly useful when working with Spring's
036 * testing support. It allows for better generation of {@link ApplicationContext} cache
037 * keys.
038 *
039 * @author Phillip Webb
040 * @author Andy Wilkinson
041 * @since 1.5.0
042 */
043@FunctionalInterface
044public interface DeterminableImports {
045
046        /**
047         * Return a set of objects that represent the imports. Objects within the returned
048         * {@code Set} must implement a valid {@link Object#hashCode() hashCode} and
049         * {@link Object#equals(Object) equals}.
050         * <p>
051         * Imports from multiple {@link DeterminableImports} instances may be combined by the
052         * caller to create a complete set.
053         * <p>
054         * Unlike {@link ImportSelector} and {@link ImportBeanDefinitionRegistrar} any
055         * {@link Aware} callbacks will not be invoked before this method is called.
056         * @param metadata the source meta-data
057         * @return a key representing the annotations that actually drive the import
058         */
059        Set<Object> determineImports(AnnotationMetadata metadata);
060
061}