org.codehaus.groovy.grails.commons.spring
Class DefaultRuntimeSpringConfiguration

java.lang.Object
  extended by org.codehaus.groovy.grails.commons.spring.DefaultRuntimeSpringConfiguration
All Implemented Interfaces:
RuntimeSpringConfiguration
Direct Known Subclasses:
WebRuntimeSpringConfiguration

public class DefaultRuntimeSpringConfiguration
extends Object
implements RuntimeSpringConfiguration

A programmable runtime Spring configuration that allows a spring ApplicationContext to be constructed at runtime Credit must go to Solomon Duskis and the article: http://jroller.com/page/Solomon?entry=programmatic_configuration_in_spring

Since:
0.3
Author:
Graeme

Field Summary
protected  ClassLoader classLoader
           
protected  GenericApplicationContext context
           
protected  ApplicationContext parent
           
 
Constructor Summary
DefaultRuntimeSpringConfiguration()
           
DefaultRuntimeSpringConfiguration(ApplicationContext parent)
           
DefaultRuntimeSpringConfiguration(ApplicationContext parent, ClassLoader cl)
           
 
Method Summary
 BeanConfiguration addAbstractBean(String name)
          Adds an abstract bean and returns the BeanConfiguration instance
 void addAlias(String alias, String beanName)
          Adds an alias to a given bean name
 void addBeanConfiguration(String beanName, BeanConfiguration beanConfiguration)
          Adds a bean configuration to the list of beans to be created
 void addBeanDefinition(String name, BeanDefinition bd)
          Adds a Spring BeanDefinition.
 BeanConfiguration addPrototypeBean(String name)
          Adds an empty prototype bean configuration
 BeanConfiguration addPrototypeBean(String name, Class clazz)
          Adds a prototype bean definition
 BeanConfiguration addSingletonBean(String name)
          Adds an empty singleton bean configuration
 BeanConfiguration addSingletonBean(String name, Class clazz)
          Adds a singleton bean definition
 BeanConfiguration addSingletonBean(String name, Class clazz, Collection args)
          Creates a new singleton bean and adds it to the list of bean references
 boolean containsBean(String name)
          Returns whether the runtime spring config contains the specified bean
protected  GenericApplicationContext createApplicationContext(ApplicationContext parent)
          Creates the ApplicationContext instance.
 AbstractBeanDefinition createBeanDefinition(String name)
          Creates and returns the BeanDefinition that is regsitered within the given name or returns null
 BeanConfiguration createPrototypeBean(String name)
          Creates a new prototype bean configuration.
 BeanConfiguration createSingletonBean(Class clazz)
          Creates a singleton bean configuration.
 BeanConfiguration createSingletonBean(Class clazz, Collection constructorArguments)
          Creates a singleton bean configuration.
 BeanConfiguration createSingletonBean(String name)
          Creates a new singleton bean configuration.
 ApplicationContext getApplicationContext()
          Retrieves the application context from the current state
 BeanConfiguration getBeanConfig(String name)
          Returns the BeanConfiguration for the specified name
 BeanDefinition getBeanDefinition(String beanName)
          Obtains a BeanDefinition instance for the given beanName
 List getBeanNames()
           
 ApplicationContext getUnrefreshedApplicationContext()
           
protected  void initialiseApplicationContext()
          Initialises the ApplicationContext instance
 void registerBeansWithConfig(RuntimeSpringConfiguration targetSpringConfig)
          Registers the beans held within this RuntimeSpringConfiguration instance with the given RuntimeSpringConfiguration
 void registerBeansWithContext(GenericApplicationContext applicationContext)
          Registers the beans held within this RuntimeSpringConfiguration instance with the given ApplicationContext
 void registerBeansWithRegistry(BeanDefinitionRegistry registry)
          Registers the beans held within this RuntimeSpringConfiguration instance with the given BeanDefinitionRegistry
 void registerPostProcessor(BeanFactoryPostProcessor processor)
          Registers a bean factory post processor with the context
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

context

protected GenericApplicationContext context

parent

protected ApplicationContext parent

classLoader

protected ClassLoader classLoader
Constructor Detail

DefaultRuntimeSpringConfiguration

public DefaultRuntimeSpringConfiguration()

DefaultRuntimeSpringConfiguration

public DefaultRuntimeSpringConfiguration(ApplicationContext parent)

DefaultRuntimeSpringConfiguration

public DefaultRuntimeSpringConfiguration(ApplicationContext parent,
                                         ClassLoader cl)
Method Detail

