public class CombinedBeanStore extends Object implements BeanStore
A specialized implementation of the BeanStore
interface that combines
multiple physical BeanStore
objects to a single logic view.
In some use cases a hierarchy of BeanStore
objects is not sufficient
to express complex relations between stores. One example are BeanStore
objects created by separate builder operations or based on
different, disjunct implementations. If now beans in these stores refer to
each other, it may be impossible to find a parent-child relationship that
allows resolving all possible dependencies.
This implementation of BeanStore
provides a solution for this
problem. It can be initialized with an arbitrary number of child BeanStore
objects and generates a logic view on top of these stores as if
their beans comprised a single BeanStore
. This is achieved by
corresponding implementations of the methods defined by the BeanStore
interface, for instance the providerNames()
method returns a union of
the names of all providers found in the child stores, or the getBeanProvider()
method checks all child stores whether the searched
provider can be found. More information about the implementation of the
single methods can be found in the Javadocs of the corresponding methods.
Implementation note: The thread-safety of this class depends on the implementations of the child bean stores. This class stores the child stores in immutable structures; so provided that all child stores are immutable, the resulting object is immutable, too.
Constructor and Description |
---|
CombinedBeanStore(BeanStore... beanStores)
Creates a new instance of
CombinedBeanStore and initializes it
with the given child bean stores. |
CombinedBeanStore(String storeName,
BeanStore... beanStores)
Creates a new instance of
CombinedBeanStore and initializes it
with the given name and the child bean stores. |
Modifier and Type | Method and Description |
---|---|
BeanProvider |
getBeanProvider(String name)
Returns the
BeanProvider with the given name. |
BeanStore |
getChildStore(int idx)
Returns the child
BeanStore with the given index. |
ConversionHelper |
getConversionHelper()
Returns the
ConversionHelper associated with this instance. |
String |
getName()
Returns the name of this store.
|
BeanStore |
getParent()
Returns the parent store of this
CombinedBeanStore . |
Set<String> |
providerNames()
Returns a set with the names of all
BeanProvider objects that can
be queried from this CombinedBeanStore . |
int |
size()
Returns the number of child
BeanStore objects stored in this
combined store. |
String |
toString()
Returns a string representation of this object.
|
public CombinedBeanStore(String storeName, BeanStore... beanStores)
CombinedBeanStore
and initializes it
with the given name and the child bean stores. A defensive copy of the
passed in array with bean stores is created. The single elements must not
be null, otherwise an exception is thrown.storeName
- the name of this BeanStore
beanStores
- the child bean storesIllegalArgumentException
- if the array with the child bean stores
is null or contains null referencespublic CombinedBeanStore(BeanStore... beanStores)
CombinedBeanStore
and initializes it
with the given child bean stores. A default name for this store is
generated.beanStores
- the child bean storesIllegalArgumentException
- if the array with the child bean stores
is null or contains null referencespublic BeanProvider getBeanProvider(String name)
BeanProvider
with the given name. This implementation
iterates over all child BeanStore
objects. The first result
different from null is returned.getBeanProvider
in interface BeanStore
name
- the name of the BeanProvider
BeanProvider
or null if it
cannot be foundpublic int size()
BeanStore
objects stored in this
combined store.public BeanStore getChildStore(int idx)
BeanStore
with the given index. Indices are
0-based and must be in the range 0 <= idx < size()
.idx
- the indexBeanStore
at this indexArrayIndexOutOfBoundsException
- if the index is invalidpublic String getName()
public BeanStore getParent()
CombinedBeanStore
. If none of
the child stores has a parent, result is null. If exactly one
child store has a parent store, then this store is returned. Otherwise,
result is again a CombinedBeanStore
with all non-null
parent stores as its children.public Set<String> providerNames()
BeanProvider
objects that can
be queried from this CombinedBeanStore
. This implementation
queries all child stores and returns a union of their provider names.
Note: the returned set can be modified. It is not connected to this
object in any way.providerNames
in interface BeanStore
BeanProvider
objects
availablepublic ConversionHelper getConversionHelper()
ConversionHelper
associated with this instance. This
implementation iterates over the child stores. The first
ConversionHelper
instance that is found is returned. If none of
the child stores returns such a helper object, result is null.getConversionHelper
in interface BeanStore
ConversionHelper
associated with this instanceCopyright © 2016 The JGUIraffe Team. All rights reserved.