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
BeanStoreinterface that combines multiple physicalBeanStoreobjects to a single logic view.In some use cases a hierarchy of
BeanStoreobjects is not sufficient to express complex relations between stores. One example areBeanStoreobjects 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
BeanStoreprovides a solution for this problem. It can be initialized with an arbitrary number of childBeanStoreobjects 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 theBeanStoreinterface, 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 ofCombinedBeanStoreand initializes it with the given name and the child bean stores.CombinedBeanStore(BeanStore... beanStores)Creates a new instance ofCombinedBeanStoreand initializes it with the given child bean stores.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BeanProvidergetBeanProvider(String name)Returns theBeanProviderwith the given name.BeanStoregetChildStore(int idx)Returns the childBeanStorewith the given index.ConversionHelpergetConversionHelper()Returns theConversionHelperassociated with this instance.StringgetName()Returns the name of this store.BeanStoregetParent()Returns the parent store of thisCombinedBeanStore.Set<String>providerNames()Returns a set with the names of allBeanProviderobjects that can be queried from thisCombinedBeanStore.intsize()Returns the number of childBeanStoreobjects stored in this combined store.StringtoString()Returns a string representation of this object.
-
-
-
Constructor Detail
-
CombinedBeanStore
public CombinedBeanStore(String storeName, BeanStore... beanStores)
Creates a new instance ofCombinedBeanStoreand 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 thisBeanStorebeanStores- 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 ofCombinedBeanStoreand 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 theBeanProviderwith the given name. This implementation iterates over all childBeanStoreobjects. The first result different from null is returned.- Specified by:
getBeanProviderin interfaceBeanStore- Parameters:
name- the name of theBeanProvider- Returns:
- the corresponding
BeanProvideror null if it cannot be found
-
size
public int size()
Returns the number of childBeanStoreobjects stored in this combined store.- Returns:
- the number of child stores
-
getChildStore
public BeanStore getChildStore(int idx)
Returns the childBeanStorewith the given index. Indices are 0-based and must be in the range 0 <= idx <size().- Parameters:
idx- the index- Returns:
- the child
BeanStoreat 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 aCombinedBeanStorewith all non-null parent stores as its children.
-
providerNames
public Set<String> providerNames()
Returns a set with the names of allBeanProviderobjects 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:
providerNamesin interfaceBeanStore- Returns:
- a set with the names of all
BeanProviderobjects available
-
getConversionHelper
public ConversionHelper getConversionHelper()
Returns theConversionHelperassociated with this instance. This implementation iterates over the child stores. The firstConversionHelperinstance that is found is returned. If none of the child stores returns such a helper object, result is null.- Specified by:
getConversionHelperin interfaceBeanStore- Returns:
- the
ConversionHelperassociated with this instance
-
-