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's getBean() method, allowing access to the required dependencies. By extending the ClassLoaderProvider 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
    • 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's getDependencies() 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 given Dependency 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 a BeanInitializer. 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 this DependencyProvider about the creation of a bean. This method has to be called by BeanProvider 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 bean
        provider - the BeanProvider responsible for this bean
      • setCreationBeanContext

        void setCreationBeanContext​(BeanContext context)
        Sets the BeanContext that is responsible for a BeanCreationEvent notification. This method can be used by implementations of the BeanContext 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 corresponding BeanCreationEvent per default has the wrapped context as its source, and also a BeanContextClient 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 a BeanCreationListener at the wrapped contexts. In the event handling method the setCreationBeanContext() can be called with the wrapping context as parameter. Then correct creation context is known and can also be passed to a BeanContextClient.
        Parameters:
        context - the BeanContext responsible for a bean creation
      • getInvocationHelper

        InvocationHelper getInvocationHelper()
        Returns a reference to the current InvocationHelper 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 by InvocationHelper 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