Save This Page
Home » spring-framework-2.5.5-with-dependencies » org.springframework » context » support » [javadoc | source]
org.springframework.context.support
abstract public class: AbstractApplicationContext [javadoc | source]
java.lang.Object
   org.springframework.core.io.DefaultResourceLoader
      org.springframework.context.support.AbstractApplicationContext

All Implemented Interfaces:
    ConfigurableApplicationContext, DisposableBean, ResourceLoader

Direct Known Subclasses:
    XmlWebApplicationContext, StaticApplicationContext, ClassPathXmlApplicationContext, GenericApplicationContext, AbstractXmlApplicationContext, GenericWebApplicationContext, ResourceAdapterApplicationContext, AbstractRefreshableWebApplicationContext, FileSystemXmlApplicationContext, AbstractRefreshableConfigApplicationContext, StaticPortletApplicationContext, StaticWebApplicationContext, AbstractRefreshableApplicationContext, AbstractRefreshablePortletApplicationContext, XmlPortletApplicationContext

Abstract implementation of the org.springframework.context.ApplicationContext interface. Doesn't mandate the type of storage used for configuration; simply implements common context functionality. Uses the Template Method design pattern, requiring concrete subclasses to implement abstract methods.

In contrast to a plain BeanFactory, an ApplicationContext is supposed to detect special beans defined in its internal bean factory: Therefore, this class automatically registers BeanFactoryPostProcessors , BeanPostProcessors and ApplicationListeners which are defined as beans in the context.

A org.springframework.context.MessageSource may also be supplied as a bean in the context, with the name "messageSource"; otherwise, message resolution is delegated to the parent context. Furthermore, a multicaster for application events can be supplied as "applicationEventMulticaster" bean of type org.springframework.context.event.ApplicationEventMulticaster in the context; otherwise, a default multicaster of type org.springframework.context.event.SimpleApplicationEventMulticaster will be used.

Implements resource loading through extending org.springframework.core.io.DefaultResourceLoader . Consequently treats non-URL resource paths as class path resources (supporting full class path resource names that include the package path, e.g. "mypackage/myresource.dat"), unless the #getResourceByPath method is overwritten in a subclass.

Field Summary
public static final  String MESSAGE_SOURCE_BEAN_NAME    Name of the MessageSource bean in the factory. If none is supplied, message resolution is delegated to the parent. 
public static final  String APPLICATION_EVENT_MULTICASTER_BEAN_NAME    Name of the ApplicationEventMulticaster bean in the factory. If none is supplied, a default SimpleApplicationEventMulticaster is used. 
protected final  Log logger    Logger used by this class. Available to subclasses. 
Constructor:
 public AbstractApplicationContext() 
 public AbstractApplicationContext(ApplicationContext parent) 
    Create a new AbstractApplicationContext with the given parent context.
    Parameters:
    parent - the parent context
