|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectnet.sf.jguiraffe.di.impl.CombinedBeanContext
public class CombinedBeanContext
A specific BeanContext implementation that allows to combine
multiple bean contexts.
Combining bean context objects makes sense when a hierarchy of bean stores is not sufficient for expressing complex scopes of beans. One use case is a bean store with bean definitions that are only locally visible and with the restriction that beans defined globally take precedence over the local beans. (To achieve this only with bean stores, the store with local beans would have to be put on top of the hierarchy; but then its beans would be globally visible.)
An instance of this class maintains an arbitrary number (> 0) of child
bean contexts. The methods demanded by the BeanContext interface
are implemented in a way that calls are delegated to the child contexts in
the following manner:
beanNames() and beanClasses() methods
construct a union of the beans defined in all child bean contexts.containsBean() methods return true if and only if
the requested bean is found in one of the child bean contexts.getBean() methods query the child contexts (in the order
they were passed when this instance was created) until one contains the
desired bean. Then this context is asked to create the bean.BeanStore as parameter also are not
really meaningful for a combined bean context: all child bean contexts should
behave the same when passed in the same bean store. So these methods are
directly delegated to the first child context.Note: This implementation is immutable and thus can be shared between multiple parties and threads.
| Constructor Summary | |
|---|---|
CombinedBeanContext(BeanContext... childContexts)
Creates a new instance of CombinedBeanContext and sets the
child contexts. |
|
| Method Summary | ||
|---|---|---|
void |
addBeanCreationListener(BeanCreationListener l)
Adds the specified BeanCreationListener to this context. |
|
java.util.Set<java.lang.Class<?>> |
beanClasses()
Returns a set with the classes of all beans that can be reached from the default bean store. |
|
java.util.Set<java.lang.Class<?>> |
beanClasses(BeanStore store)
Returns a set with the classes of the existing beans starting with the given bean store. |
|
java.lang.String |
beanNameFor(BeanProvider beanProvider)
Returns the name for the specified BeanProvider starting search
at the default bean store. |
|
java.lang.String |
beanNameFor(BeanProvider beanProvider,
BeanStore store)
Returns the name for the specified BeanProvider starting search
at the specified bean store. |
|
java.util.Set<java.lang.String> |
beanNames()
Returns a set with the names of all beans that can be reached from the default bean store. |
|
java.util.Set<java.lang.String> |
beanNames(BeanStore store)
Returns a set with the names of the existing beans starting with the given bean store. |
|
void |
close()
Closes this BeanContext. |
|
boolean |
containsBean(java.lang.Class<?> beanClass)
Tests whether a bean with the given class can be found starting from the default bean store. |
|
boolean |
containsBean(java.lang.Class<?> beanClass,
BeanStore store)
Tests whether a bean with the given class can be found starting from the specified bean store. |
|
boolean |
containsBean(java.lang.String name)
Tests whether a bean with the given name can be found starting from the default bean store. |
|
boolean |
containsBean(java.lang.String name,
BeanStore store)
Tests whether a bean with the given name can be found starting from the specified bean store. |
|
|
getBean(java.lang.Class<T> beanCls)
Returns the bean with the given class starting search at the default bean store. |
|
|
getBean(java.lang.Class<T> beanCls,
BeanStore store)
Returns the bean with the given class starting search at the provided bean store. |
|
java.lang.Object |
getBean(java.lang.String name)
Returns the bean with the given name starting search at the default bean store. |
|
java.lang.Object |
getBean(java.lang.String name,
BeanStore store)
Returns the bean with the given name starting search at the provided bean store. |
|
BeanContext |
getChildContext(int idx)
Returns the child context with the given index. |
|
BeanStore |
getDefaultBeanStore()
Returns the default bean store. |
|
void |
removeBeanCreationListener(BeanCreationListener l)
Removes the specified BeanCreationListener from this context. |
|
void |
setDefaultBeanStore(BeanStore store)
Sets the default bean store. |
|
int |
size()
Returns the number of child contexts. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public CombinedBeanContext(BeanContext... childContexts)
CombinedBeanContext and sets the
child contexts. The passed in array must contain at least a single
element. null references are not permitted.
childContexts - an array with the child contexts
java.lang.IllegalArgumentException - if the array with the child contexts is
empty or contains null elements| Method Detail |
|---|
public int size()
public BeanContext getChildContext(int idx)
size().
idx - the index
java.lang.ArrayIndexOutOfBoundsException - if the index is invalidpublic java.util.Set<java.lang.Class<?>> beanClasses()
beanClasses in interface BeanContextpublic java.util.Set<java.lang.Class<?>> beanClasses(BeanStore store)
beanClasses in interface BeanContextstore - the store
public java.util.Set<java.lang.String> beanNames()
beanNames in interface BeanContextpublic java.util.Set<java.lang.String> beanNames(BeanStore store)
beanNames in interface BeanContextstore - the store
public boolean containsBean(java.lang.String name)
containsBean in interface BeanContextname - the name of the bean
public boolean containsBean(java.lang.String name,
BeanStore store)
containsBean in interface BeanContextname - the name of the bean in questionstore - the bean store
public boolean containsBean(java.lang.Class<?> beanClass)
containsBean in interface BeanContextbeanClass - the class of the bean
public boolean containsBean(java.lang.Class<?> beanClass,
BeanStore store)
containsBean in interface BeanContextbeanClass - the class of the bean in questionstore - the bean store
public java.lang.Object getBean(java.lang.String name)
getBean() is
invoked. If no child context contains the bean in question, an exception
is thrown.
getBean in interface BeanContextname - the name of the desired bean
InjectionException - if the bean cannot be found or obtaining it
causes an exception
public java.lang.Object getBean(java.lang.String name,
BeanStore store)
getBean in interface BeanContextname - the name of the desired beanstore - the bean store
InjectionException - if the bean cannot be resolvedpublic <T> T getBean(java.lang.Class<T> beanCls)
getBean() is
invoked. If no child context contains the bean in question, an exception
is thrown.
getBean in interface BeanContextbeanCls - the class of the desired bean
InjectionException - if the bean cannot be found or obtaining it
causes an exception
public <T> T getBean(java.lang.Class<T> beanCls,
BeanStore store)
getBean in interface BeanContextbeanCls - the class of the desired beanstore - the bean store
InjectionException - if the bean cannot be resolvedpublic java.lang.String beanNameFor(BeanProvider beanProvider)
BeanProvider starting search
at the default bean store. This implementation searches the child
contexts until a match is found.
beanNameFor in interface BeanContextbeanProvider - the BeanProvider
BeanProvider or nullBeanContext.beanNameFor(BeanProvider, BeanStore)
public java.lang.String beanNameFor(BeanProvider beanProvider,
BeanStore store)
BeanProvider starting search
at the specified bean store. This implementation delegates to the first
child context.
beanNameFor in interface BeanContextbeanProvider - the BeanProviderstore - the BeanStore
BeanProvider or nullpublic BeanStore getDefaultBeanStore()
getDefaultBeanStore in interface BeanContextpublic void setDefaultBeanStore(BeanStore store)
setDefaultBeanStore in interface BeanContextstore - the new default bean storepublic void addBeanCreationListener(BeanCreationListener l)
BeanCreationListener to this context. This
implementation ensures that bean creation events fired by all child
contexts can be received.
addBeanCreationListener in interface BeanContextl - the listener to be added
java.lang.IllegalArgumentException - if one of the child stores throws an
exception (which may be the case if the listener is null)public void removeBeanCreationListener(BeanCreationListener l)
BeanCreationListener from this context.
removeBeanCreationListener in interface BeanContextl - the listener to be removedpublic void close()
BeanContext. The creation listeners registered at the
child contexts have to be removed. All child contexts are closed, too.
close in interface BeanContext
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||