org.springframework.context.support
Class AbstractApplicationContext

java.lang.Object
  extended by org.springframework.core.io.DefaultResourceLoader
      extended by org.springframework.context.support.AbstractApplicationContext
All Implemented Interfaces:
BeanFactory, DisposableBean, HierarchicalBeanFactory, ListableBeanFactory, ApplicationContext, ApplicationEventPublisher, ConfigurableApplicationContext, MessageSource, ResourceLoader, ResourcePatternResolver
Direct Known Subclasses:
AbstractRefreshableApplicationContext, GenericApplicationContext

public abstract class AbstractApplicationContext
extends DefaultResourceLoader
implements ConfigurableApplicationContext, DisposableBean

Abstract implementation of the 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 MessageSource may also be supplied as a bean in the context, with the name "messageSource"; else, message resolution is delegated to the parent context. Furthermore, a multicaster for application events can be supplied as "applicationEventMulticaster" bean of type ApplicationEventMulticaster in the context; else, a default multicaster of type SimpleApplicationEventMulticaster will be used.

Implements resource loading through extending 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 DefaultResourceLoader.getResourceByPath(java.lang.String) method is overwritten in a subclass.

Since:
January 21, 2001
Author:
Rod Johnson, Juergen Hoeller
See Also:
refreshBeanFactory(), getBeanFactory(), BeanFactoryPostProcessor, BeanPostProcessor, ApplicationEventMulticaster, ApplicationListener, MessageSource

Field Summary
static String APPLICATION_EVENT_MULTICASTER_BEAN_NAME
          Name of the ApplicationEventMulticaster bean in the factory.
protected  Log logger
          Logger used by this class.
static String MESSAGE_SOURCE_BEAN_NAME
          Name of the MessageSource bean in the factory.
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.beans.factory.BeanFactory
FACTORY_BEAN_PREFIX
 
Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX, CLASSPATH_URL_PREFIX
 
Constructor Summary
AbstractApplicationContext()
          Create a new AbstractApplicationContext with no parent.
AbstractApplicationContext(ApplicationContext parent)
          Create a new AbstractApplicationContext with the given parent context.
 
Method Summary
 void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor)
          Add a new BeanFactoryPostProcessor that will get applied to the internal bean factory of this application context on refresh, before any of the bean definitions get evaluated.
protected  void addListener(ApplicationListener listener)
          Subclasses can invoke this method to register a listener.
 void close()
          Publishes a ContextClosedEvent and destroys the singletons in the bean factory of this application context.
 boolean containsBean(String name)
          Does this bean factory contain a bean with the given name?
 boolean containsBeanDefinition(String name)
          Check if this bean factory contains a bean definition with the given name.
 boolean containsLocalBean(String name)
          Return whether the local bean factory contains a bean of the given name, ignoring beans defined in ancestor contexts.
 void destroy()
          DisposableBean callback for destruction of this instance.
 String[] getAliases(String name)
          Return the aliases for the given bean name, if defined.
 Object getBean(String name)
          Return an instance, which may be shared or independent, of the specified bean.
 Object getBean(String name, Class requiredType)
          Return an instance, which may be shared or independent, of the specified bean.
 int getBeanDefinitionCount()
          Return the number of beans defined in the factory.
 String[] getBeanDefinitionNames()
          Return the names of all beans defined in this factory.
 String[] getBeanDefinitionNames(Class type)
          Return the names of beans matching the given type (including subclasses), judging from the bean definitions.
abstract  ConfigurableListableBeanFactory getBeanFactory()
          Subclasses must return their internal bean factory here.
 List getBeanFactoryPostProcessors()
          Return the list of BeanFactoryPostProcessors that will get applied to the internal BeanFactory.
 String[] getBeanNamesForType(Class type)
          Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.
 String[] getBeanNamesForType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
          Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.
 Map getBeansOfType(Class type)
          Return the bean instances that match the given object type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.
 Map getBeansOfType(Class type, boolean includePrototypes, boolean includeFactoryBeans)
          Return the bean instances that match the given object type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.
 String getDisplayName()
          Return a friendly name for this context.
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.
 String getMessage(MessageSourceResolvable resolvable, Locale locale)
          Try to resolve the message using all the attributes contained within the MessageSourceResolvable argument that was passed in.
 String getMessage(String code, Object[] args, Locale locale)
          Try to resolve the message.
 String getMessage(String code, Object[] args, String defaultMessage, Locale locale)
          Try to resolve the message.
 ApplicationContext getParent()
          Return the parent context, or null if there is no parent (that is, this context is the root of the context hierarchy).
 BeanFactory getParentBeanFactory()
          Return the parent bean factory, or null if there is none.