createApplicationContext

protected GenericApplicationContext createApplicationContext(ApplicationContext parent)
Creates the ApplicationContext instance. Subclasses can override to customise the used ApplicationContext

Parameters:
parent - The parent ApplicationContext instance. Can be null.
Returns:
An instance of GenericApplicationContext

initialiseApplicationContext

protected void initialiseApplicationContext()
Initialises the ApplicationContext instance


addSingletonBean

public BeanConfiguration addSingletonBean(String name,
                                          Class clazz)
Description copied from interface: RuntimeSpringConfiguration
Adds a singleton bean definition

Specified by:
addSingletonBean in interface RuntimeSpringConfiguration
Parameters:
name - The name of the bean
clazz - The class of the bean
Returns:
A BeanConfiguration instance

addPrototypeBean

public BeanConfiguration addPrototypeBean(String name,
                                          Class clazz)
Description copied from interface: RuntimeSpringConfiguration
Adds a prototype bean definition

Specified by:
addPrototypeBean in interface RuntimeSpringConfiguration
Parameters:
name - The name of the bean
clazz - The class of the bean
Returns:
A BeanConfiguration instance

getApplicationContext

public ApplicationContext getApplicationContext()
Description copied from interface: RuntimeSpringConfiguration
Retrieves the application context from the current state

Specified by:
getApplicationContext in interface RuntimeSpringConfiguration
Returns:
The ApplicationContext instance

getUnrefreshedApplicationContext

public ApplicationContext getUnrefreshedApplicationContext()
Specified by:
getUnrefreshedApplicationContext in interface RuntimeSpringConfiguration

addSingletonBean

public BeanConfiguration addSingletonBean(String name)
Description copied from interface: RuntimeSpringConfiguration
Adds an empty singleton bean configuration

Specified by:
addSingletonBean in interface RuntimeSpringConfiguration
Parameters:
name - The name of the singleton bean
Returns:
A BeanConfiguration instance

createSingletonBean

public BeanConfiguration createSingletonBean(Class clazz)
Description copied from interface: RuntimeSpringConfiguration
Creates a singleton bean configuration. Differs from addSingletonBean in that it doesn't add the bean to the list of bean references. Hence should be used for creating nested beans

Specified by:
createSingletonBean in interface RuntimeSpringConfiguration
Returns:
A BeanConfiguration instance

addSingletonBean

public BeanConfiguration addSingletonBean(String name,
                                          Class clazz,
                                          Collection args)
Description copied from interface: RuntimeSpringConfiguration
Creates a new singleton bean and adds it to the list of bean references

Specified by:
addSingletonBean in interface RuntimeSpringConfiguration
Parameters:
name - The name of the bean
clazz - The class of the bean
args - The constructor arguments of the bean
Returns:
A BeanConfiguration instance

addPrototypeBean

public BeanConfiguration addPrototypeBean(String name)
Description copied from interface: RuntimeSpringConfiguration
Adds an empty prototype bean configuration

Specified by:
addPrototypeBean in interface RuntimeSpringConfiguration
Parameters:
name - The name of the prototype bean
Returns:
A BeanConfiguration instance

createSingletonBean

public BeanConfiguration createSingletonBean(Class clazz,
                                             Collection constructorArguments)
Description copied from interface: RuntimeSpringConfiguration
Creates a singleton bean configuration. Differs from addSingletonBean in that it doesn't add the bean to the list of bean references. Hence should be used for creating nested beans

Specified by:
createSingletonBean in interface RuntimeSpringConfiguration
Parameters:
clazz - The bean class
constructorArguments - The constructor arguments
Returns:
A BeanConfiguration instance

createPrototypeBean

public BeanConfiguration createPrototypeBean(String name)
Description copied from interface: RuntimeSpringConfiguration
Creates a new prototype bean configuration. Differs from addPrototypeBean in that it doesn't add the bean to the list of bean references to be created via the getApplicationContext() method, hence can be used for creating nested beans

Specified by:
createPrototypeBean in interface RuntimeSpringConfiguration
Parameters:
name - The bean name
Returns:
A BeanConfiguration instance

createSingletonBean

public BeanConfiguration createSingletonBean(String name)
Description copied from interface: RuntimeSpringConfiguration
Creates a new singleton bean configuration. Differs from addSingletonBean in that it doesn't add the bean to the list of bean references to be created via the getApplicationContext() method, hence can be used for creating nested beans

Specified by:
createSingletonBean in interface RuntimeSpringConfiguration
Parameters:
name - The bean name
Returns:
A BeanConfiguration instance

