com.interface21.beans.factory.support
Class ListableBeanFactoryImpl

java.lang.Object
  |
  +--com.interface21.beans.factory.support.AbstractBeanFactory
        |
        +--com.interface21.beans.factory.support.ListableBeanFactoryImpl
All Implemented Interfaces:
BeanFactory, ListableBeanFactory
Direct Known Subclasses:
JndiEnvironmentBeanFactory, XmlBeanFactory

public class ListableBeanFactoryImpl
extends AbstractBeanFactory
implements ListableBeanFactory

Concrete implementation of ListableBeanFactory. Includes convenient methods to populate the factory from a Map and a ResourceBundle, and to add bean defintions one by one.

Can be used as a standalone bean factory, or as a superclass for custom bean factories.

Since:
16 April 2001
Version:
$Id: ListableBeanFactoryImpl.java,v 1.8 2003/06/20 20:28:43 jhoeller Exp $
Author:
Rod Johnson

Field Summary
static java.lang.String CLASS_KEY
          Prefix for the class property of a root bean definition.
static java.lang.String DEFAULT_PREFIX
          Prefix for bean definition keys in Maps.
static java.lang.String PARENT_KEY
          Reserved "property" to indicate the parent of a child bean definition.
static java.lang.String REF_PREFIX
          Prefix before values referencing other beans
static java.lang.String REF_SUFFIX
          Property suffix for references to other beans in the current BeanFactory: e.g. owner.dog(ref)=fido.
static java.lang.String SEPARATOR
          Separator between bean name and property name.
static java.lang.String SINGLETON_KEY
          Special string added to distinguish owner.(singleton)=true Default is true.
 
Fields inherited from class com.interface21.beans.factory.support.AbstractBeanFactory
defaultParentBean, FACTORY_BEAN_PREFIX, logger
 
Constructor Summary
ListableBeanFactoryImpl()
          Creates a new ListableBeanFactoryImpl
ListableBeanFactoryImpl(BeanFactory parentBeanFactory)
          Creates a new ListableBeanFactoryImpl with the given parent
 
Method Summary
protected  AbstractBeanDefinition getBeanDefinition(java.lang.String prototypeName)
          This method must be defined by concrete subclasses to implement the Template Method GoF design pattern.
 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)
          Note that this method is slow.
 java.lang.String getDefaultParentBean()
          Return the default parent bean for this bean factory.
 void preInstantiateSingletons()
          Ensure that even potentially unreferenced singletons are instantiated Subclasses or callers should invoke this if they want this behavior.
 void registerBeanDefinition(java.lang.String prototypeName, AbstractBeanDefinition beanDefinition)
          Subclasses or users should call this method to register new bean definitions with this class.
 int registerBeanDefinitions(java.util.Map m, java.lang.String prefix)
          Register valid bean definitions in a properties file.
 int registerBeanDefinitions(java.util.ResourceBundle rb, java.lang.String prefix)
          Register bean definitions in a ResourceBundle.
 void setDefaultParentBean(java.lang.String defaultParentBean)
          Set the default parent bean for this bean factory.
 java.lang.String toString()
           
 
Methods inherited from class com.interface21.beans.factory.support.AbstractBeanFactory
getAliases, getBean, getBean, getBeanClass, getParentBeanFactory, isSingleton, registerAlias
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.interface21.beans.factory.BeanFactory
getAliases, getBean, getBean, isSingleton
 

Field Detail

DEFAULT_PREFIX

public static final java.lang.String DEFAULT_PREFIX
Prefix for bean definition keys in Maps.

CLASS_KEY

public static final java.lang.String CLASS_KEY
Prefix for the class property of a root bean definition.

SINGLETON_KEY

public static final java.lang.String SINGLETON_KEY
Special string added to distinguish owner.(singleton)=true Default is true.

PARENT_KEY

public static final java.lang.String PARENT_KEY
Reserved "property" to indicate the parent of a child bean definition.

SEPARATOR

public static final java.lang.String SEPARATOR
Separator between bean name and property name. We follow normal Java conventions.

