org.springframework.context.support
Class AbstractApplicationContext

Direct Known Subclasses:
AbstractXmlApplicationContext, StaticApplicationContext

public abstract class AbstractApplicationContext
implements ConfigurableApplicationContext

Partial implementation of ApplicationContext. Doesn't mandate the type of storage used for configuration, but implements common functionality.

This class uses the Template Method design pattern, requiring concrete subclasses to implement protected abstract methods.

A message source may be supplied as a bean in the default bean factory, with the name "messageSource". Else, message resolution is delegated to the parent context.

Author:
Rod Johnson, Juergen Hoeller
Version: $Revision: 1.29 $
Since: January 21, 2001
See Also: refreshBeanFactory(), getBeanFactory(), MESSAGE_SOURCE_BEAN_NAME

Field Summary
 final static StringMESSAGE_SOURCE_BEAN_NAME
          Name of the MessageSource bean in the factory.

Constructor Summary
AbstractApplicationContext()
          Create a new AbstractApplicationContext with no parent.
AbstractApplicationContext(ApplicationContext parent)
          Create a new AbstractApplicationContext with the given parent context.

Method Summary
 voidclose()
          Destroy the singletons in the bean factory of this application context.
 booleancontainsBean(String name)
           
 booleancontainsBeanDefinition(String name)
           
 String[]getAliases(String name)
           
 ObjectgetBean(String name)
           
 ObjectgetBean(String name, Class requiredType)
           
 intgetBeanDefinitionCount()
           
 String[]getBeanDefinitionNames()
           
 String[]getBeanDefinitionNames(Class type)
           
 abstract ConfigurableListableBeanFactorygetBeanFactory()
          Subclasses must return their internal bean factory here.
 MapgetBeansOfType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
           
 StringgetDisplayName()
          Return a friendly name for context
 StringgetMessage(String code, Object[] args, String defaultMessage, Locale locale)
           
 StringgetMessage(String code, Object[] args, Locale locale)
           
 StringgetMessage(MessageSourceResolvable resolvable, Locale locale)
           
 ApplicationContextgetParent()
          Return the parent context, or null if there is no parent, and this is the root of the context hierarchy.
 BeanFactorygetParentBeanFactory()
           
 ResourcegetResource(String location)
          This implementation supports fully qualified URLs, including the "classpath:" pseudo-URL, and context-specific file paths via getResourceByPath.
 longgetStartupDate()
          Return the timestamp when this context was first loaded
 booleanisSingleton(String name)
           
 voidpublishEvent(ApplicationEvent event)
          Publish the given event to all listeners.
 voidrefresh()
          Load or reload configuration.
 voidsetParent(ApplicationContext parent)
           
 StringtoString()
          Show information about this context

Field Detail

MESSAGE_SOURCE_BEAN_NAME

public final static String MESSAGE_SOURCE_BEAN_NAME
Name of the MessageSource bean in the factory. If none is supplied, message resolution is delegated to the parent.
See Also:
MessageSource
Constructor Detail

AbstractApplicationContext

public AbstractApplicationContext()
Create a new AbstractApplicationContext with no parent.

AbstractApplicationContext

public AbstractApplicationContext(ApplicationContext parent)
Create a new AbstractApplicationContext with the given parent context.
Parameters:
parent - parent context
Method Detail

close

public void close()
Destroy the singletons in the bean factory of this application context.

containsBean

public boolean containsBean(String name)

containsBeanDefinition

public boolean containsBeanDefinition(String name)

getAliases

public String[] getAliases(String name)
throws org.springframework.beans.factory.NoSuchBeanDefinitionException

getBean

public Object getBean(String name)
throws org.springframework.beans.BeansException

getBean

public Object getBean(String name, Class requiredType)
throws org.springframework.beans.BeansException

getBeanDefinitionCount

public int getBeanDefinitionCount()

getBeanDefinitionNames

public String[] getBeanDefinitionNames()

getBeanDefinitionNames

public String[] getBeanDefinitionNames(Class type)

getBeanFactory

public abstract ConfigurableListableBeanFactory getBeanFactory()
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.
Returns: this application context's internal bean factory

getBeansOfType

public Map getBeansOfType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
throws org.springframework.beans.BeansException

getDisplayName

public String getDisplayName()
Return a friendly name for context
Returns: a display name for the context

getMessage

public String getMessage(String code, Object[] args, String defaultMessage, Locale locale)

getMessage

public String getMessage(String code, Object[] args, Locale locale)
throws org.springframework.context.NoSuchMessageException

getMessage

public String getMessage(MessageSourceResolvable resolvable, Locale locale)
throws org.springframework.context.NoSuchMessageException

getParent

public ApplicationContext getParent()
Return the parent context, or null if there is no parent, and this is the root of the context hierarchy.
Returns: the parent context, or null if there is no parent

getParentBeanFactory

public BeanFactory getParentBeanFactory()

getResource

public Resource getResource(String location)
This implementation supports fully qualified URLs, including the "classpath:" pseudo-URL, and context-specific file paths via getResourceByPath. Throws a FileNotFoundException if getResourceByPath returns null.
See Also:
getResourceByPath(java.lang.String), org.springframework.core.io.ResourceEditor.CLASSPATH_URL_PREFIX

getStartupDate

public long getStartupDate()
Return the timestamp when this context was first loaded
Returns: the timestamp (ms) when this context was first loaded

isSingleton

public boolean isSingleton(String name)
throws org.springframework.beans.factory.NoSuchBeanDefinitionException

publishEvent

public void publishEvent(ApplicationEvent event)
Publish the given event to all listeners.

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

Parameters:
event - event to publish. The event may be application-specific, or a standard framework event.

refresh

public void refresh()
throws org.springframework.beans.BeansException
Load or reload configuration.
Throws:
org.springframework.context.ApplicationContextException - if the configuration was invalid or couldn't be found, or if configuration has already been loaded and reloading is forbidden
BeansException - if the bean factory could not be initialized

setParent

public void setParent(ApplicationContext parent)

toString

public String toString()
Show information about this context

Association Links

to Class java.lang.String

Name of the MessageSource bean in the factory. If none is supplied, message resolution is delegated to the parent.

see MessageSource

to Class org.springframework.context.ApplicationContext

Parent context

to Class java.lang.String

Display name

to Class org.springframework.context.MessageSource

MessageSource helper we delegate our implementation of this interface to

to Class org.springframework.context.event.ApplicationEventMulticaster

Helper class used in event publishing. TODO: This could be parameterized as a JavaBean (with a distinguished name specified), enabling a different thread usage policy for event publication.