Package net.sf.jguiraffe.di.impl
Klasse SimpleBeanStoreImpl
java.lang.Object
net.sf.jguiraffe.di.impl.SimpleBeanStoreImpl
- Alle implementierten Schnittstellen:
BeanStore
A helper class that simplifies implementations of the BeanStore
interface.
The purpose of this class is to support BeanStore
implementations based on classes that are not aware of BeanProvider
s,
but provide a map-like interface for accessing their data. This is achieved
in the following ways:
- Static data (in form of arbitrary objects) can directly be added to this
class. Internally
ConstantBeanProvider
objects are created for the data objects to be managed. These providers are directly exposed through theBeanStore
methods. - If dynamic data is involved (i.e. objects that may change over time and
cannot be kept in a map), components can implement the internal
BeanContributor
interface and register themselves at aSimpleBeanStoreImpl
instance. TheBeanConstributor
interface is much easier to implement than theBeanStore
interface. The implementations of theBeanStore
methods provided by this class take the registeredBeanContributor
s into account. - Methods of the
BeanStore
interface that do not directly deal with bean providers are already implemented by this class.
Note: The class per se is not thread-safe. When used inside the dependency injection framework, proper synchronization is automatically applied. But during initialization or for other use cases the developer has to ensure that there are no concurrent accesses.
- Version:
- $Id: SimpleBeanStoreImpl.java 213 2012-07-14 19:40:51Z oheger $
- Autor:
- Oliver Heger
-
Verschachtelte Klassen - Übersicht
Verschachtelte KlassenModifizierer und TypKlasseBeschreibungstatic interface
Definition of an interface for objects that can contribute beans for aSimpleBeanStoreImpl
object. -
Konstruktorübersicht
KonstruktorenKonstruktorBeschreibungCreates a new instance ofSimpleBeanStoreImpl
.SimpleBeanStoreImpl
(String name, BeanStore parent) Creates a new instance ofSimpleBeanStoreImpl
and sets the name and the reference to the parent. -
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoid
Adds the specified bean to this store.void
Adds a newBeanContributor
to this object.getBeanProvider
(String name) Returns aBeanProvider
for the bean with the given name.Returns theConversionHelper
associated with this instance.getName()
Returns the name of this bean store.Returns the parent bean store.protected BeanProvider
providerFor
(Object bean) Returns a bean provider for the specified bean.Returns a set with the names of the available bean providers.removeBean
(String name) Removes the bean with the given name.void
Removes the specified bean contributor from this object.void
setConversionHelper
(ConversionHelper conversionHelper) Sets theConversionHelper
associated with this object.void
Sets the name of this bean store.void
Sets the parent bean store.
-
Konstruktordetails
-
SimpleBeanStoreImpl
public SimpleBeanStoreImpl()Creates a new instance ofSimpleBeanStoreImpl
. -
SimpleBeanStoreImpl
Creates a new instance ofSimpleBeanStoreImpl
and sets the name and the reference to the parent.- Parameter:
name
- the name of this bean storeparent
- the reference to the parent bean store
-
-
Methodendetails
-
addBeanContributor
Adds a newBeanContributor
to this object. This contributor will be triggered when this bean store is accessed.- Parameter:
contr
- the contributor to be added (must not be null)- Löst aus:
IllegalArgumentException
- if the contributor is null
-
removeBeanContributor
Removes the specified bean contributor from this object.- Parameter:
contr
- the contributor to remove
-
addBean
Adds the specified bean to this store. For the passed in bean a constant bean provider is created. It can then be queried through thegetBeanProvider()
method.- Parameter:
name
- the name of the bean (must not be null)bean
- the bean (must not be null)- Löst aus:
IllegalArgumentException
- if the name or the bean is null
-
removeBean
Removes the bean with the given name.- Parameter:
name
- the name of the bean to be removed- Gibt zurück:
- the removed bean (null if the bean was unknown)
-
getBeanProvider
Returns aBeanProvider
for the bean with the given name. This implementation checks whether such a bean was directly added using theaddBean()
method. If not, the registered bean contributors are consulted. If no such bean can be found, null is returned.- Angegeben von:
getBeanProvider
in SchnittstelleBeanStore
- Parameter:
name
- the name of the bean in question- Gibt zurück:
- a
BeanProvider
for this bean
-
getName
Returns the name of this bean store. -
setName
Sets the name of this bean store.- Parameter:
name
- the new name
-
getParent
Returns the parent bean store. -
setParent
Sets the parent bean store.- Parameter:
parent
- the parent bean store
-
getConversionHelper
Returns theConversionHelper
associated with this instance.- Angegeben von:
getConversionHelper
in SchnittstelleBeanStore
- Gibt zurück:
- the
ConversionHelper
-
setConversionHelper
Sets theConversionHelper
associated with this object. The object passed to this method will be returned bygetConversionHelper()
.- Parameter:
conversionHelper
- theConversionHelper
-
providerNames
Returns a set with the names of the available bean providers. This implementation will first obtain the names of all directly added beans. Then the registered bean contributors are invoked to add their bean names to the resulting list.- Angegeben von:
providerNames
in SchnittstelleBeanStore
- Gibt zurück:
- a set with the names of the known bean providers
-
providerFor
Returns a bean provider for the specified bean. This method is called whenever a bean has to be wrapped by a provider. This default implementation returns aConstantBeanProvider
for the passed in bean.- Parameter:
bean
- the bean- Gibt zurück:
- a provider for this bean
-