Package org.grails.spring
Class DefaultRuntimeSpringConfiguration
- java.lang.Object
-
- org.grails.spring.DefaultRuntimeSpringConfiguration
-
- All Implemented Interfaces:
RuntimeSpringConfiguration
public class DefaultRuntimeSpringConfiguration extends java.lang.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
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>aliasesprotected org.springframework.beans.factory.ListableBeanFactorybeanFactoryprotected java.lang.ClassLoaderclassLoaderprotected org.springframework.context.support.GenericApplicationContextcontextprotected org.springframework.context.ApplicationContextparent
-
Constructor Summary
Constructors Constructor Description DefaultRuntimeSpringConfiguration()DefaultRuntimeSpringConfiguration(org.springframework.context.ApplicationContext parent)DefaultRuntimeSpringConfiguration(org.springframework.context.ApplicationContext parent, java.lang.ClassLoader cl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description BeanConfigurationaddAbstractBean(java.lang.String name)\ Adds an abstract bean definition to the bean factory and returns the BeanConfiguration object.voidaddAlias(java.lang.String alias, java.lang.String beanName)Adds an alias to a given bean name.voidaddBeanConfiguration(java.lang.String beanName, BeanConfiguration beanConfiguration)Adds a bean configuration to the list of beans to be created.voidaddBeanDefinition(java.lang.String name, org.springframework.beans.factory.config.BeanDefinition bd)Adds a Spring BeanDefinition.BeanConfigurationaddPrototypeBean(java.lang.String name)Adds an empty prototype bean configuration.BeanConfigurationaddPrototypeBean(java.lang.String name, java.lang.Class clazz)Adds a prototype bean definition.BeanConfigurationaddSingletonBean(java.lang.String name)Adds an empty singleton bean configuration.BeanConfigurationaddSingletonBean(java.lang.String name, java.lang.Class clazz)Adds a singleton bean definition.BeanConfigurationaddSingletonBean(java.lang.String name, java.lang.Class clazz, java.util.Collection args)Creates a new singleton bean and adds it to the list of bean references.booleancontainsBean(java.lang.String name)Returns whether the runtime spring config contains the specified bean.protected org.springframework.context.support.GenericApplicationContextcreateApplicationContext(org.springframework.context.ApplicationContext parentCtx)Creates the ApplicationContext instance.org.springframework.beans.factory.support.AbstractBeanDefinitioncreateBeanDefinition(java.lang.String name)Creates and returns the BeanDefinition that is regsitered within the given name or returns null.BeanConfigurationcreatePrototypeBean(java.lang.String name)Creates a new prototype bean configuration.BeanConfigurationcreateSingletonBean(java.lang.Class clazz)Creates a singleton bean configuration.BeanConfigurationcreateSingletonBean(java.lang.Class clazz, java.util.Collection constructorArguments)Creates a singleton bean configuration.BeanConfigurationcreateSingletonBean(java.lang.String name)Creates a new singleton bean configuration.org.springframework.context.ApplicationContextgetApplicationContext()Retrieves the application context from the current state.BeanConfigurationgetBeanConfig(java.lang.String name)Returns the BeanConfiguration for the specified name.org.springframework.beans.factory.config.BeanDefinitiongetBeanDefinition(java.lang.String beanName)Obtains a BeanDefinition instance for the given beanName.java.util.List<java.lang.String>getBeanNames()org.springframework.context.ApplicationContextgetUnrefreshedApplicationContext()protected voidinitialiseApplicationContext()Initialises the ApplicationContext instance.voidregisterBeansWithConfig(RuntimeSpringConfiguration targetSpringConfig)Registers the beans held within this RuntimeSpringConfiguration instance with the given RuntimeSpringConfiguration.voidregisterBeansWithContext(org.springframework.context.support.GenericApplicationContext applicationContext)Registers the beans held within this RuntimeSpringConfiguration instance with the given ApplicationContext.voidregisterBeansWithRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)Registers the beans held within this RuntimeSpringConfiguration instance with the given BeanDefinitionRegistry.voidregisterPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor processor)Registers a bean factory post processor with the context.voidsetBeanFactory(org.springframework.beans.factory.ListableBeanFactory beanFactory)Sets the BeanFactory implementation to use.
-
-
-
Field Detail
-
context
protected org.springframework.context.support.GenericApplicationContext context
-
parent
protected org.springframework.context.ApplicationContext parent
-
classLoader
protected java.lang.ClassLoader classLoader
-
aliases
protected java.util.Map<java.lang.String,java.util.List<java.lang.String>> aliases
-
beanFactory
protected org.springframework.beans.factory.ListableBeanFactory beanFactory
-
-
Constructor Detail
-
DefaultRuntimeSpringConfiguration
public DefaultRuntimeSpringConfiguration()
-
DefaultRuntimeSpringConfiguration
public DefaultRuntimeSpringConfiguration(org.springframework.context.ApplicationContext parent)
-
DefaultRuntimeSpringConfiguration
public DefaultRuntimeSpringConfiguration(org.springframework.context.ApplicationContext parent, java.lang.ClassLoader cl)
-
-
Method Detail
-
createApplicationContext
protected org.springframework.context.support.GenericApplicationContext createApplicationContext(org.springframework.context.ApplicationContext parentCtx)
Creates the ApplicationContext instance. Subclasses can override to customise the used ApplicationContext- Parameters:
parentCtx- The parent ApplicationContext instance. Can be null.- Returns:
- An instance of GenericApplicationContext
-
initialiseApplicationContext
protected void initialiseApplicationContext()
Initialises the ApplicationContext instance.
-
addSingletonBean
public BeanConfiguration addSingletonBean(java.lang.String name, java.lang.Class clazz)
Description copied from interface:RuntimeSpringConfigurationAdds a singleton bean definition.- Specified by:
addSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the beanclazz- The class of the bean- Returns:
- A BeanConfiguration instance
-
addPrototypeBean
public BeanConfiguration addPrototypeBean(java.lang.String name, java.lang.Class clazz)
Description copied from interface:RuntimeSpringConfigurationAdds a prototype bean definition.- Specified by:
addPrototypeBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the beanclazz- The class of the bean- Returns:
- A BeanConfiguration instance
-
getApplicationContext
public org.springframework.context.ApplicationContext getApplicationContext()
Description copied from interface:RuntimeSpringConfigurationRetrieves the application context from the current state.- Specified by:
getApplicationContextin interfaceRuntimeSpringConfiguration- Returns:
- The ApplicationContext instance
-
getUnrefreshedApplicationContext
public org.springframework.context.ApplicationContext getUnrefreshedApplicationContext()
- Specified by:
getUnrefreshedApplicationContextin interfaceRuntimeSpringConfiguration
-
addSingletonBean
public BeanConfiguration addSingletonBean(java.lang.String name)
Description copied from interface:RuntimeSpringConfigurationAdds an empty singleton bean configuration.- Specified by:
addSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the singleton bean- Returns:
- A BeanConfiguration instance
-
createSingletonBean
public BeanConfiguration createSingletonBean(java.lang.Class clazz)
Description copied from interface:RuntimeSpringConfigurationCreates 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:
createSingletonBeanin interfaceRuntimeSpringConfiguration- Returns:
- A BeanConfiguration instance
-
addSingletonBean
public BeanConfiguration addSingletonBean(java.lang.String name, java.lang.Class clazz, java.util.Collection args)
Description copied from interface:RuntimeSpringConfigurationCreates a new singleton bean and adds it to the list of bean references.- Specified by:
addSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the beanclazz- The class of the beanargs- The constructor arguments of the bean- Returns:
- A BeanConfiguration instance
-
addPrototypeBean
public BeanConfiguration addPrototypeBean(java.lang.String name)
Description copied from interface:RuntimeSpringConfigurationAdds an empty prototype bean configuration.- Specified by:
addPrototypeBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the prototype bean- Returns:
- A BeanConfiguration instance
-
createSingletonBean
public BeanConfiguration createSingletonBean(java.lang.Class clazz, java.util.Collection constructorArguments)
Description copied from interface:RuntimeSpringConfigurationCreates 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:
createSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
clazz- The bean classconstructorArguments- The constructor arguments- Returns:
- A BeanConfiguration instance
-
createPrototypeBean
public BeanConfiguration createPrototypeBean(java.lang.String name)
Description copied from interface:RuntimeSpringConfigurationCreates 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:
createPrototypeBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The bean name- Returns:
- A BeanConfiguration instance
-
createSingletonBean
public BeanConfiguration createSingletonBean(java.lang.String name)
Description copied from interface:RuntimeSpringConfigurationCreates 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:
createSingletonBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The bean name- Returns:
- A BeanConfiguration instance
-
addBeanConfiguration
public void addBeanConfiguration(java.lang.String beanName, BeanConfiguration beanConfiguration)Description copied from interface:RuntimeSpringConfigurationAdds a bean configuration to the list of beans to be created.- Specified by:
addBeanConfigurationin interfaceRuntimeSpringConfiguration- Parameters:
beanName- The name of the bean in the contextbeanConfiguration- The BeanConfiguration instance
-
addBeanDefinition
public void addBeanDefinition(java.lang.String name, org.springframework.beans.factory.config.BeanDefinition bd)Description copied from interface:RuntimeSpringConfigurationAdds a Spring BeanDefinition. Differs from BeanConfiguration which is a factory class for creating BeanDefinition instances- Specified by:
addBeanDefinitionin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the beanbd- The BeanDefinition instance
-
containsBean
public boolean containsBean(java.lang.String name)
Description copied from interface:RuntimeSpringConfigurationReturns whether the runtime spring config contains the specified bean.- Specified by:
containsBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The bean name- Returns:
- true if it does
-
getBeanConfig
public BeanConfiguration getBeanConfig(java.lang.String name)
Description copied from interface:RuntimeSpringConfigurationReturns the BeanConfiguration for the specified name.- Specified by:
getBeanConfigin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the bean configuration- Returns:
- The BeanConfiguration
-
createBeanDefinition
public org.springframework.beans.factory.support.AbstractBeanDefinition createBeanDefinition(java.lang.String name)
Description copied from interface:RuntimeSpringConfigurationCreates and returns the BeanDefinition that is regsitered within the given name or returns null.- Specified by:
createBeanDefinitionin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the bean definition- Returns:
- A BeanDefinition
-
registerPostProcessor
public void registerPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor processor)
Description copied from interface:RuntimeSpringConfigurationRegisters a bean factory post processor with the context.- Specified by:
registerPostProcessorin interfaceRuntimeSpringConfiguration- Parameters:
processor- The BeanFactoryPostProcessor instance
-
getBeanNames
public java.util.List<java.lang.String> getBeanNames()
- Specified by:
getBeanNamesin interfaceRuntimeSpringConfiguration
-
registerBeansWithContext
public void registerBeansWithContext(org.springframework.context.support.GenericApplicationContext applicationContext)
Description copied from interface:RuntimeSpringConfigurationRegisters the beans held within this RuntimeSpringConfiguration instance with the given ApplicationContext.- Specified by:
registerBeansWithContextin interfaceRuntimeSpringConfiguration- Parameters:
applicationContext- The ApplicationContext instance
-
registerBeansWithRegistry
public void registerBeansWithRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry registry)
Description copied from interface:RuntimeSpringConfigurationRegisters the beans held within this RuntimeSpringConfiguration instance with the given BeanDefinitionRegistry.- Specified by:
registerBeansWithRegistryin interfaceRuntimeSpringConfiguration- Parameters:
registry- The BeanDefinitionRegistry instance
-
registerBeansWithConfig
public void registerBeansWithConfig(RuntimeSpringConfiguration targetSpringConfig)
Description copied from interface:RuntimeSpringConfigurationRegisters the beans held within this RuntimeSpringConfiguration instance with the given RuntimeSpringConfiguration.- Specified by:
registerBeansWithConfigin interfaceRuntimeSpringConfiguration- Parameters:
targetSpringConfig- The RuntimeSpringConfiguration instance
-
addAbstractBean
public BeanConfiguration addAbstractBean(java.lang.String name)
Description copied from interface:RuntimeSpringConfiguration\ Adds an abstract bean definition to the bean factory and returns the BeanConfiguration object.- Specified by:
addAbstractBeanin interfaceRuntimeSpringConfiguration- Parameters:
name- The name of the bean- Returns:
- The BeanConfiguration object
-
addAlias
public void addAlias(java.lang.String alias, java.lang.String beanName)Description copied from interface:RuntimeSpringConfigurationAdds an alias to a given bean name.- Specified by:
addAliasin interfaceRuntimeSpringConfiguration- Parameters:
alias- The aliasbeanName- The bean
-
getBeanDefinition
public org.springframework.beans.factory.config.BeanDefinition getBeanDefinition(java.lang.String beanName)
Description copied from interface:RuntimeSpringConfigurationObtains a BeanDefinition instance for the given beanName.- Specified by:
getBeanDefinitionin interfaceRuntimeSpringConfiguration- Parameters:
beanName- The beanName- Returns:
- The BeanDefinition or null if it doesn't exit
-
setBeanFactory
public void setBeanFactory(org.springframework.beans.factory.ListableBeanFactory beanFactory)
Description copied from interface:RuntimeSpringConfigurationSets the BeanFactory implementation to use.- Specified by:
setBeanFactoryin interfaceRuntimeSpringConfiguration- Parameters:
beanFactory- The BeanFactory implementation
-
-