addBeanConfiguration

public void addBeanConfiguration(String beanName,
                                 BeanConfiguration beanConfiguration)
Description copied from interface: RuntimeSpringConfiguration
Adds a bean configuration to the list of beans to be created

Specified by:
addBeanConfiguration in interface RuntimeSpringConfiguration
Parameters:
beanName - The name of the bean in the context
beanConfiguration - The BeanConfiguration instance

addBeanDefinition

public void addBeanDefinition(String name,
                              BeanDefinition bd)
Description copied from interface: RuntimeSpringConfiguration
Adds a Spring BeanDefinition. Differs from BeanConfiguration which is a factory class for creating BeanDefinition instances

Specified by:
addBeanDefinition in interface RuntimeSpringConfiguration
Parameters:
name - The name of the bean
bd - The BeanDefinition instance

containsBean

public boolean containsBean(String name)
Description copied from interface: RuntimeSpringConfiguration
Returns whether the runtime spring config contains the specified bean

Specified by:
containsBean in interface RuntimeSpringConfiguration
Parameters:
name - The bean name
Returns:
True if it does

getBeanConfig

public BeanConfiguration getBeanConfig(String name)
Description copied from interface: RuntimeSpringConfiguration
Returns the BeanConfiguration for the specified name

Specified by:
getBeanConfig in interface RuntimeSpringConfiguration
Parameters:
name - The name of the bean configuration
Returns:
The BeanConfiguration

createBeanDefinition

public AbstractBeanDefinition createBeanDefinition(String name)
Description copied from interface: RuntimeSpringConfiguration
Creates and returns the BeanDefinition that is regsitered within the given name or returns null

Specified by:
createBeanDefinition in interface RuntimeSpringConfiguration
Parameters:
name - The name of the bean definition
Returns:
A BeanDefinition

registerPostProcessor

public void registerPostProcessor(BeanFactoryPostProcessor processor)
Description copied from interface: RuntimeSpringConfiguration
Registers a bean factory post processor with the context

Specified by:
registerPostProcessor in interface RuntimeSpringConfiguration
Parameters:
processor - The BeanFactoryPostProcessor instance

getBeanNames

public List getBeanNames()
Specified by:
getBeanNames in interface RuntimeSpringConfiguration

registerBeansWithContext

public void registerBeansWithContext(GenericApplicationContext applicationContext)
Description copied from interface: RuntimeSpringConfiguration
Registers the beans held within this RuntimeSpringConfiguration instance with the given ApplicationContext

Specified by:
registerBeansWithContext in interface RuntimeSpringConfiguration
Parameters:
applicationContext - The ApplicationContext instance

registerBeansWithRegistry

public void registerBeansWithRegistry(BeanDefinitionRegistry registry)
Description copied from interface: RuntimeSpringConfiguration
Registers the beans held within this RuntimeSpringConfiguration instance with the given BeanDefinitionRegistry

Specified by:
registerBeansWithRegistry in interface RuntimeSpringConfiguration
Parameters:
registry - The BeanDefinitionRegistry instance

registerBeansWithConfig

public void registerBeansWithConfig(RuntimeSpringConfiguration targetSpringConfig)
Description copied from interface: RuntimeSpringConfiguration
Registers the beans held within this RuntimeSpringConfiguration instance with the given RuntimeSpringConfiguration

Specified by:
registerBeansWithConfig in interface RuntimeSpringConfiguration
Parameters:
targetSpringConfig - The RuntimeSpringConfiguration instance

addAbstractBean

public BeanConfiguration addAbstractBean(String name)
Adds an abstract bean and returns the BeanConfiguration instance

Specified by:
addAbstractBean in interface RuntimeSpringConfiguration
Parameters:
name - The name of the bean
Returns:
The BeanConfiguration object

addAlias

public void addAlias(String alias,
                     String beanName)
Description copied from interface: RuntimeSpringConfiguration
Adds an alias to a given bean name

Specified by:
addAlias in interface RuntimeSpringConfiguration
Parameters:
alias - The alias
beanName - The bean

getBeanDefinition

public BeanDefinition getBeanDefinition(String beanName)
Description copied from interface: RuntimeSpringConfiguration
Obtains a BeanDefinition instance for the given beanName

Specified by:
getBeanDefinition in interface RuntimeSpringConfiguration
Parameters:
beanName - The beanName
Returns:
The BeanDefinition or null if it doesn't exit


Copyright (c) 2005-2009 The Grails project