protected  ResourcePatternResolver getResourcePatternResolver()
          Return the ResourcePatternResolver to use for resolving location patterns into Resource instances.
 Resource[] getResources(String locationPattern)
          Resolve the given location pattern into Resource objects.
 long getStartupDate()
          Return the timestamp (ms) when this context was first loaded.
 Class getType(String name)
          Determine the type of the bean with the given name.
 boolean isSingleton(String name)
          Is this bean a shared singleton?
protected  void onRefresh()
          Template method which can be overridden to add context-specific refresh work.
protected  void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
          Modify the application context's internal bean factory after its standard initialization.
 void publishEvent(ApplicationEvent event)
          Publish the given event to all listeners.
 void refresh()
          Load or refresh the persistent representation of the configuration, which might an XML file, properties file, or relational database schema.
protected abstract  void refreshBeanFactory()
          Subclasses must implement this method to perform the actual configuration load.
 void setDisplayName(String displayName)
          Set a friendly name for this context.
 void setParent(ApplicationContext parent)
          Set the parent of this application context.
 String toString()
          Return information about this context.
 
Methods inherited from class org.springframework.core.io.DefaultResourceLoader
getClassLoader, getResource, getResourceByPath, setClassLoader
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.springframework.core.io.ResourceLoader
getResource
 

Field Detail

MESSAGE_SOURCE_BEAN_NAME

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.

See Also:
MessageSource, Constant Field Values

APPLICATION_EVENT_MULTICASTER_BEAN_NAME

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.

See Also:
ApplicationEventMulticaster, SimpleApplicationEventMulticaster, Constant Field Values

logger

protected final Log logger
Logger used by this class. Available to subclasses.

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 - the parent context
Method Detail

getParent

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).

Specified by:
getParent in interface ApplicationContext
Returns:
the parent context, or null if there is no parent

setDisplayName

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


getDisplayName

public String getDisplayName()
Return a friendly name for this context.

Specified by:
getDisplayName in interface ApplicationContext
Returns:
a display name for this context

getStartupDate

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

Specified by:
getStartupDate in interface ApplicationContext
Returns:
the timestamp (ms) when this context was first loaded

publishEvent

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.

Specified by:
publishEvent in interface ApplicationContext
Specified by:
publishEvent in interface ApplicationEventPublisher
Parameters:
event - the event to publish (may be application-specific or a standard framework event)
See Also:
RequestHandledEvent

setParent

public void setParent(ApplicationContext parent)
Description copied from interface: ConfigurableApplicationContext
Set the parent of this application context.

Note that the parent shouldn't be changed: It should only be set outside a constructor if it isn't available when an object of this class is created, for example in case of WebApplicationContext setup.

Specified by:
setParent in interface ConfigurableApplicationContext
Parameters:
parent - the parent context
See Also:
ConfigurableWebApplicationContext

addBeanFactoryPostProcessor

public void addBeanFactoryPostProcessor(BeanFactoryPostProcessor beanFactoryPostProcessor)
Description copied from interface: ConfigurableApplicationContext
Add a new BeanFactoryPostProcessor that will get applied to the internal bean factory of this application context on refresh, before any of the bean definitions get evaluated. To be invoked during context configuration.

Specified by:
addBeanFactoryPostProcessor in interface ConfigurableApplicationContext
Parameters:
beanFactoryPostProcessor - the factory processor to register

getBeanFactoryPostProcessors

public List getBeanFactoryPostProcessors()
Return the list of BeanFactoryPostProcessors that will get applied to the internal BeanFactory.

See Also:
BeanFactoryPostProcessor

refresh

public void refresh()
             throws BeansException,
                    IllegalStateException
Description copied from interface: ConfigurableApplicationContext
Load or refresh the persistent representation of the configuration, which might an XML file, properties file, or relational database schema.

Specified by:
refresh in interface ConfigurableApplicationContext
Throws:
BeansException - if the bean factory could not be initialized
IllegalStateException - if already initialized and multiple refresh attempts are not supported

