org.springframework.config.java.process
Class ConfigurationProcessor

java.lang.Object
  extended by org.springframework.config.java.process.ConfigurationProcessor
All Implemented Interfaces:
InitializingBean, ResourceLoaderAware

public class ConfigurationProcessor
extends Object
implements InitializingBean, ResourceLoaderAware

For internal use only. Processes Configuration beans.

A Configuration bean contains bean definition methods annotated with the Bean annotation. The Configuration class itself may optionally be annotated with a Configuration annotation setting global defaults.

Bean creation methods may be public or protected.

Typically used for only one configuration class in a single BeanDefinitionRegistry.

Most of the actual work is performed by ConfigurationListeners, which makes the processing of this class extensible. ConfigurationListeners react to configuration methods and classes.

The process work on configurations created from classes but also object instances.

This class implements InitializingBean interface - remember to call InitializingBean.afterPropertiesSet() before any processing.

Author:
Rod Johnson, Costin Leau, Chris Beams
See Also:
ConfigurationListener

Field Summary
protected  Log log
           
 
Constructor Summary
ConfigurationProcessor(ConfigurableApplicationContext ac)
          Constructor taking an application context as parameter.
ConfigurationProcessor(ConfigurableListableBeanFactory clbf)
          Create a configuration processor.
 
Method Summary
 void addValueSource(ValueSource vs)
           
 void afterPropertiesSet()
          Called to avoid constructor changes every time a new configuration switch appears on this class.
protected  void generateBeanDefinitionFromBeanCreationMethod(ConfigurableListableBeanFactory beanFactory, String configurerBeanName, Class<?> configurerClass, String beanName, Method beanCreationMethod, Bean beanAnnotation)
          Generate the actual bean definition using the given method.
protected  void generateBeanDefinitions(String configurationBeanName, Class<?> configurationClass)
          Modify metadata by emitting new bean definitions based on the bean creation methods in this Java bytecode.
 BeanFactory getChildBeanFactory()
           
 ResourceLoader getResourceLoader()
           
static boolean isConfigurationClass(Class<?> candidateConfigurationClass)
          Check if the given class is a configuration.
 int processClass(Class<?> configurationClass)
          Generate bean definitions from a 'naked' configuration class.
 void registerBeanDefinition(String name, BeanDefinition bd, boolean hide)
           
 void registerSingleton(String name, Object o, boolean hide)
           
 void setBeanNamingStrategy(BeanNamingStrategy beanNamingStrategy)
          Optionally indicate the naming strategy used for creating the bean names during processing.
 void setConfigurationListenerRegistry(org.springframework.config.java.process.ConfigurationListenerRegistry configurationListenerRegistry)
          Optionally specify a custom subclass of ConfigurationListenerRegistry.
 void setResourceLoader(ResourceLoader resourceLoader)
          Optionally indicate the resourceLoader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected final Log log
Constructor Detail

ConfigurationProcessor

public ConfigurationProcessor(ConfigurableApplicationContext ac)
Constructor taking an application context as parameter. Suitable for programmatic use.

Parameters:
ac - application context in which the newly created bean definition will reside

ConfigurationProcessor

public ConfigurationProcessor(ConfigurableListableBeanFactory clbf)
Create a configuration processor. This is tied to an owning factory.

Parameters:
clbf - owning factory
Method Detail

setResourceLoader

public void setResourceLoader(ResourceLoader resourceLoader)
Optionally indicate the resourceLoader. If unspecified, DefaultResourceLoader will be used. will be used.

Specified by:
setResourceLoader in interface ResourceLoaderAware
Parameters:
resourceLoader -

getResourceLoader

public ResourceLoader getResourceLoader()

setBeanNamingStrategy

public void setBeanNamingStrategy(BeanNamingStrategy beanNamingStrategy)
Optionally indicate the naming strategy used for creating the bean names during processing. If unspecified a default, method-name-based strategy will be used.

Parameters:
beanNamingStrategy - bean naming strategy implementation

setConfigurationListenerRegistry

public void setConfigurationListenerRegistry(org.springframework.config.java.process.ConfigurationListenerRegistry configurationListenerRegistry)
Optionally specify a custom subclass of ConfigurationListenerRegistry. If unspecified, the default implementation will be used.

TODO: if ConfigurationListener is made internal, this configuration should be eliminated as well

Parameters:
configurationListenerRegistry -

addValueSource

public void addValueSource(ValueSource vs)

getChildBeanFactory

public BeanFactory getChildBeanFactory()

registerBeanDefinition

public void registerBeanDefinition(String name,
                                   BeanDefinition bd,
                                   boolean hide)

registerSingleton

public void registerSingleton(String name,
                              Object o,
                              boolean hide)

afterPropertiesSet

public void afterPropertiesSet()
Called to avoid constructor changes every time a new configuration switch appears on this class.

Specified by:
afterPropertiesSet in interface InitializingBean

processClass

public int processClass(Class<?> configurationClass)
                 throws BeanDefinitionStoreException
Generate bean definitions from a 'naked' configuration class.

Normally this method is used internally on inner classes however, it is possible to use it directly on classes that haven't been manually declared in the enclosing bean factory.

Parameters:
configurationClass - class containing @Configurable or @Bean annotation
Returns:
the number of bean definition generated (including the configuration)
Throws:
BeanDefinitionStoreException - if no bean definitions are found

generateBeanDefinitions

protected void generateBeanDefinitions(String configurationBeanName,
                                       Class<?> configurationClass)
Modify metadata by emitting new bean definitions based on the bean creation methods in this Java bytecode.

Parameters:
configurationBeanName - name of the bean containing the factory methods
configurationClass - enhanced configuration class

generateBeanDefinitionFromBeanCreationMethod

protected void generateBeanDefinitionFromBeanCreationMethod(ConfigurableListableBeanFactory beanFactory,
                                                            String configurerBeanName,
                                                            Class<?> configurerClass,
                                                            String beanName,
                                                            Method beanCreationMethod,
                                                            Bean beanAnnotation)
Generate the actual bean definition using the given method.

Parameters:
beanFactory - containing beanFactory
configurerBeanName - the configuration name
configurerClass - configuration class
beanCreationMethod - method creating the actual bean
beanAnnotation - the Bean annotation available on the creation method.

isConfigurationClass

public static boolean isConfigurationClass(Class<?> candidateConfigurationClass)
Check if the given class is a configuration.

Parameters:
candidateConfigurationClass - - must be non-abstract and be annotated with @Configuration and/or have at least one method annotated with @Bean


Copyright � 2005-2008 Spring Framework. All Rights Reserved.