Class ConstructorBeanProvider
- java.lang.Object
-
- net.sf.jguiraffe.di.impl.providers.SimpleBeanProvider
-
- net.sf.jguiraffe.di.impl.providers.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 aConstructorInvocation
object. ThegetBean()
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 Summary
Constructors Constructor Description ConstructorBeanProvider(ConstructorInvocation ctorinv)
Creates a new instance ofConstructorBeanProvider
and initializes it with the constructor invocation to be called.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Object
getBean(DependencyProvider dependencyProvider)
Returns the bean managed by this provider.Class<?>
getBeanClass(DependencyProvider dependencyProvider)
Returns the class of the managed bean.Set<Dependency>
getDependencies()
Returns the dependencies of this bean provider.ConstructorInvocation
getInvocation()
Returns theConstructorInvocation
object that determines the constructor to be invoked.String
toString()
Returns a string representation of this object.-
Methods inherited from class net.sf.jguiraffe.di.impl.providers.SimpleBeanProvider
getLockID, isBeanAvailable, setLockID, shutdown
-
-
-
-
Constructor Detail
-
ConstructorBeanProvider
public ConstructorBeanProvider(ConstructorInvocation ctorinv)
Creates a new instance ofConstructorBeanProvider
and initializes it with the constructor invocation to be called. This object specifies the constructor to be invoked.- Parameters:
ctorinv
- theConstructorInvocation
(must not be null)- Throws:
IllegalArgumentException
- if the constructor invocation is undefined
-
-
Method Detail
-
getInvocation
public ConstructorInvocation getInvocation()
Returns theConstructorInvocation
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 interfaceBeanProvider
- Overrides:
getDependencies
in classSimpleBeanProvider
- Returns:
- a set with the dependencies of this bean provider
- See Also:
Dependency
-
-