getResourcePatternResolver

protected ResourcePatternResolver getResourcePatternResolver()
Return the ResourcePatternResolver to use for resolving location patterns into Resource instances. Default is 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.

See Also:
getResources(java.lang.String), PathMatchingResourcePatternResolver

postProcessBeanFactory

protected void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory)
                               throws BeansException
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.

Parameters:
beanFactory - the bean factory used by the application context
Throws:
BeansException - in case of errors

onRefresh

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.

Throws:
BeansException - in case of errors during refresh
See Also:
refresh()

addListener

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.

Parameters:
listener - the listener to register

close

public void close()
Publishes a ContextClosedEvent and destroys the singletons in the bean factory of this application context.

Specified by:
close in interface ConfigurableApplicationContext
See Also:
ContextClosedEvent

destroy

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.

Specified by:
destroy in interface DisposableBean
See Also:
close(), SingletonBeanFactoryLocator

getBean

public Object getBean(String name)
               throws BeansException
Description copied from interface: BeanFactory
Return an instance, which may be shared or independent, of the specified bean.

This method allows a Spring BeanFactory to be used as a replacement for the Singleton or Prototype design pattern. Callers may retain references to returned objects in the case of Singleton beans.

Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.

Specified by:
getBean in interface BeanFactory
Parameters:
name - the name of the bean to retrieve
Returns:
an instance of the bean
Throws:
NoSuchBeanDefinitionException - if there is no bean definition with the specified name
BeansException - if the bean could not be obtained

getBean

public Object getBean(String name,
                      Class requiredType)
               throws BeansException
Description copied from interface: BeanFactory
Return an instance, which may be shared or independent, of the specified bean.

Behaves the same as BeanFactory.getBean(String), but provides a measure of type safety by throwing a BeanNotOfRequiredTypeException if the bean is not of the required type. This means that ClassCastException can't be thrown on casting the result correctly, as can happen with BeanFactory.getBean(String).

Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.

Specified by:
getBean in interface BeanFactory
Parameters:
name - the name of the bean to retrieve
requiredType - type the bean must match. Can be an interface or superclass of the actual class, or null for any match. For example, if the value is Object.class, this method will succeed whatever the class of the returned instance.
Returns:
an instance of the bean
Throws:
BeanNotOfRequiredTypeException - if the bean is not of the required type
NoSuchBeanDefinitionException - if there's no such bean definition
BeansException - if the bean could not be created

containsBean

public boolean containsBean(String name)
Description copied from interface: BeanFactory
Does this bean factory contain a bean with the given name?

Will ask the parent factory if the bean cannot be found in this factory instance.

Specified by:
containsBean in interface BeanFactory
Parameters:
name - the name of the bean to query
Returns:
whether a bean with the given name is defined

isSingleton

public boolean isSingleton(String name)
                    throws NoSuchBeanDefinitionException
Description copied from interface: BeanFactory
Is this bean a shared singleton? That is, will BeanFactory.getBean(java.lang.String) always return the same instance?

Will ask the parent factory if the bean cannot be found in this factory instance.

Specified by:
isSingleton in interface BeanFactory
Parameters:
name - the name of the bean to query
Returns:
whether this bean corresponds to a singleton instance
Throws:
NoSuchBeanDefinitionException - if there is no bean with the given name
See Also:
BeanFactory.getBean(java.lang.String)

getType

public Class getType(String name)
              throws NoSuchBeanDefinitionException
Description copied from interface: BeanFactory
Determine the type of the bean with the given name. More specifically, check the type of object that BeanFactory.getBean(java.lang.String) would return. For a FactoryBean, return the type of object that the FactoryBean creates.

Specified by:
getType in interface BeanFactory
Parameters:
name - the name of the bean to query
Returns:
the type of the bean, or null if not determinable
Throws:
NoSuchBeanDefinitionException - if there is no bean with the given name
See Also:
BeanFactory.getBean(java.lang.String), FactoryBean.getObjectType()

getAliases

public String[] getAliases(String name)
                    throws NoSuchBeanDefinitionException
Description copied from interface: BeanFactory
Return the aliases for the given bean name, if defined.

Will ask the parent factory if the bean cannot be found in this factory instance.