Method from org.springframework.context.support.AbstractApplicationContext Summary:
addApplicationListener,   addBeanFactoryPostProcessor,   addListener,   cancelRefresh,   close,   closeBeanFactory,   containsBean,   containsBeanDefinition,   containsLocalBean,   destroy,   destroyBeans,   doClose,   finishBeanFactoryInitialization,   finishRefresh,   getAliases,   getApplicationListeners,   getAutowireCapableBeanFactory,   getBean,   getBean,   getBean,   getBeanDefinitionCount,   getBeanDefinitionNames,   getBeanFactory,   getBeanFactoryPostProcessors,   getBeanNamesForType,   getBeanNamesForType,   getBeansOfType,   getBeansOfType,   getDisplayName,   getId,   getInternalParentBeanFactory,   getInternalParentMessageSource,   getMessage,   getMessage,   getMessage,   getParent,   getParentBeanFactory,   getResourcePatternResolver,   getResources,   getStartupDate,   getType,   initApplicationEventMulticaster,   initMessageSource,   invokeBeanFactoryPostProcessors,   isActive,   isPrototype,   isRunning,   isSingleton,   isTypeMatch,   obtainFreshBeanFactory,   onClose,   onRefresh,   postProcessBeanFactory,   prepareBeanFactory,   prepareRefresh,   publishEvent,   refresh,   refreshBeanFactory,   registerBeanPostProcessors,   registerListeners,   registerShutdownHook,   setDisplayName,   setId,   setParent,   start,   stop,   toString
Methods from org.springframework.core.io.DefaultResourceLoader:
getClassLoader,   getResource,   getResourceByPath,   setClassLoader
Methods from java.lang.Object:
equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from org.springframework.context.support.AbstractApplicationContext Detail:
 public  void addApplicationListener(ApplicationListener listener) 
 public  void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor) 
 protected  void addListener(ApplicationListener listener) 
    Subclasses can invoke this method to register a listener. Any beans in the context that are listeners are automatically added.
 protected  void cancelRefresh(BeansException ex) 
    Cancel this context's refresh attempt, resetting the active flag after an exception got thrown.
 public  void close() 
    Close this application context, destroying all beans in its bean factory.

    Delegates to doClose() for the actual closing procedure. Also removes a JVM shutdown hook, if registered, as it's not needed anymore.

 abstract protected  void closeBeanFactory()
    Subclasses must implement this method to release their internal bean factory. This method gets invoked by #close() after all other shutdown work.

    Should never throw an exception but rather log shutdown failures.

 public boolean containsBean(String name) 
 public boolean containsBeanDefinition(String name) 
 public boolean containsLocalBean(String name) 
 public  void destroy() 
    DisposableBean callback for destruction of this instance. Only called when the ApplicationContext itself is running as a bean in another BeanFactory or ApplicationContext, which is rather unusual.

    The close method is the native way to shut down an ApplicationContext.

 protected  void destroyBeans() 
    Template method for destroying all beans that this context manages. The default implementation destroy all cached singletons in this context, invoking DisposableBean.destroy() and/or the specified "destroy-method".

    Can be overridden to add context-specific bean destruction steps right before or right after standard singleton destruction, while the context's BeanFactory is still active.

 protected  void doClose() 
    Actually performs context closing: publishes a ContextClosedEvent and destroys the singletons in the bean factory of this application context.

    Called by both close() and a JVM shutdown hook, if any.

 protected  void finishBeanFactoryInitialization(ConfigurableListableBeanFactory beanFactory) 
    Finish the initialization of this context's bean factory, initializing all remaining singleton beans.
 protected  void finishRefresh() 
 public String[] getAliases(String name) 
 public List getApplicationListeners() 
    Return the list of statically specified ApplicationListeners.
 public AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException 
    Return this context's internal bean factory as AutowireCapableBeanFactory, if already available.
 public Object getBean(String name) throws BeansException 
 public Object getBean(String name,
    Class requiredType) throws BeansException 
 public Object getBean(String name,
    Object[] args) throws BeansException 
 public int getBeanDefinitionCount() 
 public String[] getBeanDefinitionNames() 
 abstract public ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException
    Subclasses must return their internal bean factory here. They should implement the lookup efficiently, so that it can be called repeatedly without a performance penalty.

    Note: Subclasses should check whether the context is still active before returning the internal bean factory. The internal factory should generally be considered unavailable once the context has been closed.

 public List getBeanFactoryPostProcessors() 
    Return the list of BeanFactoryPostProcessors that will get applied to the internal BeanFactory.
 public String[] getBeanNamesForType(Class type) 
 public String[] getBeanNamesForType(Class type,
    boolean includePrototypes,
    boolean allowEagerInit) 
 public Map getBeansOfType(Class type) throws BeansException 
 public Map getBeansOfType(Class type,
    boolean includePrototypes,
    boolean allowEagerInit) throws BeansException 
 public String getDisplayName() 
    Return a friendly name for this context.
 public String getId() 
 protected BeanFactory getInternalParentBeanFactory() 
    Return the internal bean factory of the parent context if it implements ConfigurableApplicationContext; else, return the parent context itself.
 protected MessageSource getInternalParentMessageSource() 
    Return the internal message source of the parent context if it is an AbstractApplicationContext too; else, return the parent context itself.
 public String getMessage(MessageSourceResolvable resolvable,
    Locale locale) throws NoSuchMessageException 
 public String getMessage(String code,
    Object[] args,
    Locale locale) throws NoSuchMessageException 
 public String getMessage(String code,
    Object[] args,
    String defaultMessage,
    Locale locale) 
 public ApplicationContext getParent() 
    Return the parent context, or null if there is no parent (that is, this context is the root of the context hierarchy).
 public BeanFactory getParentBeanFactory() 
 protected ResourcePatternResolver getResourcePatternResolver() 
    Return the ResourcePatternResolver to use for resolving location patterns into Resource instances. Default is a org.springframework.core.io.support.PathMatchingResourcePatternResolver , supporting Ant-style location patterns.

    Can be overridden in subclasses, for extended resolution strategies, for example in a web environment.

    Do not call this when needing to resolve a location pattern. Call the context's getResources method instead, which will delegate to the ResourcePatternResolver.

 public Resource[] getResources(String locationPattern) throws IOException 
 public long getStartupDate() 
    Return the timestamp (ms) when this context was first loaded.
 public Class getType(String name) throws NoSuchBeanDefinitionException 
 protected  void initApplicationEventMulticaster() 
    Initialize the ApplicationEventMulticaster. Uses SimpleApplicationEventMulticaster if none defined in the context.
 protected  void initMessageSource() 
    Initialize the MessageSource. Use parent's if none defined in this context.
 protected  void invokeBeanFactoryPostProcessors(ConfigurableListableBeanFactory beanFactory) 
    Instantiate and invoke all registered BeanFactoryPostProcessor beans, respecting explicit order if given.

    Must be called before singleton instantiation.

 public boolean isActive() 
 public boolean isPrototype(String name) throws NoSuchBeanDefinitionException 
 public boolean isRunning() 
 public boolean isSingleton(String name) throws NoSuchBeanDefinitionException 
 public boolean isTypeMatch(String name,
    Class targetType) throws NoSuchBeanDefinitionException 
 protected ConfigurableListableBeanFactory obtainFreshBeanFactory() 
    Tell the subclass to refresh the internal bean factory.
 protected  void onClose() 
    Template method which can be overridden to add context-specific shutdown work. The default implementation is empty.

    Called at the end of #doClose 's shutdown procedure, after this context's BeanFactory has been closed. If custom shutdown logic needs to execute while the BeanFactory is still active, override the #destroyBeans() method instead.

 protected  void onRefresh() throws BeansException 
    Template method which can be overridden to add context-specific refresh work. Called on initialization of special beans, before instantiation of singletons.

    This implementation is empty.

 protected  void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) 
    Modify the application context's internal bean factory after its standard initialization. All bean definitions will have been loaded, but no beans will have been instantiated yet. This allows for registering special BeanPostProcessors etc in certain ApplicationContext implementations.
 protected  void prepareBeanFactory(ConfigurableListableBeanFactory beanFactory) 
    Configure the factory's standard context characteristics, such as the context's ClassLoader and post-processors.
 protected  void prepareRefresh() 
    Prepare this context for refreshing, setting its startup date and active flag.
 public  void publishEvent(ApplicationEvent event) 
    Publish the given event to all listeners.

    Note: Listeners get initialized after the MessageSource, to be able to access it within listener implementations. Thus, MessageSource implementations cannot publish events.

 public  void refresh() throws IllegalStateException, BeansException 
 abstract protected  void refreshBeanFactory() throws IllegalStateException, BeansException
    Subclasses must implement this method to perform the actual configuration load. The method is invoked by #refresh() before any other initialization work.

    A subclass will either create a new bean factory and hold a reference to it, or return a single BeanFactory instance that it holds. In the latter case, it will usually throw an IllegalStateException if refreshing the context more than once.

 protected  void registerBeanPostProcessors(ConfigurableListableBeanFactory beanFactory) 
    Instantiate and invoke all registered BeanPostProcessor beans, respecting explicit order if given.

    Must be called before any instantiation of application beans.

 protected  void registerListeners() 
    Add beans that implement ApplicationListener as listeners. Doesn't affect other listeners, which can be added without being beans.
 public  void registerShutdownHook() 
    Register a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time.

    Delegates to doClose() for the actual closing procedure.

 public  void setDisplayName(String displayName) 
    Set a friendly name for this context. Typically done during initialization of concrete context implementations.
 public  void setId(String id) 
    Set the unique id of this application context.

    Default is the object id of the context instance, or the name of the context bean if the context is itself defined as a bean.

 public  void setParent(ApplicationContext parent) 
 public  void start() 
 public  void stop() 
 public String toString() 
    Return information about this context.