Package net.sf.jguiraffe.di
Interface DependencyProvider
-
- All Superinterfaces:
ClassLoaderProvider
- All Known Implementing Classes:
RestrictedDependencyProvider
public interface DependencyProvider extends ClassLoaderProvider
Definition of an interface that provides access to dependencies defined by a
BeanProvider
.This interface is used by a
BeanProvider
implementation for resolving its dependencies to other beans. An implementation of this interface is passed to the bean provider'sgetBean()
method, allowing access to the required dependencies. By extending theClassLoaderProvider
interface functionality for dealing with dynamic class loading is also available through this interface.Note that this interface is used internally by the framework. Clients probably won't have to deal with it directly. It is only of importance for custom implementations of the
BeanProvider
interface.- Version:
- $Id: DependencyProvider.java 205 2012-01-29 18:29:57Z oheger $
- Author:
- Oliver Heger
-
-
Field Summary
-
Fields inherited from interface net.sf.jguiraffe.di.ClassLoaderProvider
CONTEXT_CLASS_LOADER
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addInitializer(BeanInitializer initializer)
Registers aBeanInitializer
.void
beanCreated(Object bean, BeanProvider provider)
Notifies thisDependencyProvider
about the creation of a bean.Object
getDependentBean(Dependency dependency)
Returns the dependency bean for the specified dependency.InvocationHelper
getInvocationHelper()
Returns a reference to the currentInvocationHelper
object.boolean
isBeanAvailable(Dependency dependency)
Checks whether the bean specified by the givenDependency
is currently available.void
setCreationBeanContext(BeanContext context)
Sets theBeanContext
that is responsible for aBeanCreationEvent
notification.-
Methods inherited from interface net.sf.jguiraffe.di.ClassLoaderProvider
classLoaderNames, getClassLoader, getDefaultClassLoaderName, loadClass, registerClassLoader, setDefaultClassLoaderName
-
-
-
-
Method Detail
-
getDependentBean
Object getDependentBean(Dependency dependency)
Returns the dependency bean for the specified dependency. This dependency must have been part of the collection of dependencies returned by the bean provider'sgetDependencies()
method.- Parameters:
dependency
- the dependency pointing to the bean in question- Returns:
- the bean for this dependency
- Throws:
InjectionException
- if the bean cannot be resolved
-
isBeanAvailable
boolean isBeanAvailable(Dependency dependency)
Checks whether the bean specified by the givenDependency
is currently available. This method can be used by complex bean providers to find out whether an initialization of their managed bean is now possible. Because of cyclic dependencies it may be the case that a required dependency cannot be resolved now. The affected bean provider can then register itself as an initializer and try again after the creation phase has completed.- Parameters:
dependency
- the dependency pointing to the bean in question- Returns:
- a flag whether this bean is currently available
- Throws:
InjectionException
- if the dependency cannot be resolved- See Also:
addInitializer(BeanInitializer)
-
addInitializer
void addInitializer(BeanInitializer initializer)
Registers aBeanInitializer
. This object will be called at the end of the transaction when all beans have been created. This gives complex bean providers an opportunity of trying some initializations again that were not possible before because of cyclic dependencies. A concrete implementation has to ensure that the initializers registered here are always called before the current transaction ends - no matter whether it succeeds or fails.- Parameters:
initializer
- the initializer to register
-
beanCreated
void beanCreated(Object bean, BeanProvider provider)
Notifies thisDependencyProvider
about the creation of a bean. This method has to be called byBeanProvider
implementations when a new bean has been completely created. It allows the framework to perform some post processing, e.g. enhanced initialization of the new bean or notification of context listeners.- Parameters:
bean
- the newly created beanprovider
- theBeanProvider
responsible for this bean
-
setCreationBeanContext
void setCreationBeanContext(BeanContext context)
Sets theBeanContext
that is responsible for aBeanCreationEvent
notification. This method can be used by implementations of theBeanContext
interface that wrap other contexts, e.g. a combined bean context. Such wrapping contexts usually delegate to other contexts when a bean is requested. If such a request causes a new bean to be created, the correspondingBeanCreationEvent
per default has the wrapped context as its source, and also aBeanContextClient
object will be initialized with this context. However, it may be appropriate to set the wrapping context as source. This can be achieved by registering aBeanCreationListener
at the wrapped contexts. In the event handling method thesetCreationBeanContext()
can be called with the wrapping context as parameter. Then correct creation context is known and can also be passed to aBeanContextClient
.- Parameters:
context
- theBeanContext
responsible for a bean creation
-
getInvocationHelper
InvocationHelper getInvocationHelper()
Returns a reference to the currentInvocationHelper
object. This helper object can be used by bean providers for more advanced operations related to reflection, e.g. method invocations or data type conversions. Especially the data type conversion facilities provided byInvocationHelper
may be of interest. The object returned by an implementation should be a central instance, i.e. the same instance that has been used for registering custom converter implementations.- Returns:
- the current
InvocationHelper
object
-
-