|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
public interface BeanContext
Definition of an interface that allows access to the beans managed by the dependency injection framework.
This interface serves as the top-level entry point into the dependency
injection framework. It allows querying beans from a specified
or a default BeanStoreBeanStore by
name or by type. Listing the available beans is also possible.
When objects are dynamically created, class loader issues have to be taken
into account. A BeanContext allows the registration of class
loaders by name. In the configuration, it can then be specified, which bean
is to be created using which class loader. For the context class loader there
is a special constant.
| Method Summary | ||
|---|---|---|
void |
addBeanCreationListener(BeanCreationListener l)
Adds a new BeanCreationListener to this context. |
|
java.util.Set<java.lang.Class<?>> |
beanClasses()
Returns a set with the classes of all beans defined in the default BeanStore (or one of its parents). |
|
java.util.Set<java.lang.Class<?>> |
beanClasses(BeanStore store)
Returns a set with the classes of all beans defined in the given BeanStore. |
|
java.lang.String |
beanNameFor(BeanProvider beanProvider)
Returns the name of the bean that is managed by the specified BeanProvider, starting search with the default BeanStore. |
|
java.lang.String |
beanNameFor(BeanProvider beanProvider,
BeanStore store)
Returns the name of the bean that is managed by the specified BeanProvider, starting search in the specified BeanStore. |
|
java.util.Set<java.lang.String> |
beanNames()
Returns a set with the names of all beans defined in the default BeanStore. |
|
java.util.Set<java.lang.String> |
beanNames(BeanStore store)
Returns a set with the names of all beans defined in the given BeanStore. |
|
void |
close()
Closes this bean context. |
|
boolean |
containsBean(java.lang.Class<?> beanClass)
Checks whether the default BeanStore contains a bean with
the given class. |
|
boolean |
containsBean(java.lang.Class<?> beanClass,
BeanStore store)
Checks whether the specified BeanStore contains a bean
with the given class. |
|
boolean |
containsBean(java.lang.String name)
Checks whether the default BeanStore contains a bean with
the given name. |
|
boolean |
containsBean(java.lang.String name,
BeanStore store)
Checks whether the specified BeanStore contains a bean
with the given name. |
|
|
getBean(java.lang.Class<T> beanCls)
Returns the bean with the specified class from the default BeanStore. |
|
|
getBean(java.lang.Class<T> beanCls,
BeanStore store)
Returns the bean with the specified class from the given BeanStore. |
|
java.lang.Object |
getBean(java.lang.String name)
Returns the bean with the specified name from the default BeanStore. |
|
java.lang.Object |
getBean(java.lang.String name,
BeanStore store)
Returns the bean with the specified name from the given BeanStore. |
|
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. |
|
| Method Detail |
|---|
java.lang.Object getBean(java.lang.String name)
BeanStore.
name - the name of the bean to be retrieved
InjectionException - if the bean cannot be resolved or its creation
or initialization causes an error
java.lang.Object getBean(java.lang.String name,
BeanStore store)
BeanStore. This method can be used if a child bean store
of the default bean store is to be accessed.
name - the name of the bean to be retrievedstore - the BeanStore to query
InjectionException - if the bean cannot be resolved or its creation
or initialization causes an error
java.lang.IllegalArgumentException - if the passed in bean store is null<T> T getBean(java.lang.Class<T> beanCls)
BeanStore. An implementation of this method has to
iterate over the beans defined in the bean store to find out, whether the
specified class is assignable from their class. Then the first fitting
bean will be returned. So it is for instance possible to query for an
interface and find a bean that is a concrete implementation of this
interface. If there are multiple bean definitions that are compatible
with this class, it is up to a concrete implementation of this interface
to choose one. Defining beans based on a class (or interface) allows to
abstract from the concrete naming of beans and focuses more on the beans'
semantics.
beanCls - the class of the bean to be fetched
InjectionException - if the bean cannot be resolved or its creation
or initialization causes an error
<T> T getBean(java.lang.Class<T> beanCls,
BeanStore store)
BeanStore. Works like the overloaded method, but operates
on the given bean store.
beanCls - the class of the bean to be fetchedstore - the BeanStore to use
InjectionException - if the bean cannot be resolved or its creation
or initialization causes an error
java.lang.IllegalArgumentException - if the passed in bean store is nulljava.util.Set<java.lang.String> beanNames()
BeanStore.
java.util.Set<java.lang.String> beanNames(BeanStore store)
BeanStore. This list will also contain beans that are
defined in one of the bean store's parents.
store - the bean store (must not be null)
java.lang.IllegalArgumentException - if the passed in bean store is nulljava.util.Set<java.lang.Class<?>> beanClasses()
BeanStore (or one of its parents).
java.util.Set<java.lang.Class<?>> beanClasses(BeanStore store)
BeanStore. This list will also contain beans that are
defined in one of the bean store's parents.
store - the bean store (must not be null)
java.lang.IllegalArgumentException - if the passed in bean store is nullboolean containsBean(java.lang.String name)
BeanStore contains a bean with
the given name. If necessary the bean store's parents will also be
searched.
name - the name of the searched bean
boolean containsBean(java.lang.String name,
BeanStore store)
BeanStore contains a bean
with the given name. If necessary the bean store's parents will also be
searched.
name - the name of the searched beanstore - the bean store
boolean containsBean(java.lang.Class<?> beanClass)
BeanStore contains a bean with
the given class. If necessary the bean store's parents will also be
searched.
beanClass - the class of the searched bean
boolean containsBean(java.lang.Class<?> beanClass,
BeanStore store)
BeanStore contains a bean
with the given class. If necessary the bean store's parents will also be
searched.
beanClass - the class of the searched beanstore - the bean store
BeanStore getDefaultBeanStore()
void setDefaultBeanStore(BeanStore store)
store - the new default bean storejava.lang.String beanNameFor(BeanProvider beanProvider)
BeanProvider, starting search with the default BeanStore.
beanProvider - the BeanProvider
BeanProvider is registered in
one of the accessible bean stores or null if it cannot be
resolvedbeanNameFor(BeanProvider, BeanStore)
java.lang.String beanNameFor(BeanProvider beanProvider,
BeanStore store)
BeanProvider, starting search in the specified BeanStore. This
method can be used for performing a "reverse lookup": when a bean
provider is known, but the corresponding bean name is searched. A use
case would be the processing of a BeanCreationEvent. The event
object contains the BeanProvider that created the bean, but the
name of this bean is not part of the event.
beanProvider - the BeanProviderstore - the BeanStore
BeanProvider is registered in
one of the accessible bean stores or null if it cannot be
resolvedvoid addBeanCreationListener(BeanCreationListener l)
BeanCreationListener to this context. This listener
will receive notifications about newly created beans.
l - the listener to be added (must not be null)
java.lang.IllegalArgumentException - if the listener is nullvoid removeBeanCreationListener(BeanCreationListener l)
BeanCreationListener from this context. If
the listener is not registered, this method has no effect.
l - the listener to removevoid close()
BeanStore associated with this context is
not closed by this method (this is because a BeanStore could be
shared by multiple contexts, and there is not necessary a 1:1
relationship between a BeanStore and a BeanContext).
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||