public class SimpleBeanStoreImpl extends Object implements 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:
ConstantBeanProvider
objects are created for the
data objects to be managed. These providers are directly exposed through the
BeanStore
methods.BeanContributor
interface and register themselves at a
SimpleBeanStoreImpl
instance. The BeanConstributor
interface is much easier to implement than the BeanStore
interface. The implementations of the BeanStore
methods provided
by this class take the registered BeanContributor
s into account.
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.
Modifier and Type | Class and Description |
---|---|
static interface |
SimpleBeanStoreImpl.BeanContributor
Definition of an interface for objects that can contribute beans for a
SimpleBeanStoreImpl object. |
Constructor and Description |
---|
SimpleBeanStoreImpl()
Creates a new instance of
SimpleBeanStoreImpl . |
SimpleBeanStoreImpl(String name,
BeanStore parent)
Creates a new instance of
SimpleBeanStoreImpl and sets the
name and the reference to the parent. |
Modifier and Type | Method and Description |
---|---|
void |
addBean(String name,
Object bean)
Adds the specified bean to this store.
|
void |
addBeanContributor(SimpleBeanStoreImpl.BeanContributor contr)
Adds a new
BeanContributor to this object. |
BeanProvider |
getBeanProvider(String name)
Returns a
BeanProvider for the bean with the given name. |
ConversionHelper |
getConversionHelper()
Returns the
ConversionHelper associated with this instance. |
String |
getName()
Returns the name of this bean store.
|
BeanStore |
getParent()
Returns the parent bean store.
|
protected BeanProvider |
providerFor(Object bean)
Returns a bean provider for the specified bean.
|
Set<String> |
providerNames()
Returns a set with the names of the available bean providers.
|
Object |
removeBean(String name)
Removes the bean with the given name.
|
void |
removeBeanContributor(SimpleBeanStoreImpl.BeanContributor contr)
Removes the specified bean contributor from this object.
|
void |
setConversionHelper(ConversionHelper conversionHelper)
Sets the
ConversionHelper associated with this object. |
void |
setName(String name)
Sets the name of this bean store.
|
void |
setParent(BeanStore parent)
Sets the parent bean store.
|
public SimpleBeanStoreImpl()
SimpleBeanStoreImpl
.public void addBeanContributor(SimpleBeanStoreImpl.BeanContributor contr)
BeanContributor
to this object. This
contributor will be triggered when this bean store is accessed.contr
- the contributor to be added (must not be null)IllegalArgumentException
- if the contributor is nullpublic void removeBeanContributor(SimpleBeanStoreImpl.BeanContributor contr)
contr
- the contributor to removepublic void addBean(String name, Object bean)
getBeanProvider()
method.name
- the name of the bean (must not be null)bean
- the bean (must not be null)IllegalArgumentException
- if the name or the bean is nullpublic Object removeBean(String name)
name
- the name of the bean to be removedpublic BeanProvider getBeanProvider(String name)
BeanProvider
for the bean with the given name.
This implementation checks whether such a bean was directly added using
the addBean()
method. If not, the registered bean
contributors are consulted. If no such bean can be found, null is
returned.getBeanProvider
in interface BeanStore
name
- the name of the bean in questionBeanProvider
for this beanpublic String getName()
public void setName(String name)
name
- the new namepublic BeanStore getParent()
public void setParent(BeanStore parent)
parent
- the parent bean storepublic ConversionHelper getConversionHelper()
ConversionHelper
associated with this instance.getConversionHelper
in interface BeanStore
ConversionHelper
public void setConversionHelper(ConversionHelper conversionHelper)
ConversionHelper
associated with this object. The object
passed to this method will be returned by getConversionHelper()
.conversionHelper
- the ConversionHelper
public Set<String> providerNames()
providerNames
in interface BeanStore
protected BeanProvider providerFor(Object bean)
ConstantBeanProvider
for the
passed in bean.bean
- the beanCopyright © 2016 The JGUIraffe Team. All rights reserved.