REF_SUFFIX

public static final java.lang.String REF_SUFFIX
Property suffix for references to other beans in the current BeanFactory: e.g. owner.dog(ref)=fido. Whether this is a reference to a singleton or a prototype will depend on the definition of the target bean.

REF_PREFIX

public static final java.lang.String REF_PREFIX
Prefix before values referencing other beans
Constructor Detail

ListableBeanFactoryImpl

public ListableBeanFactoryImpl()
Creates a new ListableBeanFactoryImpl

ListableBeanFactoryImpl

public ListableBeanFactoryImpl(BeanFactory parentBeanFactory)
Creates a new ListableBeanFactoryImpl with the given parent
Method Detail

setDefaultParentBean

public void setDefaultParentBean(java.lang.String defaultParentBean)
Set the default parent bean for this bean factory. If a child bean definition (i.e. a definition without class attribute) handled by this factory doesn't provide a parent attribute, this default value gets used.

Can be used e.g. for view definition files, to define a parent with common attributes for all views.


getDefaultParentBean

public java.lang.String getDefaultParentBean()
Return the default parent bean for this bean factory.

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 final 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 final java.lang.String[] getBeanDefinitionNames(java.lang.Class type)
Note that this method is slow. Don't invoke it too often: it's best used only in application initialization.
Specified by:
getBeanDefinitionNames in interface ListableBeanFactory
Following copied from interface: com.interface21.beans.factory.ListableBeanFactory
Parameters:
type - class or interface to match
Returns:
the names of beans matching the given object type (including subclasses). Never returns null.

registerBeanDefinition

public final void registerBeanDefinition(java.lang.String prototypeName,
                                         AbstractBeanDefinition beanDefinition)
                                  throws BeansException
Subclasses or users should call this method to register new bean definitions with this class. All other registration methods in this class use this method.
This method isn't guaranteed to be threadsafe. It should be called before any bean instances are accessed.
Parameters:
prototypeName - name of the bean instance to register
beanDefinition - definition of the bean instance to register

preInstantiateSingletons

public void preInstantiateSingletons()
Ensure that even potentially unreferenced singletons are instantiated Subclasses or callers should invoke this if they want this behavior.

registerBeanDefinitions

public final int registerBeanDefinitions(java.util.Map m,
                                         java.lang.String prefix)
                                  throws BeansException
Register valid bean definitions in a properties file. Ignore ineligible properties
Parameters:
m - Map name -> property (String or Object). Property values will be strings if coming from a Properties file etc. Property names (keys) must be strings. Class keys must be Strings. employee.class=MyClass // special property //employee.abstract=true // this prototype can't be instantiated directly employee.group=Insurance Services // real property employee.usesDialUp=false // default unless overriden employee.manager(ref)=tony // reference to another prototype defined in the same file // cyclic and unresolved references will be detected salesrep.parent=employee salesrep.department=Sales and Marketing techie.parent=employee techie.department=Software Engineering techie.usesDialUp=true // overridden property
prefix - The match or filter within the keys in the map: e.g. 'beans.'
Returns:
the number of bean definitions found
Throws:
BeansException - if there is an error trying to register a definition

registerBeanDefinitions

public final int registerBeanDefinitions(java.util.ResourceBundle rb,
                                         java.lang.String prefix)
                                  throws BeansException
Register bean definitions in a ResourceBundle. Similar syntax as for a Map. This method is useful to enable standard Java internationalization support.

getBeanDefinition

protected final AbstractBeanDefinition getBeanDefinition(java.lang.String prototypeName)
                                                  throws NoSuchBeanDefinitionException
Description copied from class: AbstractBeanFactory
This method must be defined by concrete subclasses to implement the Template Method GoF design pattern.
Subclasses should normally implement caching, as this method is invoked by this class every time a bean is requested.
Overrides:
getBeanDefinition in class AbstractBeanFactory
See Also:
AbstractBeanFactory.getBeanDefinition(String)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Rod Johnson and Spring contributors 2001-2003.