Specified by:
getAliases in interface BeanFactory
Parameters:
name - the bean name to check for aliases
Returns:
the aliases, or an empty array if none
Throws:
NoSuchBeanDefinitionException - if there is no bean definition with the specified name

containsBeanDefinition

public boolean containsBeanDefinition(String name)
Description copied from interface: ListableBeanFactory
Check if this bean factory contains a bean definition with the given name.

Does not consider any hierarchy this factory may participate in. Use containsBean to check ancestor factories too.

Note: Ignores any singleton beans that have been registered by other means than bean definitions.

Specified by:
containsBeanDefinition in interface ListableBeanFactory
Parameters:
name - the name of the bean to look for
Returns:
if this bean factory contains a bean definition with the given name
See Also:
BeanFactory.containsBean(java.lang.String)

getBeanDefinitionCount

public int getBeanDefinitionCount()
Description copied from interface: ListableBeanFactory
Return the number of beans defined in the factory.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' countBeansIncludingAncestors to include beans in ancestor factories too.

Note: Ignores any singleton beans that have been registered by other means than bean definitions.

Specified by:
getBeanDefinitionCount in interface ListableBeanFactory
Returns:
the number of beans defined in the factory
See Also:
BeanFactoryUtils.countBeansIncludingAncestors(org.springframework.beans.factory.ListableBeanFactory)

getBeanDefinitionNames

public String[] getBeanDefinitionNames()
Description copied from interface: ListableBeanFactory
Return the names of all beans defined in this factory.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beanNamesIncludingAncestors to include beans in ancestor factories too.

Note: Ignores any singleton beans that have been registered by other means than bean definitions.

Specified by:
getBeanDefinitionNames in interface ListableBeanFactory
Returns:
the names of all beans defined in this factory, or an empty array if none defined
See Also:
BeanFactoryUtils.beanNamesIncludingAncestors(ListableBeanFactory)

getBeanDefinitionNames

public String[] getBeanDefinitionNames(Class type)
Description copied from interface: ListableBeanFactory
Return the names of beans matching the given type (including subclasses), judging from the bean definitions. Merges child bean definition with their parent before checking the type.

Does not consider objects created by FactoryBeans but rather the FactoryBean classes themselves, avoiding instantiation of any beans. Use getBeanNamesForType to match objects created by FactoryBeans.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beanNamesIncludingAncestors to include beans in ancestor factories too.

Note: Ignores any singleton beans that have been registered by other means than bean definitions.

Specified by:
getBeanDefinitionNames in interface ListableBeanFactory
Parameters:
type - the class or interface to match, or null for all bean names
Returns:
the names of beans matching the given object type (including subclasses), or an empty array if none
See Also:
ListableBeanFactory.getBeanNamesForType(java.lang.Class), BeanFactoryUtils.beanNamesIncludingAncestors(ListableBeanFactory, Class)

getBeanNamesForType

public String[] getBeanNamesForType(Class type)
Description copied from interface: ListableBeanFactory
Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Does consider objects created by FactoryBeans, which means that FactoryBeans will get initialized. If the object created by the FactoryBean doesn't match, the raw FactoryBean itself will be matched against the type.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beanNamesForTypeIncludingAncestors to include beans in ancestor factories too.

Note: Does not ignore singleton beans that have been registered by other means than bean definitions.

This version of getBeanNamesForType matches all kinds of beans, be it singletons, prototypes, or FactoryBeans. In most implementations, the result will be the same as for getBeanNamesOfType(type, true, true).

Bean names returned by this method should always return bean names in the order of definition in the backend configuration, as far as possible.

Specified by:
getBeanNamesForType in interface ListableBeanFactory
Parameters:
type - the class or interface to match, or null for all bean names
Returns:
the names of beans (or objects created by FactoryBeans) matching the given object type (including subclasses), or an empty array if none
See Also:
FactoryBean.getObjectType(), BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class)

getBeanNamesForType

public String[] getBeanNamesForType(Class type,
                                    boolean includePrototypes,
                                    boolean includeFactoryBeans)
Description copied from interface: ListableBeanFactory
Return the names of beans matching the given type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Does consider objects created by FactoryBeans if the "includeFactoryBeans" flag is set, which means that FactoryBeans will get initialized. If the object created by the FactoryBean doesn't match, the raw FactoryBean itself will be matched against the type. If "includeFactoryBeans" is not set, only raw FactoryBeans will be checked (which doesn't require initialization of each FactoryBean). $ *

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beanNamesForTypeIncludingAncestors to include beans in ancestor factories too.

