001/*
002 * Copyright 2002-2014 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;
018
019import org.springframework.beans.factory.HierarchicalBeanFactory;
020import org.springframework.beans.factory.ListableBeanFactory;
021import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
022import org.springframework.core.env.EnvironmentCapable;
023import org.springframework.core.io.support.ResourcePatternResolver;
024
025/**
026 * Central interface to provide configuration for an application.
027 * This is read-only while the application is running, but may be
028 * reloaded if the implementation supports this.
029 *
030 * <p>An ApplicationContext provides:
031 * <ul>
032 * <li>Bean factory methods for accessing application components.
033 * Inherited from {@link org.springframework.beans.factory.ListableBeanFactory}.
034 * <li>The ability to load file resources in a generic fashion.
035 * Inherited from the {@link org.springframework.core.io.ResourceLoader} interface.
036 * <li>The ability to publish events to registered listeners.
037 * Inherited from the {@link ApplicationEventPublisher} interface.
038 * <li>The ability to resolve messages, supporting internationalization.
039 * Inherited from the {@link MessageSource} interface.
040 * <li>Inheritance from a parent context. Definitions in a descendant context
041 * will always take priority. This means, for example, that a single parent
042 * context can be used by an entire web application, while each servlet has
043 * its own child context that is independent of that of any other servlet.
044 * </ul>
045 *
046 * <p>In addition to standard {@link org.springframework.beans.factory.BeanFactory}
047 * lifecycle capabilities, ApplicationContext implementations detect and invoke
048 * {@link ApplicationContextAware} beans as well as {@link ResourceLoaderAware},
049 * {@link ApplicationEventPublisherAware} and {@link MessageSourceAware} beans.
050 *
051 * @author Rod Johnson
052 * @author Juergen Hoeller
053 * @see ConfigurableApplicationContext
054 * @see org.springframework.beans.factory.BeanFactory
055 * @see org.springframework.core.io.ResourceLoader
056 */
057public interface ApplicationContext extends EnvironmentCapable, ListableBeanFactory, HierarchicalBeanFactory,
058                MessageSource, ApplicationEventPublisher, ResourcePatternResolver {
059
060        /**
061         * Return the unique id of this application context.
062         * @return the unique id of the context, or {@code null} if none
063         */
064        String getId();
065
066        /**
067         * Return a name for the deployed application that this context belongs to.
068         * @return a name for the deployed application, or the empty String by default
069         */
070        String getApplicationName();
071
072        /**
073         * Return a friendly name for this context.
074         * @return a display name for this context (never {@code null})
075         */
076        String getDisplayName();
077
078        /**
079         * Return the timestamp when this context was first loaded.
080         * @return the timestamp (ms) when this context was first loaded
081         */
082        long getStartupDate();
083
084        /**
085         * Return the parent context, or {@code null} if there is no parent
086         * and this is the root of the context hierarchy.
087         * @return the parent context, or {@code null} if there is no parent
088         */
089        ApplicationContext getParent();
090
091        /**
092         * Expose AutowireCapableBeanFactory functionality for this context.
093         * <p>This is not typically used by application code, except for the purpose of
094         * initializing bean instances that live outside of the application context,
095         * applying the Spring bean lifecycle (fully or partly) to them.
096         * <p>Alternatively, the internal BeanFactory exposed by the
097         * {@link ConfigurableApplicationContext} interface offers access to the
098         * {@link AutowireCapableBeanFactory} interface too. The present method mainly
099         * serves as a convenient, specific facility on the ApplicationContext interface.
100         * <p><b>NOTE: As of 4.2, this method will consistently throw IllegalStateException
101         * after the application context has been closed.</b> In current Spring Framework
102         * versions, only refreshable application contexts behave that way; as of 4.2,
103         * all application context implementations will be required to comply.
104         * @return the AutowireCapableBeanFactory for this context
105         * @throws IllegalStateException if the context does not support the
106         * {@link AutowireCapableBeanFactory} interface, or does not hold an
107         * autowire-capable bean factory yet (e.g. if {@code refresh()} has
108         * never been called), or if the context has been closed already
109         * @see ConfigurableApplicationContext#refresh()
110         * @see ConfigurableApplicationContext#getBeanFactory()
111         */
112        AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException;
113
114}