public class DefaultBeanStore extends Object implements MutableBeanStore
A simple yet fully functional default implementation of the
BeanStore
interface.
This implementation is based on a HashMap
.
BeanProvider
objects can be added to this map using the
addBeanProvider()
method. They can then be queried through the
getBeanProvider
method.
Note: This implementation is not thread-safe. The underlying map is not
synchronized. This does not cause any problems when used read-only by the
dependency injection framework. But if bean providers should be concurrently
added or other properties are to be manipulated, manual synchronization is
required. The intended use case is that an instance is created and populated
with BeanProvider
objects in an initialization phase. Then it should
only be accessed in a read-only fashion by the dependency injection
framework.
Constructor and Description |
---|
DefaultBeanStore()
Creates a new instance of
DefaultBeanStore . |
DefaultBeanStore(String name,
BeanStore parent)
Creates a new instance of
DefaultBeanStore and sets the name
and the reference to the parent. |
Modifier and Type | Method and Description |
---|---|
String |
addAnonymousBeanProvider(int index,
BeanProvider provider)
Adds an anonymous
BeanProvider . |
void |
addBeanProvider(String name,
BeanProvider provider)
Adds the specified
BeanProvider to this bean store under the
given name. |
void |
clear()
Removes all
BeanProvider s from this bean store. |
static ConversionHelper |
fetchConversionHelper(BeanStore store,
boolean createIfNecessary)
A convenience method for retrieving a
ConversionHelper object
from a hierarchy of bean stores. |
BeanProvider |
getBeanProvider(String name)
Returns the
BeanProvider with the specified name. |
ConversionHelper |
getConversionHelper()
Returns the
ConversionHelper associated with this object. |
String |
getName()
Returns the name of this bean store.
|
BeanStore |
getParent()
Returns the parent of this bean store or null if this is a top
level store.
|
Set<String> |
providerNames()
Returns a set with the names of all contained bean providers.
|
BeanProvider |
removeBeanProvider(String name)
Removes the
BeanProvider with the specified name from this
bean store. |
void |
setConversionHelper(ConversionHelper conversionHelper)
Sets the
ConversionHelper object to be associated with this
instance. |
void |
setName(String n)
Sets the name of this bean store.
|
void |
setParent(BeanStore p)
Sets the parent for this bean store.
|
String |
toString()
Returns a string representation of this object.
|
public DefaultBeanStore()
DefaultBeanStore
.public ConversionHelper getConversionHelper()
ConversionHelper
associated with this object.getConversionHelper
in interface BeanStore
ConversionHelper
public void setConversionHelper(ConversionHelper conversionHelper)
ConversionHelper
object to be associated with this
instance. The object passed to this method is returned by
getConversionHelper()
.conversionHelper
- the ConversionHelper
objectpublic static ConversionHelper fetchConversionHelper(BeanStore store, boolean createIfNecessary)
ConversionHelper
object
from a hierarchy of bean stores. This method queries the specified
BeanStore
for its ConversionHelper
. If it has one, the
helper object is returned. Otherwise, the parent BeanStore
is
queried. This continues until a ConversionHelper
object is found
or the top of the hierarchy is reached. If no ConversionHelper
can be found and the createIfNecessary
flag is true, a new
default helper object is created. Otherwise, the method returns
null if no helper can be found.store
- the BeanStore
where to start the searchcreateIfNecessary
- a flag whether a default helper instance should
be created if none can be foundConversionHelper
or nullpublic void addBeanProvider(String name, BeanProvider provider)
BeanProvider
to this bean store under the
given name.addBeanProvider
in interface MutableBeanStore
name
- the name of the bean provider (must not be null)provider
- the BeanProvider
to be registeredIllegalArgumentException
- if the name or the provider is
nullpublic String addAnonymousBeanProvider(int index, BeanProvider provider)
BeanProvider
. This method will generate a
special name (which is mainly used internally) for the bean provider to
add and store it under this name. The name is returned.addAnonymousBeanProvider
in interface MutableBeanStore
index
- the index of the bean providerprovider
- the BeanProvider
to be added (must not be
null)BeanProvider
IllegalArgumentException
- if the provider is nullpublic BeanProvider removeBeanProvider(String name)
BeanProvider
with the specified name from this
bean store. If this provider cannot be found, this operation has no
effect.removeBeanProvider
in interface MutableBeanStore
name
- the name of the provider to removepublic void clear()
BeanProvider
s from this bean store.clear
in interface MutableBeanStore
public BeanProvider getBeanProvider(String name)
BeanProvider
with the specified name. If no such
element exists, null is returned.getBeanProvider
in interface BeanStore
name
- the name of the desired providerBeanProvider
with this namepublic String getName()
public void setName(String n)
setName
in interface MutableBeanStore
n
- the new namepublic BeanStore getParent()
public void setParent(BeanStore p)
setParent
in interface MutableBeanStore
p
- the parentpublic Set<String> providerNames()
providerNames
in interface BeanStore
Copyright © 2016 The JGUIraffe Team. All rights reserved.