|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovy.lang.GroovyObjectSupport grails.spring.BeanBuilder
public class BeanBuilder extends groovy.lang.GroovyObjectSupport
Runtime bean configuration wrapper. Like a Groovy builder, but more of a DSL for Spring configuration. Allows syntax like:
import org.hibernate.SessionFactory import org.apache.commons.dbcp.BasicDataSource BeanBuilder builder = new BeanBuilder() builder.beans { dataSource(BasicDataSource) { // <--- invokeMethod driverClassName = "org.hsqldb.jdbcDriver" url = "jdbc:hsqldb:mem:grailsDB" username = "sa" // <-- setProperty password = "" settings = [mynew:"setting"] } sessionFactory(SessionFactory) { dataSource = dataSource // <-- getProperty for retrieving refs } myService(MyService) { nestedBean = { AnotherBean bean-> // <-- setProperty with closure for nested bean dataSource = dataSource } } }
You can also use the Spring IO API to load resources containing beans defined as a Groovy script using either the constructors or the loadBeans(Resource[] resources) method
Constructor Summary | |
BeanBuilder()
|
|
BeanBuilder(java.lang.ClassLoader classLoader)
|
|
BeanBuilder(ApplicationContext parent)
|
|
BeanBuilder(ApplicationContext parent, java.lang.ClassLoader classLoader)
|
|
BeanBuilder(ApplicationContext parentCtx, RuntimeSpringConfiguration springConfig, java.lang.ClassLoader classLoader)
|
Method Summary | |
---|---|
protected boolean
|
addToDeferred(BeanConfiguration beanConfig, java.lang.String property, java.lang.Object newValue)
|
BeanBuilder
|
beans(groovy.lang.Closure c)
Defines a set of beans for the given block or closure. |
ApplicationContext
|
createApplicationContext()
Creates an ApplicationContext from the current state of the BeanBuilder |
protected DynamicElementReader
|
createDynamicElementReader(java.lang.String namespace, boolean decorator)
|
protected RuntimeSpringConfiguration
|
createRuntimeSpringConfiguration(ApplicationContext parent, java.lang.ClassLoader classLoader)
|
protected void
|
filterGStringReferences(Object[] constructorArgs)
|
protected void
|
finalizeDeferredProperties()
|
BeanDefinition
|
getBeanDefinition(java.lang.String name)
Retrieves a BeanDefinition for the given name |
java.util.Map
|
getBeanDefinitions()
Retrieves all BeanDefinitions for this BeanBuilder |
Log
|
getLog()
|
ApplicationContext
|
getParentCtx()
Retrieves the parent ApplicationContext |
java.lang.Object
|
getProperty(java.lang.String name)
This method overrides property retrieval in the scope of the BeanBuilder to either: |
RuntimeSpringConfiguration
|
getSpringConfig()
Retrieves the RuntimeSpringConfiguration instance used the the BeanBuilder |
void
|
importBeans(java.lang.String resourcePattern)
Imports Spring bean definitions from either XML or Groovy sources into the current bean builder instance |
protected void
|
initializeBeanBuilderForClassLoader(java.lang.ClassLoader classLoader)
|
protected void
|
initializeSpringConfig()
|
protected BeanBuilder
|
invokeBeanDefiningClosure(groovy.lang.Closure callable)
When an methods argument is only a closure it is a set of bean definitions |
protected BeanConfiguration
|
invokeBeanDefiningMethod(java.lang.String name, Object[] args)
This method is called when a bean definition node is called |
java.lang.Object
|
invokeMethod(java.lang.String name, java.lang.Object arg)
This method overrides method invocation to create beans for each method name that takes a class argument |
void
|
loadBeans(java.lang.String resourcePattern)
Takes a resource pattern as (@see org.springframework.core.io.support.PathMatchingResourcePatternResolver) This allows you load multiple bean resources in this single builder |
void
|
loadBeans(Resource resource)
Loads a single Resource into the bean builder |
void
|
loadBeans(Resource[] resources)
Loads a set of given beans |
protected java.lang.Object
|
manageListIfNecessary(java.lang.Object value)
Checks whether there are any runtime refs inside the list and converts it to a ManagedList if necessary |
protected java.lang.Object
|
manageMapIfNecessary(java.lang.Object value)
Checks whether there are any runtime refs inside a Map and converts it to a ManagedMap if necessary |
void
|
registerBeans(BeanDefinitionRegistry registry)
Register a set of beans with the given bean registry. |
void
|
registerBeans(RuntimeSpringConfiguration targetSpringConfig)
Registers bean definitions with another instance of RuntimeSpringConfiguration, overriding any beans in the target. |
protected java.util.List
|
resolveConstructorArguments(Object[] args, int start, int end)
|
void
|
setBinding(groovy.lang.Binding b)
Sets the binding (the variables available in the scope of the BeanBuilder) |
void
|
setClassLoader(java.lang.ClassLoader classLoader)
|
void
|
setNamespaceHandlerResolver(NamespaceHandlerResolver namespaceHandlerResolver)
|
void
|
setProperty(java.lang.String name, java.lang.Object value)
This method overrides property setting in the scope of the BeanBuilder to set properties on the current BeanConfiguration |
protected void
|
setPropertyOnBeanConfig(java.lang.String name, java.lang.Object value)
|
void
|
setResourcePatternResolver(ResourcePatternResolver resourcePatternResolver)
|
void
|
setSpringConfig(RuntimeSpringConfiguration springConfig)
Sets the runtime Spring configuration instance to use. |
protected Object[]
|
subarray(Object[] args, int i, int j)
|
void
|
xmlns(java.util.Map definition)
Defines an Spring namespace definition to use |
Methods inherited from class groovy.lang.GroovyObjectSupport | |
---|---|
groovy.lang.GroovyObjectSupport#setProperty(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#getProperty(java.lang.String), groovy.lang.GroovyObjectSupport#getMetaClass(), groovy.lang.GroovyObjectSupport#setMetaClass(groovy.lang.MetaClass), groovy.lang.GroovyObjectSupport#invokeMethod(java.lang.String, java.lang.Object), groovy.lang.GroovyObjectSupport#wait(), groovy.lang.GroovyObjectSupport#wait(long), groovy.lang.GroovyObjectSupport#wait(long, int), groovy.lang.GroovyObjectSupport#equals(java.lang.Object), groovy.lang.GroovyObjectSupport#toString(), groovy.lang.GroovyObjectSupport#hashCode(), groovy.lang.GroovyObjectSupport#getClass(), groovy.lang.GroovyObjectSupport#notify(), groovy.lang.GroovyObjectSupport#notifyAll() |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(), java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Constructor Detail |
---|
public BeanBuilder()
public BeanBuilder(java.lang.ClassLoader classLoader)
public BeanBuilder(ApplicationContext parent)
public BeanBuilder(ApplicationContext parent, java.lang.ClassLoader classLoader)
public BeanBuilder(ApplicationContext parentCtx, RuntimeSpringConfiguration springConfig, java.lang.ClassLoader classLoader)
Method Detail |
---|
protected boolean addToDeferred(BeanConfiguration beanConfig, java.lang.String property, java.lang.Object newValue)
public BeanBuilder beans(groovy.lang.Closure c)
c
- The block or closure
public ApplicationContext createApplicationContext()
protected DynamicElementReader createDynamicElementReader(java.lang.String namespace, boolean decorator)
protected RuntimeSpringConfiguration createRuntimeSpringConfiguration(ApplicationContext parent, java.lang.ClassLoader classLoader)
protected void filterGStringReferences(Object[] constructorArgs)
protected void finalizeDeferredProperties()
public BeanDefinition getBeanDefinition(java.lang.String name)
name
- The bean definition
public java.util.Map getBeanDefinitions()
public Log getLog()
public ApplicationContext getParentCtx()
public java.lang.Object getProperty(java.lang.String name)
public RuntimeSpringConfiguration getSpringConfig()
public void importBeans(java.lang.String resourcePattern)
resourcePattern
- The resource pattern
protected void initializeBeanBuilderForClassLoader(java.lang.ClassLoader classLoader)
protected void initializeSpringConfig()
protected BeanBuilder invokeBeanDefiningClosure(groovy.lang.Closure callable)
callable
- The closure argument
protected BeanConfiguration invokeBeanDefiningMethod(java.lang.String name, Object[] args)
name
- The name of the bean to defineargs
- The arguments to the bean. The first argument is the class name, the last argument is sometimes a closure. All
the arguments in between are constructor arguments
public java.lang.Object invokeMethod(java.lang.String name, java.lang.Object arg)
public void loadBeans(java.lang.String resourcePattern)
resourcePattern
- The resource pattern
public void loadBeans(Resource resource)
resource
- The resource to load
public void loadBeans(Resource[] resources)
resources
- The resources to load
protected java.lang.Object manageListIfNecessary(java.lang.Object value)
value
- The object that represents the list
protected java.lang.Object manageMapIfNecessary(java.lang.Object value)
value
- The current map
public void registerBeans(BeanDefinitionRegistry registry)
public void registerBeans(RuntimeSpringConfiguration targetSpringConfig)
targetSpringConfig
- The RuntimeSpringConfiguration object
protected java.util.List resolveConstructorArguments(Object[] args, int start, int end)
public void setBinding(groovy.lang.Binding b)
b
- The Binding instance
public void setClassLoader(java.lang.ClassLoader classLoader)
public void setNamespaceHandlerResolver(NamespaceHandlerResolver namespaceHandlerResolver)
public void setProperty(java.lang.String name, java.lang.Object value)
protected void setPropertyOnBeanConfig(java.lang.String name, java.lang.Object value)
public void setResourcePatternResolver(ResourcePatternResolver resourcePatternResolver)
public void setSpringConfig(RuntimeSpringConfiguration springConfig)
springConfig
- The spring config
protected Object[] subarray(Object[] args, int i, int j)
public void xmlns(java.util.Map definition)
definition
- The definition
Groovy Documentation