Note: Does not ignore singleton beans that have been registered by other means than bean definitions.

Bean names returned by this method should always return bean names in the order of definition in the backend configuration, as far as possible.

Specified by:
getBeanNamesForType in interface ListableBeanFactory
Parameters:
type - the class or interface to match, or null for all bean names
includePrototypes - whether to include prototype beans too or just singletons (also applies to FactoryBeans)
includeFactoryBeans - whether to include objects created by FactoryBeans (or by factory methods with a "factory-bean" reference) too, or just conventional beans. Note that FactoryBeans need to be initialized to determine their type: So be aware that passing in "true" for this flag will initialize FactoryBeans (and "factory-bean" references).
Returns:
the names of beans (or objects created by FactoryBeans) matching the given object type (including subclasses), or an empty array if none
See Also:
FactoryBean.getObjectType(), BeanFactoryUtils.beanNamesForTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)

getBeansOfType

public Map getBeansOfType(Class type)
                   throws BeansException
Description copied from interface: ListableBeanFactory
Return the bean instances that match the given object type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Does consider objects created by FactoryBeans, which means that FactoryBeans will get initialized. If the object created by the FactoryBean doesn't match, the raw FactoryBean itself will be matched against the type.

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beansOfTypeIncludingAncestors to include beans in ancestor factories too.

Note: Does not ignore singleton beans that have been registered by other means than bean definitions.

This version of getBeansOfType matches all kinds of beans, be it singletons, prototypes, or FactoryBeans. In most implementations, the result will be the same as for getBeansOfType(type, true, true).

The Map returned by this method should always return bean names and corresponding bean instances in the order of definition in the backend configuration, as far as possible. This will usually mean that either JDK 1.4 or Commons Collections needs to be available.

Specified by:
getBeansOfType in interface ListableBeanFactory
Parameters:
type - the class or interface to match, or null for all concrete beans
Returns:
a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
Throws:
BeansException - if a bean could not be created
See Also:
FactoryBean.getObjectType(), BeanFactoryUtils.beansOfTypeIncludingAncestors(ListableBeanFactory, Class)

getBeansOfType

public Map getBeansOfType(Class type,
                          boolean includePrototypes,
                          boolean includeFactoryBeans)
                   throws BeansException
Description copied from interface: ListableBeanFactory
Return the bean instances that match the given object type (including subclasses), judging from either bean definitions or the value of getObjectType in the case of FactoryBeans.

Does consider objects created by FactoryBeans if the "includeFactoryBeans" flag is set, which means that FactoryBeans will get initialized. If the object created by the FactoryBean doesn't match, the raw FactoryBean itself will be matched against the type. If "includeFactoryBeans" is not set, only raw FactoryBeans will be checked (which doesn't require initialization of each FactoryBean).

Does not consider any hierarchy this factory may participate in. Use BeanFactoryUtils' beansOfTypeIncludingAncestors to include beans in ancestor factories too.

Note: Does not ignore singleton beans that have been registered by other means than bean definitions.

The Map returned by this method should always return bean names and corresponding bean instances in the order of definition in the backend configuration, as far as possible. This will usually mean that either JDK 1.4 or Commons Collections needs to be available.

Specified by:
getBeansOfType in interface ListableBeanFactory
Parameters:
type - the class or interface to match, or null for all concrete beans
includePrototypes - whether to include prototype beans too or just singletons (also applies to FactoryBeans)
includeFactoryBeans - whether to include objects created by FactoryBeans (or by factory methods with a "factory-bean" reference) too, or just conventional beans. Note that FactoryBeans need to be initialized to determine their type: So be aware that passing in "true" for this flag will initialize FactoryBeans (and "factory-bean" references).
Returns:
a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
Throws:
BeansException - if a bean could not be created
See Also:
FactoryBean.getObjectType(), BeanFactoryUtils.beansOfTypeIncludingAncestors(ListableBeanFactory, Class, boolean, boolean)

getParentBeanFactory

public BeanFactory getParentBeanFactory()
Description copied from interface: HierarchicalBeanFactory
Return the parent bean factory, or null if there is none.

