Class CombinedBeanStore
- java.lang.Object
-
- net.sf.jguiraffe.di.impl.CombinedBeanStore
-
- All Implemented Interfaces:
BeanStore
public class CombinedBeanStore extends Object implements BeanStore
A specialized implementation of the
BeanStore
interface that combines multiple physicalBeanStore
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 areBeanStore
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 childBeanStore
objects and generates a logic view on top of these stores as if their beans comprised a singleBeanStore
. This is achieved by corresponding implementations of the methods defined by theBeanStore
interface, for instance theproviderNames()
method returns a union of the names of all providers found in the child stores, or thegetBeanProvider()
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.
- Version:
- $Id: CombinedBeanStore.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description CombinedBeanStore(String storeName, BeanStore... beanStores)
Creates a new instance ofCombinedBeanStore
and initializes it with the given name and the child bean stores.CombinedBeanStore(BeanStore... beanStores)
Creates a new instance ofCombinedBeanStore
and initializes it with the given child bean stores.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BeanProvider
getBeanProvider(String name)
Returns theBeanProvider
with the given name.BeanStore
getChildStore(int idx)
Returns the childBeanStore
with the given index.ConversionHelper
getConversionHelper()
Returns theConversionHelper
associated with this instance.String
getName()
Returns the name of this store.BeanStore
getParent()
Returns the parent store of thisCombinedBeanStore
.Set<String>
providerNames()
Returns a set with the names of allBeanProvider
objects that can be queried from thisCombinedBeanStore
.int
size()
Returns the number of childBeanStore
objects stored in this combined store.String
toString()
Returns a string representation of this object.
-
-
-
Constructor Detail
-
CombinedBeanStore
public CombinedBeanStore(String storeName, BeanStore... beanStores)
Creates a new instance ofCombinedBeanStore
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.- Parameters:
storeName
- the name of thisBeanStore
beanStores
- the child bean stores- Throws:
IllegalArgumentException
- if the array with the child bean stores is null or contains null references
-
CombinedBeanStore
public CombinedBeanStore(BeanStore... beanStores)
Creates a new instance ofCombinedBeanStore
and initializes it with the given child bean stores. A default name for this store is generated.- Parameters:
beanStores
- the child bean stores- Throws:
IllegalArgumentException
- if the array with the child bean stores is null or contains null references
-
-
Method Detail
-
getBeanProvider
public BeanProvider getBeanProvider(String name)
Returns theBeanProvider
with the given name. This implementation iterates over all childBeanStore
objects. The first result different from null is returned.- Specified by:
getBeanProvider
in interfaceBeanStore
- Parameters:
name
- the name of theBeanProvider
- Returns:
- the corresponding
BeanProvider
or null if it cannot be found
-
size
public int size()
Returns the number of childBeanStore
objects stored in this combined store.- Returns:
- the number of child stores
-
getChildStore
public BeanStore getChildStore(int idx)
Returns the childBeanStore
with the given index. Indices are 0-based and must be in the range 0 <= idx <size()
.- Parameters:
idx
- the index- Returns:
- the child
BeanStore
at this index - Throws:
ArrayIndexOutOfBoundsException
- if the index is invalid
-
getName
public String getName()
Returns the name of this store. If a name was provided at construction time, this name is returned. Otherwise, a name was automatically generated for this store.
-
getParent
public BeanStore getParent()
Returns the parent store of thisCombinedBeanStore
. 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 aCombinedBeanStore
with all non-null parent stores as its children.
-
providerNames
public Set<String> providerNames()
Returns a set with the names of allBeanProvider
objects that can be queried from thisCombinedBeanStore
. 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.- Specified by:
providerNames
in interfaceBeanStore
- Returns:
- a set with the names of all
BeanProvider
objects available
-
getConversionHelper
public ConversionHelper getConversionHelper()
Returns theConversionHelper
associated with this instance. This implementation iterates over the child stores. The firstConversionHelper
instance that is found is returned. If none of the child stores returns such a helper object, result is null.- Specified by:
getConversionHelper
in interfaceBeanStore
- Returns:
- the
ConversionHelper
associated with this instance
-
-