public class BeanContextWrapper extends Object implements BeanContext
A simple wrapper implementation of the BeanContext
interface.
The main purpose of this class is to override the default
BeanStore
of a bean context. It is initialized with the
BeanContext
object to be wrapped and the default
BeanStore
to be used. All calls to methods defined by the
BeanContext
interface 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.
Constructor and Description |
---|
BeanContextWrapper(BeanContext wrappedContext)
Creates a new instance of
BeanContextWrapper and sets the
wrapped context. |
BeanContextWrapper(BeanContext wrappedContext,
BeanStore defaultStore)
Creates a new instance of
BeanContextWrapper and sets the
wrapped context and the default bean store. |
Modifier and Type | Method and Description |
---|---|
void |
addBeanCreationListener(BeanCreationListener l)
Adds the specified
BeanCreationListener to 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.
|
String |
beanNameFor(BeanProvider beanProvider)
Returns the name of the given
BeanProvider starting the search
with the default bean store. |
String |
beanNameFor(BeanProvider beanProvider,
BeanStore store)
Returns the name of the given
BeanProvider starting 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.
|
void |
close()
Closes this
BeanContext . |
boolean |
containsBean(Class<?> beanClass)
Checks whether a bean with the given class can be found in this bean
context's default bean store.
|
boolean |
containsBean(Class<?> beanClass,
BeanStore store)
Checks whether a bean with the given class can be found in the specified
bean store.
|
boolean |
containsBean(String name)
Checks whether a bean with the given name can be found in the default
bean store of this bean context.
|
boolean |
containsBean(String name,
BeanStore store)
Checks whether a bean with the given name can be found in the specified
bean store.
|
<T> T |
getBean(Class<T> beanCls)
Returns the bean with the given class starting the search with the
default bean store.
|
<T> T |
getBean(Class<T> beanCls,
BeanStore store)
Returns the bean with the given class starting the search with the
specified bean store.
|
Object |
getBean(String name)
Returns the bean with the given name starting the search with the default
bean store.
|
Object |
getBean(String name,
BeanStore store)
Returns the bean with the given name starting the search with the
specified bean store.
|
ClassLoaderProvider |
getClassLoaderProvider()
Returns the
ClassLoaderProvider used by this context. |
BeanStore |
getDefaultBeanStore()
Returns the default bean store.
|
BeanContext |
getWrappedContext()
Returns the wrapped bean context.
|
void |
removeBeanCreationListener(BeanCreationListener l)
Removes the specified
BeanCreationListener from this context. |
void |
setClassLoaderProvider(ClassLoaderProvider clp)
Sets the
ClassLoaderProvider to be used by this context. |
void |
setDefaultBeanStore(BeanStore store)
Sets the default bean store.
|
public BeanContextWrapper(BeanContext wrappedContext)
BeanContextWrapper
and sets the
wrapped context.wrappedContext
- the bean context to be wrapped (must not be
null)IllegalArgumentException
- if the bean context is nullpublic BeanContextWrapper(BeanContext wrappedContext, BeanStore defaultStore)
BeanContextWrapper
and sets the
wrapped context and the default bean store.wrappedContext
- the bean context to be wrapped (must not be
null)defaultStore
- the default bean store ton be usedIllegalArgumentException
- if the bean context is nullpublic BeanContext getWrappedContext()
public Set<Class<?>> beanClasses()
beanClasses
in interface BeanContext
public Set<Class<?>> beanClasses(BeanStore store)
beanClasses
in interface BeanContext
store
- the bean storepublic Set<String> beanNames()
beanNames
in interface BeanContext
public Set<String> beanNames(BeanStore store)
beanNames
in interface BeanContext
store
- the bean storepublic boolean containsBean(String name)
containsBean
in interface BeanContext
name
- the name of the searched beanpublic boolean containsBean(String name, BeanStore store)
containsBean
in interface BeanContext
name
- the name of the beanstore
- the bean storepublic boolean containsBean(Class<?> beanClass)
containsBean
in interface BeanContext
beanClass
- the class of the beanpublic boolean containsBean(Class<?> beanClass, BeanStore store)
containsBean
in interface BeanContext
beanClass
- the class of the beanstore
- the bean storepublic Object getBean(String name)
getBean
in interface BeanContext
name
- the name of the desired beanpublic Object getBean(String name, BeanStore store)
getBean
in interface BeanContext
name
- the name of the desired beanstore
- the bean store to start withpublic <T> T getBean(Class<T> beanCls)
getBean
in interface BeanContext
T
- the type of the beanbeanCls
- the class of the desired beanpublic <T> T getBean(Class<T> beanCls, BeanStore store)
getBean
in interface BeanContext
T
- the type of the beanbeanCls
- the class of the desired beanstore
- the store to start withpublic String beanNameFor(BeanProvider beanProvider)
BeanProvider
starting the search
with the default bean store. This implementation delegates to the wrapped
context.beanNameFor
in interface BeanContext
beanProvider
- the BeanProvider
BeanProvider
or nullBeanContext.beanNameFor(BeanProvider, BeanStore)
public String beanNameFor(BeanProvider beanProvider, BeanStore store)
BeanProvider
starting the search
with the specified bean store. This implementation delegates to the
wrapped context.beanNameFor
in interface BeanContext
beanProvider
- the BeanProvider
store
- the BeanStore
BeanProvider
or nullpublic BeanStore getDefaultBeanStore()
getDefaultBeanStore
in interface BeanContext
public void setDefaultBeanStore(BeanStore store)
setDefaultBeanStore
in interface BeanContext
store
- the new default bean storepublic void addBeanCreationListener(BeanCreationListener l)
BeanCreationListener
to 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.addBeanCreationListener
in interface BeanContext
l
- the listener to be addedpublic void removeBeanCreationListener(BeanCreationListener l)
BeanCreationListener
from this context.removeBeanCreationListener
in interface BeanContext
l
- the listener to be removedpublic void close()
BeanContext
. This implementation removes the BeanCreationListener
registered at the wrapped context. Note that the
wrapped context will not be closed! This is because the wrapped context
is typically shared.close
in interface BeanContext
public ClassLoaderProvider getClassLoaderProvider()
ClassLoaderProvider
used by this context. This
implementation delegates to the wrapped context.getClassLoaderProvider
in interface BeanContext
ClassLoaderProvider
public void setClassLoaderProvider(ClassLoaderProvider clp)
ClassLoaderProvider
to be used by this context. This
implementation delegates to the wrapped context.setClassLoaderProvider
in interface BeanContext
clp
- the new ClassLoaderProvider
Copyright © 2016 The JGUIraffe Team. All rights reserved.