Specified by:
getParentBeanFactory in interface HierarchicalBeanFactory

containsLocalBean

public boolean containsLocalBean(String name)
Description copied from interface: HierarchicalBeanFactory
Return whether the local bean factory contains a bean of the given name, ignoring beans defined in ancestor contexts.

This is an alternative to containsBean, ignoring a bean of the given name from an ancestor bean factory.

Specified by:
containsLocalBean in interface HierarchicalBeanFactory
Parameters:
name - the name of the bean to query
Returns:
whether a bean with the given name is defined in the local factory
See Also:
BeanFactory.containsBean(java.lang.String)

getInternalParentBeanFactory

protected BeanFactory getInternalParentBeanFactory()
Return the internal bean factory of the parent context if it implements ConfigurableApplicationContext; else, return the parent context itself.

See Also:
ConfigurableApplicationContext.getBeanFactory()

getMessage

public String getMessage(String code,
                         Object[] args,
                         String defaultMessage,
                         Locale locale)
Description copied from interface: MessageSource
Try to resolve the message. Return default message if no message was found.

Specified by:
getMessage in interface MessageSource
Parameters:
code - the code to lookup up, such as 'calculator.noRateSet'. Users of this class are encouraged to base message names on the relevant fully qualified class name, thus avoiding conflict and ensuring maximum clarity.
args - array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}" within a message), or null if none.
defaultMessage - String to return if the lookup fails
locale - the Locale in which to do the lookup
Returns:
the resolved message if the lookup was successful; otherwise the default message passed as a parameter
See Also:
java.text.MessageFormat

getMessage

public String getMessage(String code,
                         Object[] args,
                         Locale locale)
                  throws NoSuchMessageException
Description copied from interface: MessageSource
Try to resolve the message. Treat as an error if the message can't be found.

Specified by:
getMessage in interface MessageSource
Parameters:
code - the code to lookup up, such as 'calculator.noRateSet'
args - Array of arguments that will be filled in for params within the message (params look like "{0}", "{1,date}", "{2,time}" within a message), or null if none.
locale - the Locale in which to do the lookup
Returns:
the resolved message
Throws:
NoSuchMessageException - if the message wasn't found
See Also:
java.text.MessageFormat

getMessage

public String getMessage(MessageSourceResolvable resolvable,
                         Locale locale)
                  throws NoSuchMessageException
Description copied from interface: MessageSource
Try to resolve the message using all the attributes contained within the MessageSourceResolvable argument that was passed in.

NOTE: We must throw a NoSuchMessageException on this method since at the time of calling this method we aren't able to determine if the defaultMessage property of the resolvable is null or not.

Specified by:
getMessage in interface MessageSource
Parameters:
resolvable - value object storing attributes required to properly resolve a message
locale - the Locale in which to do the lookup
Returns:
the resolved message
Throws:
NoSuchMessageException - if the message wasn't found
See Also:
java.text.MessageFormat

getInternalParentMessageSource

protected MessageSource getInternalParentMessageSource()
Return the internal message source of the parent context if it is an AbstractApplicationContext too; else, return the parent context itself.


getResources

public Resource[] getResources(String locationPattern)
                        throws IOException
Description copied from interface: ResourcePatternResolver
Resolve the given location pattern into Resource objects.

Overlapping resource entries that point to the same physical resource should be avoided, as far as possible. The result should have set semantics.

Specified by:
getResources in interface ResourcePatternResolver
Parameters:
locationPattern - the location pattern to resolve
Returns:
the corresponding Resource objects
Throws:
IOException - in case of I/O errors

refreshBeanFactory

protected abstract void refreshBeanFactory()
                                    throws BeansException,
                                           IllegalStateException
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.

Throws:
BeansException - if initialization of the bean factory failed
IllegalStateException - if already initialized and multiple refresh attempts are not supported

getBeanFactory

public abstract 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.

Specified by:
getBeanFactory in interface ConfigurableApplicationContext
Returns:
this application context's internal bean factory (never null)
Throws:
IllegalStateException - if the context does not hold an internal bean factory yet (usually if refresh() has never been called) or if the context has been closed already
See Also:
refreshBeanFactory()

toString

public String toString()
Return information about this context.

Overrides:
toString in class Object


Copyright (c) 2002-2007 The Spring Framework Project.