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
BeanProviderimplementation 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 theClassLoaderProviderinterface 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
BeanProviderinterface.- 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 voidaddInitializer(BeanInitializer initializer)Registers aBeanInitializer.voidbeanCreated(Object bean, BeanProvider provider)Notifies thisDependencyProviderabout the creation of a bean.ObjectgetDependentBean(Dependency dependency)Returns the dependency bean for the specified dependency.InvocationHelpergetInvocationHelper()Returns a reference to the currentInvocationHelperobject.booleanisBeanAvailable(Dependency dependency)Checks whether the bean specified by the givenDependencyis currently available.voidsetCreationBeanContext(BeanContext context)Sets theBeanContextthat is responsible for aBeanCreationEventnotification.-
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 givenDependencyis 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 thisDependencyProviderabout the creation of a bean. This method has to be called byBeanProviderimplementations 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- theBeanProviderresponsible for this bean
-
setCreationBeanContext
void setCreationBeanContext(BeanContext context)
Sets theBeanContextthat is responsible for aBeanCreationEventnotification. This method can be used by implementations of theBeanContextinterface 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 correspondingBeanCreationEventper default has the wrapped context as its source, and also aBeanContextClientobject will be initialized with this context. However, it may be appropriate to set the wrapping context as source. This can be achieved by registering aBeanCreationListenerat 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- theBeanContextresponsible for a bean creation
-
getInvocationHelper
InvocationHelper getInvocationHelper()
Returns a reference to the currentInvocationHelperobject. 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 byInvocationHelpermay 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
InvocationHelperobject
-
-