Package net.sf.jguiraffe.di.impl
Class BeanContextWrapper
- java.lang.Object
-
- net.sf.jguiraffe.di.impl.BeanContextWrapper
-
- All Implemented Interfaces:
BeanContext
public class BeanContextWrapper extends Object implements BeanContext
A simple wrapper implementation of the
BeanContextinterface.The main purpose of this class is to override the default
BeanStoreof a bean context. It is initialized with theBeanContextobject to be wrapped and the defaultBeanStoreto be used. All calls to methods defined by theBeanContextinterface are delegated to the wrapped bean context object. If they address the default bean store (i.e. no bean store is explicitly passed to the method), the bean store set for this instance is used. That way an already configured bean context can be used in a different context (which means, using another bean store as default entry in the look up mechanism) without manipulating its state.- Version:
- $Id: BeanContextWrapper.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Constructor Summary
Constructors Constructor Description BeanContextWrapper(BeanContext wrappedContext)Creates a new instance ofBeanContextWrapperand sets the wrapped context.BeanContextWrapper(BeanContext wrappedContext, BeanStore defaultStore)Creates a new instance ofBeanContextWrapperand sets the wrapped context and the default bean store.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBeanCreationListener(BeanCreationListener l)Adds the specifiedBeanCreationListenerto this context.Set<Class<?>>beanClasses()Returns a set of the classes of the beans available in this bean context's default bean store.Set<Class<?>>beanClasses(BeanStore store)Returns a set of the classes of the beans available in the specified bean store.StringbeanNameFor(BeanProvider beanProvider)Returns the name of the givenBeanProviderstarting the search with the default bean store.StringbeanNameFor(BeanProvider beanProvider, BeanStore store)Returns the name of the givenBeanProviderstarting the search with the specified bean store.Set<String>beanNames()Returns a set with the names of the beans defined in this context's default bean store.Set<String>beanNames(BeanStore store)Returns a set with the names of the beans defined in the given bean store.voidclose()Closes thisBeanContext.booleancontainsBean(Class<?> beanClass)Checks whether a bean with the given class can be found in this bean context's default bean store.booleancontainsBean(Class<?> beanClass, BeanStore store)Checks whether a bean with the given class can be found in the specified bean store.booleancontainsBean(String name)Checks whether a bean with the given name can be found in the default bean store of this bean context.booleancontainsBean(String name, BeanStore store)Checks whether a bean with the given name can be found in the specified bean store.<T> TgetBean(Class<T> beanCls)Returns the bean with the given class starting the search with the default bean store.<T> TgetBean(Class<T> beanCls, BeanStore store)Returns the bean with the given class starting the search with the specified bean store.ObjectgetBean(String name)Returns the bean with the given name starting the search with the default bean store.ObjectgetBean(String name, BeanStore store)Returns the bean with the given name starting the search with the specified bean store.ClassLoaderProvidergetClassLoaderProvider()Returns theClassLoaderProviderused by this context.BeanStoregetDefaultBeanStore()Returns the default bean store.BeanContextgetWrappedContext()Returns the wrapped bean context.voidremoveBeanCreationListener(BeanCreationListener l)Removes the specifiedBeanCreationListenerfrom this context.voidsetClassLoaderProvider(ClassLoaderProvider clp)Sets theClassLoaderProviderto be used by this context.voidsetDefaultBeanStore(BeanStore store)Sets the default bean store.
-
-
-
Constructor Detail
-
BeanContextWrapper
public BeanContextWrapper(BeanContext wrappedContext)
Creates a new instance ofBeanContextWrapperand sets the wrapped context.- Parameters:
wrappedContext- the bean context to be wrapped (must not be null)- Throws:
IllegalArgumentException- if the bean context is null
-
BeanContextWrapper
public BeanContextWrapper(BeanContext wrappedContext, BeanStore defaultStore)
Creates a new instance ofBeanContextWrapperand sets the wrapped context and the default bean store.- Parameters:
wrappedContext- the bean context to be wrapped (must not be null)defaultStore- the default bean store ton be used- Throws:
IllegalArgumentException- if the bean context is null
-
-
Method Detail
-
getWrappedContext
public BeanContext getWrappedContext()
Returns the wrapped bean context.- Returns:
- a reference to the original bean context
-
beanClasses
public Set<Class<?>> beanClasses()
Returns a set of the classes of the beans available in this bean context's default bean store. This implementation delegates to the wrapped context.- Specified by:
beanClassesin interfaceBeanContext- Returns:
- a set with the classes of the defined beans
-
beanClasses
public Set<Class<?>> beanClasses(BeanStore store)
Returns a set of the classes of the beans available in the specified bean store. This implementation delegates to the wrapped context.- Specified by:
beanClassesin interfaceBeanContext- Parameters:
store- the bean store- Returns:
- a set with the classes of the defined beans
-
beanNames
public Set<String> beanNames()
Returns a set with the names of the beans defined in this context's default bean store. This implementation delegates to the wrapped context.- Specified by:
beanNamesin interfaceBeanContext- Returns:
- a set with the names of the defined beans
-
beanNames
public Set<String> beanNames(BeanStore store)
Returns a set with the names of the beans defined in the given bean store. This implementation delegates to the wrapped context.- Specified by:
beanNamesin interfaceBeanContext- Parameters:
store- the bean store- Returns:
- a set with the names of the defined beans
-
containsBean
public boolean containsBean(String name)
Checks whether a bean with the given name can be found in the default bean store of this bean context. This implementation delegates to the wrapped context.- Specified by:
containsBeanin interfaceBeanContext- Parameters:
name- the name of the searched bean- Returns:
- a flag whether this bean can be found
-
containsBean
public boolean containsBean(String name, BeanStore store)
Checks whether a bean with the given name can be found in the specified bean store. This implementation delegates to the wrapped context.- Specified by:
containsBeanin interfaceBeanContext- Parameters:
name- the name of the beanstore- the bean store- Returns:
- a flag whether this bean can be found
-
containsBean
public boolean containsBean(Class<?> beanClass)
Checks whether a bean with the given class can be found in this bean context's default bean store. This implementation delegates to the wrapped context.- Specified by:
containsBeanin interfaceBeanContext- Parameters:
beanClass- the class of the bean- Returns:
- a flag whether this bean can be found
-
containsBean
public boolean containsBean(Class<?> beanClass, BeanStore store)
Checks whether a bean with the given class can be found in the specified bean store. This implementation delegates to the wrapped context.- Specified by:
containsBeanin interfaceBeanContext- Parameters:
beanClass- the class of the beanstore- the bean store- Returns:
- a flag whether this bean can be found
-
getBean
public Object getBean(String name)
Returns the bean with the given name starting the search with the default bean store. This implementation delegates to the wrapped context.- Specified by:
getBeanin interfaceBeanContext- Parameters:
name- the name of the desired bean- Returns:
- the bean
-
getBean
public Object getBean(String name, BeanStore store)
Returns the bean with the given name starting the search with the specified bean store. This implementation delegates to the wrapped context.- Specified by:
getBeanin interfaceBeanContext- Parameters:
name- the name of the desired beanstore- the bean store to start with- Returns:
- the bean
-
getBean
public <T> T getBean(Class<T> beanCls)
Returns the bean with the given class starting the search with the default bean store. This implementation delegates to the wrapped context.- Specified by:
getBeanin interfaceBeanContext- Type Parameters:
T- the type of the bean- Parameters:
beanCls- the class of the desired bean- Returns:
- the bean
-
getBean
public <T> T getBean(Class<T> beanCls, BeanStore store)
Returns the bean with the given class starting the search with the specified bean store. This implementation delegates to the wrapped context.- Specified by:
getBeanin interfaceBeanContext- Type Parameters:
T- the type of the bean- Parameters:
beanCls- the class of the desired beanstore- the store to start with- Returns:
- the bean
-
beanNameFor
public String beanNameFor(BeanProvider beanProvider)
Returns the name of the givenBeanProviderstarting the search with the default bean store. This implementation delegates to the wrapped context.- Specified by:
beanNameForin interfaceBeanContext- Parameters:
beanProvider- theBeanProvider- Returns:
- the name of this
BeanProvideror null - See Also:
BeanContext.beanNameFor(BeanProvider, BeanStore)
-
beanNameFor
public String beanNameFor(BeanProvider beanProvider, BeanStore store)
Returns the name of the givenBeanProviderstarting the search with the specified bean store. This implementation delegates to the wrapped context.- Specified by:
beanNameForin interfaceBeanContext- Parameters:
beanProvider- theBeanProviderstore- theBeanStore- Returns:
- the name of this
BeanProvideror null
-
getDefaultBeanStore
public BeanStore getDefaultBeanStore()
Returns the default bean store. This implementation returns the default store set for this wrapped context and not the one of the underlying context.- Specified by:
getDefaultBeanStorein interfaceBeanContext- Returns:
- the default bean store
-
setDefaultBeanStore
public void setDefaultBeanStore(BeanStore store)
Sets the default bean store. This implementation only changes the default bean store of this wrapped context. The default store of the underlying context is not touched.- Specified by:
setDefaultBeanStorein interfaceBeanContext- Parameters:
store- the new default bean store
-
addBeanCreationListener
public void addBeanCreationListener(BeanCreationListener l)
Adds the specifiedBeanCreationListenerto this context. This implementation ensures that events from the wrapped context are received. However, the events are correctly transformed so that this context is set as the source context of the event.- Specified by:
addBeanCreationListenerin interfaceBeanContext- Parameters:
l- the listener to be added
-
removeBeanCreationListener
public void removeBeanCreationListener(BeanCreationListener l)
Removes the specifiedBeanCreationListenerfrom this context.- Specified by:
removeBeanCreationListenerin interfaceBeanContext- Parameters:
l- the listener to be removed
-
close
public void close()
Closes thisBeanContext. This implementation removes theBeanCreationListenerregistered at the wrapped context. Note that the wrapped context will not be closed! This is because the wrapped context is typically shared.- Specified by:
closein interfaceBeanContext
-
getClassLoaderProvider
public ClassLoaderProvider getClassLoaderProvider()
Returns theClassLoaderProviderused by this context. This implementation delegates to the wrapped context.- Specified by:
getClassLoaderProviderin interfaceBeanContext- Returns:
- the
ClassLoaderProvider
-
setClassLoaderProvider
public void setClassLoaderProvider(ClassLoaderProvider clp)
Sets theClassLoaderProviderto be used by this context. This implementation delegates to the wrapped context.- Specified by:
setClassLoaderProviderin interfaceBeanContext- Parameters:
clp- the newClassLoaderProvider
-
-