Class ConstructorBeanProvider

  • All Implemented Interfaces:
    BeanProvider

    public class ConstructorBeanProvider
    extends SimpleBeanProvider

    A simple bean provider that creates new bean instances by invoking a constructor.

    This BeanProvider class is initialized with a ConstructorInvocation object. The getBean() method will trigger this invocation object and return the newly created instance.

    The ConstructorInvocation also determines the dependencies of this bean provider: these are the parameters to be passed to the constructor, which can be arbitrary other beans defined in the current bean store.

    A ConstructorBeanProvider is intended to be used together with another life-cycle-aware bean provider. It will then be used for creating new bean instances while its owning bean provider is responsible for further initialization and life-cycle support.

    Version:
    $Id: ConstructorBeanProvider.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    • Constructor Detail

      • ConstructorBeanProvider

        public ConstructorBeanProvider​(ConstructorInvocation ctorinv)
        Creates a new instance of ConstructorBeanProvider and initializes it with the constructor invocation to be called. This object specifies the constructor to be invoked.
        Parameters:
        ctorinv - the ConstructorInvocation (must not be null)
        Throws:
        IllegalArgumentException - if the constructor invocation is undefined
    • Method Detail

      • getInvocation

        public ConstructorInvocation getInvocation()
        Returns the ConstructorInvocation object that determines the constructor to be invoked.
        Returns:
        the used constructor invocation
      • getBean

        public Object getBean​(DependencyProvider dependencyProvider)
        Returns the bean managed by this provider. This implementation will invoke the specified constructor for creating the new bean instance.
        Parameters:
        dependencyProvider - the dependency provider
        Returns:
        the newly created bean instance
        Throws:
        InjectionException - if an error occurs when creating the bean
      • getBeanClass

        public Class<?> getBeanClass​(DependencyProvider dependencyProvider)
        Returns the class of the managed bean. This class is also determined by the constructor invocation.
        Parameters:
        dependencyProvider - the dependency provider
        Returns:
        the class of the managed bean
      • getDependencies

        public Set<Dependency> getDependencies()
        Returns the dependencies of this bean provider. This implementation returns the dependencies required for the constructor invocation (i.e. the parameters to be passed to the constructor).
        Specified by:
        getDependencies in interface BeanProvider
        Overrides:
        getDependencies in class SimpleBeanProvider
        Returns:
        a set with the dependencies of this bean provider
        See Also:
        Dependency
      • toString

        public String toString()
        Returns a string representation of this object. This string also contains information about the constructor that will be invoked.
        Overrides:
        toString in class Object
        Returns:
        a string for this object