The Spring Framework

org.springframework.beans.factory.support
Class ConstructorResolver

java.lang.Object
  extended by org.springframework.beans.factory.support.ConstructorResolver

abstract class ConstructorResolver
extends Object

Helper class for resolving constructors and factory methods. Performs constructor resolution through argument matching.

Works on an AbstractBeanFactory and an InstantiationStrategy. Used by AbstractAutowireCapableBeanFactory.

Since:
2.0
Author:
Juergen Hoeller
See Also:
autowireConstructor(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition), instantiateUsingFactoryMethod(java.lang.String, org.springframework.beans.factory.support.RootBeanDefinition, java.lang.Object[]), AbstractAutowireCapableBeanFactory

Field Summary
protected  Log logger
          Logger available to subclasses
 
Constructor Summary
ConstructorResolver(AbstractBeanFactory beanFactory, InstantiationStrategy instantiationStrategy)
          Create a new ConstructorResolver for the given factory and instantiation strategy.
 
Method Summary
protected  BeanWrapper autowireConstructor(String beanName, RootBeanDefinition mergedBeanDefinition)
          "autowire constructor" (with constructor arguments by type) behavior.
protected abstract  Map findMatchingBeans(Class requiredType)
          Find bean instances that match the required type.
 BeanWrapper instantiateUsingFactoryMethod(String beanName, RootBeanDefinition mergedBeanDefinition, Object[] explicitArgs)
          Instantiate the bean using a named factory method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final Log logger
Logger available to subclasses

Constructor Detail

ConstructorResolver

public ConstructorResolver(AbstractBeanFactory beanFactory,
                           InstantiationStrategy instantiationStrategy)
Create a new ConstructorResolver for the given factory and instantiation strategy.

Parameters:
beanFactory - the BeanFactory to work with
instantiationStrategy - the instantiate strategy for creating bean instances
Method Detail

autowireConstructor

protected BeanWrapper autowireConstructor(String beanName,
                                          RootBeanDefinition mergedBeanDefinition)
                                   throws BeansException
"autowire constructor" (with constructor arguments by type) behavior. Also applied if explicit constructor argument values are specified, matching all remaining arguments with beans from the bean factory.

This corresponds to constructor injection: In this mode, a Spring bean factory is able to host components that expect constructor-based dependency resolution.

Parameters:
beanName - name of the bean
mergedBeanDefinition - the bean definition for the bean
Returns:
BeanWrapper for the new instance
Throws:
BeansException

instantiateUsingFactoryMethod

public BeanWrapper instantiateUsingFactoryMethod(String beanName,
                                                 RootBeanDefinition mergedBeanDefinition,
                                                 Object[] explicitArgs)
                                          throws BeansException
Instantiate the bean using a named factory method. The method may be static, if the mergedBeanDefinition parameter specifies a class, rather than a factoryBean, or an instance variable on a factory object itself configured using Dependency Injection.

Implementation requires iterating over the static or instance methods with the name specified in the RootBeanDefinition (the method may be overloaded) and trying to match with the parameters. We don't have the types attached to constructor args, so trial and error is the only way to go here. The explicitArgs array may contain argument values passed in programmatically via the corresponding getBean method.

Parameters:
beanName - name of the bean
mergedBeanDefinition - the bean definition for the bean
explicitArgs - argument values passed in programmatically via the getBean method, or null if none (-> use constructor argument values from bean definition)
Returns:
BeanWrapper for the new instance
Throws:
BeansException

findMatchingBeans

protected abstract Map findMatchingBeans(Class requiredType)
                                  throws BeansException
Find bean instances that match the required type. Called by autowiring. If a subclass cannot obtain information about bean names by type, a corresponding exception should be thrown.

Parameters:
requiredType - the type of the beans to look up
Returns:
a Map of bean names and bean instances that match the required type, or null if none found
Throws:
BeansException - in case of errors

The Spring Framework

Copyright © 2002-2006 The Spring Framework.