org.springframework.beans.factory
Interface ListableBeanFactory

All Superinterfaces:
BeanFactory
All Known Subinterfaces:
ApplicationContext, ConfigurableApplicationContext, ConfigurableListableBeanFactory, ConfigurableWebApplicationContext, WebApplicationContext
All Known Implementing Classes:
AbstractApplicationContext, DefaultListableBeanFactory, StaticListableBeanFactory, StaticWebApplicationContext, XmlWebApplicationContext

public interface ListableBeanFactory
extends BeanFactory

Extension of the BeanFactory interface to be implemented by bean factories that can enumerate all their bean instances, rather than attempting bean lookup by name one by one as requested by clients. BeanFactory implementations that preload all their beans (for example, DOM-based XML factories) may implement this interface. This interface is discussed in "Expert One-on-One J2EE Design and Development", by Rod Johnson.

If this is a HierarchicalBeanFactory, the return values will not take any BeanFactory hierarchy into account, but will relate only to the beans defined in the current factory. Use the BeanFactoryUtils helper class to get all beans.

The methods in this interface will just respect bean definitions of this factory. They will ignore any singleton beans that have been registered by other means like ConfigurableBeanFactory's registerSingleton. Use BeanFactory's methods to access such beans. In typical scenarios, all beans will be defined by bean definitions anyway.

With the exception of getBeanDefinitionCount(), the methods in this interface are not designed for frequent invocation. Implementations may be slow.

Since:
16 April 2001
Version:
$Id: ListableBeanFactory.java,v 1.9 2004/03/18 02:46:07 trisberg Exp $
Author:
Rod Johnson
See Also:
BeanFactoryUtils, ConfigurableBeanFactory.registerSingleton(java.lang.String, java.lang.Object)

Method Summary
 boolean containsBeanDefinition(java.lang.String name)
          Check if this bean factory contains a bean definition with the given name.
 int getBeanDefinitionCount()
          Return the number of beans defined in the factory.
 java.lang.String[] getBeanDefinitionNames()
          Return the names of all beans defined in this factory.
 java.lang.String[] getBeanDefinitionNames(java.lang.Class type)
          Return the names of beans matching the given type (including subclasses), judging from the bean definitions.
 java.util.Map getBeansOfType(java.lang.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.
 
Methods inherited from interface org.springframework.beans.factory.BeanFactory
containsBean, getAliases, getBean, getBean, isSingleton
 

Method Detail

getBeanDefinitionCount

public int getBeanDefinitionCount()
Return the number of beans defined in the factory. Does not consider any hierarchy this factory may participate in.

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

Returns:
the number of beans defined in the factory

getBeanDefinitionNames

public java.lang.String[] getBeanDefinitionNames()
Return the names of all beans defined in this factory. Does not consider any hierarchy this factory may participate in.

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

Returns:
the names of all beans defined in this factory, or an empty array if none defined

getBeanDefinitionNames

public java.lang.String[] getBeanDefinitionNames(java.lang.Class type)
Return the names of beans matching the given type (including subclasses), judging from the bean definitions. Will not consider FactoryBeans, as the type of their created objects is not known before instantiation. Does not consider any hierarchy this factory may participate in.

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

Parameters:
type - 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

containsBeanDefinition

public boolean containsBeanDefinition(java.lang.String name)
Check if this bean factory contains a bean definition with the given name. Does not consider any hierarchy this factory may participate in.

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

Parameters:
name - the name of the bean to look for
Returns:
if this bean factory contains a bean definition with the given name

getBeansOfType

public java.util.Map getBeansOfType(java.lang.Class type,
                                    boolean includePrototypes,
                                    boolean includeFactoryBeans)
                             throws BeansException
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 not consider any hierarchy this factory may participate in.

If FactoryBean's getObjectType() returns null and the bean is a singleton, the type of the actually created objects should be evaluated. Prototypes without explicit object type specification should be ignored.

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

Parameters:
type - class or interface to match
includePrototypes - whether to include prototype beans too or just singletons (also applies to FactoryBeans)
includeFactoryBeans - whether to include FactoryBeans too or just normal beans
Returns:
a Map with the matching beans, containing the bean names as keys and the corresponding bean instances as values
Throws:
BeansException - if the beans could not be created


Copyright (C) 2003-2004 The Spring Framework Project.