com.interface21.beans.factory.support
Class StaticListableBeanFactory

java.lang.Object
  |
  +--com.interface21.beans.factory.support.StaticListableBeanFactory
All Implemented Interfaces:
BeanFactory, ListableBeanFactory

public class StaticListableBeanFactory
extends java.lang.Object
implements ListableBeanFactory

Singleton only. Allows beans to be registered by name programmatically. Mainly useful for testing.

Since:
06-Jan-03
Author:
Rod Johnson

Constructor Summary
StaticListableBeanFactory()
           
 
Method Summary
 void addBean(java.lang.String name, java.lang.Object bean)
          Add a new singleton bean
 java.lang.String[] getAliases(java.lang.String name)
          Return the aliases for the given bean name, if defined.
 java.lang.Object getBean(java.lang.String name)
          Return an instance (possibly shared or independent) of the given bean name.
 java.lang.Object getBean(java.lang.String name, java.lang.Class requiredType)
          Return an instance (possibly shared or independent) of the given bean 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 object type (including subclasses).
 boolean isSingleton(java.lang.String name)
          Is this bean a singleton?
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StaticListableBeanFactory

public StaticListableBeanFactory()
Method Detail

getBeanDefinitionCount

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

getBeanDefinitionNames

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

getBeanDefinitionNames

public java.lang.String[] getBeanDefinitionNames(java.lang.Class type)
Description copied from interface: ListableBeanFactory
Return the names of beans matching the given object type (including subclasses).
Specified by:
getBeanDefinitionNames in interface ListableBeanFactory
See Also:
ListableBeanFactory.getBeanDefinitionNames(Class)

getBean

public java.lang.Object getBean(java.lang.String name,
                                java.lang.Class requiredType)
                         throws BeansException
Description copied from interface: BeanFactory
Return an instance (possibly shared or independent) of the given bean name. Provides a measure of type safety by throwing an exception if the bean is not of the required type. This method allows a bean factory to be used as a replacement for the Singleton or Prototype design pattern.
Note that callers should retain references to returned objects. There is no guarantee that this method will be implemented to be efficient. For example, it may be synchronized, or may need to run an RDBMS query.
Specified by:
getBean in interface BeanFactory
See Also:
BeanFactory.getBean(String, Class)

getBean

public java.lang.Object getBean(java.lang.String name)
                         throws BeansException
Description copied from interface: BeanFactory
Return an instance (possibly shared or independent) of the given bean name. This method allows a bean factory to be used as a replacement for the Singleton or Prototype design pattern.
Note that callers should retain references to returned objects. There is no guarantee that this method will be implemented to be efficient. For example, it may be synchronized, or may need to run an RDBMS query.
Specified by:
getBean in interface BeanFactory
See Also:
BeanFactory.getBean(String)

addBean

public void addBean(java.lang.String name,
                    java.lang.Object bean)
Add a new singleton bean

isSingleton

public boolean isSingleton(java.lang.String name)
Description copied from interface: BeanFactory
Is this bean a singleton? That is, will getBean() always return the same object?
Specified by:
isSingleton in interface BeanFactory
See Also:
BeanFactory.isSingleton(java.lang.String)

getAliases

public java.lang.String[] getAliases(java.lang.String name)
Description copied from interface: BeanFactory
Return the aliases for the given bean name, if defined.
Specified by:
getAliases in interface BeanFactory
Following copied from interface: com.interface21.beans.factory.BeanFactory
Parameters:
name - the bean name to check for aliases
Returns:
the aliases, or an empty array if none


Rod Johnson and Spring contributors 2001-2003.