Package groovy.util
Class FactoryBuilderSupport
java.lang.Object
groovy.lang.GroovyObjectSupport
groovy.lang.Binding
groovy.util.FactoryBuilderSupport
- All Implemented Interfaces:
GroovyObject
- Direct Known Subclasses:
ObjectGraphBuilder
public abstract class FactoryBuilderSupport extends Binding
Mix of BuilderSupport and SwingBuilder's factory support.
Warning: this implementation is not thread safe and should not be used
across threads in a multi-threaded environment. A locking mechanism
should be implemented by the subclass if use is expected across
multiple threads.
-
Field Summary
Fields Modifier and Type Field Description protected java.util.LinkedList<Closure>
attributeDelegates
protected boolean
autoRegistrationComplete
protected boolean
autoRegistrationRunning
static java.lang.String
CHILD_BUILDER
static java.lang.String
CURRENT_BUILDER
static java.lang.String
CURRENT_FACTORY
static java.lang.String
CURRENT_NAME
static java.lang.String
CURRENT_NODE
protected java.util.Map<java.lang.String,Closure>
explicitMethods
protected java.util.Map<java.lang.String,Closure[]>
explicitProperties
protected Closure
methodMissingDelegate
static java.lang.String
OWNER
static java.lang.String
PARENT_BUILDER
static java.lang.String
PARENT_CONTEXT
static java.lang.String
PARENT_FACTORY
static java.lang.String
PARENT_NAME
static java.lang.String
PARENT_NODE
protected java.util.LinkedList<Closure>
postInstantiateDelegates
protected java.util.LinkedList<Closure>
postNodeCompletionDelegates
protected java.util.LinkedList<Closure>
preInstantiateDelegates
protected Closure
propertyMissingDelegate
protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>>
registrationGroup
protected java.lang.String
registrationGroupName
static java.lang.String
SCRIPT_CLASS_NAME
-
Constructor Summary
Constructors Constructor Description FactoryBuilderSupport()
FactoryBuilderSupport(boolean init)
-
Method Summary
Modifier and Type Method Description Closure
addAttributeDelegate(Closure attrDelegate)
Add an attribute delegate so it can intercept attributes being set.void
addDisposalClosure(Closure closure)
Closure
addPostInstantiateDelegate(Closure delegate)
Add a postInstantiate delegate so it can intercept nodes after they are created.Closure
addPostNodeCompletionDelegate(Closure delegate)
Add a nodeCompletion delegate so it can intercept nodes after they done with building.Closure
addPreInstantiateDelegate(Closure delegate)
Add a preInstantiate delegate so it can intercept nodes before they are created.void
autoRegisterNodes()
Ask the nodes to be registeredjava.lang.Object
build(Script script)
java.lang.Object
build(java.lang.Class viewClass)
java.lang.Object
build(java.lang.String script, GroovyClassLoader loader)
protected boolean
checkExplicitMethod(java.lang.String methodName, java.lang.Object args, Reference result)
static void
checkValueIsNull(java.lang.Object value, java.lang.Object name)
Throws an exception if value is null.static boolean
checkValueIsType(java.lang.Object value, java.lang.Object name, java.lang.Class type)
Checks type of value against builder typestatic boolean
checkValueIsTypeNotString(java.lang.Object value, java.lang.Object name, java.lang.Class type)
Checks values against factory's typeprotected java.lang.Object
createNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
This method is responsible for instantiating a node and configure its properties.protected java.lang.Object
dispatchNodeCall(java.lang.Object name, java.lang.Object args)
protected java.lang.Object
dispathNodeCall(java.lang.Object name, java.lang.Object args)
Deprecated.void
dispose()
java.util.List<Closure>
getAttributeDelegates()
FactoryBuilderSupport
getChildBuilder()
java.util.Map<java.lang.String,java.lang.Object>
getContext()
java.lang.Object
getContextAttribute(java.lang.String key)
protected java.util.LinkedList<java.util.Map<java.lang.String,java.lang.Object>>
getContexts()
protected java.util.Map<java.lang.String,java.lang.Object>
getContinuationData()
Stores the thread local states in a Map that can be passed across threadsjava.lang.Object
getCurrent()
FactoryBuilderSupport
getCurrentBuilder()
Factory
getCurrentFactory()
java.lang.String
getCurrentName()
java.util.List<Closure>
getDisposalClosures()
java.util.Map<java.lang.String,Closure>
getExplicitMethods()
java.util.Map<java.lang.String,Closure[]>
getExplicitProperties()
java.util.Map<java.lang.String,Factory>
getFactories()
java.util.Map<java.lang.String,Closure>
getLocalExplicitMethods()
java.util.Map<java.lang.String,Closure[]>
getLocalExplicitProperties()
java.util.Map<java.lang.String,Factory>
getLocalFactories()
Closure
getMethodMissingDelegate()
java.lang.Object
getName(java.lang.String methodName)
A hook to allow names to be converted into some other object such as a QName in XML or ObjectName in JMX.Closure
getNameMappingClosure()
java.util.Map
getParentContext()
Factory
getParentFactory()
java.lang.String
getParentName()
java.lang.Object
getParentNode()
java.util.List<Closure>
getPostInstantiateDelegates()
java.util.List<Closure>
getPostNodeCompletionDelegates()
java.util.List<Closure>
getPreInstantiateDelegates()
java.lang.Object
getProperty(java.lang.String property)
Overloaded to make variables appear as bean properties or via the subscript operatorClosure
getPropertyMissingDelegate()
protected FactoryBuilderSupport
getProxyBuilder()
Proxy builders are useful for changing the building context, thus enabling mix & match builders.java.util.Set<java.lang.String>
getRegistrationGroupItems(java.lang.String group)
java.util.Set<java.lang.String>
getRegistrationGroups()
java.lang.Object
getVariable(java.lang.String name)
java.util.Map
getVariables()
protected void
handleNodeAttributes(java.lang.Object node, java.util.Map attributes)
Assigns any existing properties to the node.
It will call attributeDelegates before passing control to the factory that built the node.java.lang.Object
invokeMethod(java.lang.String methodName)
Convenience method when no arguments are requiredjava.lang.Object
invokeMethod(java.lang.String methodName, java.lang.Object args)
Invokes the given method.protected void
newContext()
Pushes a new context on the stack.protected void
nodeCompleted(java.lang.Object parent, java.lang.Object node)
A hook to allow nodes to be processed once they have had all of their children applied.protected java.util.Map<java.lang.String,java.lang.Object>
popContext()
Removes the last context from the stack.protected void
postInstantiate(java.lang.Object name, java.util.Map attributes, java.lang.Object node)
A hook after the factory creates the node and before attributes are set.
It will call any registered postInstantiateDelegates, if you override this method be sure to call this impl somewhere in your code.protected java.lang.Object
postNodeCompletion(java.lang.Object parent, java.lang.Object node)
A hook to allow nodes to be processed once they have had all of their children applied and allows the actual node object that represents the Markup element to be changed.
It will call any registered postNodeCompletionDelegates, if you override this method be sure to call this impl at the end of your code.protected void
preInstantiate(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
A hook before the factory creates the node.
It will call any registered preInstantiateDelegates, if you override this method be sure to call this impl somewhere in your code.void
registerBeanFactory(java.lang.String theName, java.lang.Class beanClass)
Registers a factory for a JavaBean.
The JavaBean class should have a no-args constructor.void
registerBeanFactory(java.lang.String theName, java.lang.String groupName, java.lang.Class beanClass)
Registers a factory for a JavaBean.
The JavaBean class should have a no-args constructor.void
registerExplicitMethod(java.lang.String name, Closure closure)
void
registerExplicitMethod(java.lang.String name, java.lang.String groupName, Closure closure)
void
registerExplicitProperty(java.lang.String name, Closure getter, Closure setter)
void
registerExplicitProperty(java.lang.String name, java.lang.String groupName, Closure getter, Closure setter)
void
registerFactory(java.lang.String name, Factory factory)
Registers a factory for a node name.void
registerFactory(java.lang.String name, java.lang.String groupName, Factory factory)
Registers a factory for a node name.void
removeAttributeDelegate(Closure attrDelegate)
Remove the most recently added instance of the attribute delegate.void
removePostInstantiateDelegate(Closure delegate)
Remove the most recently added instance of the postInstantiate delegate.void
removePostNodeCompletionDelegate(Closure delegate)
Remove the most recently added instance of the nodeCompletion delegate.void
removePreInstantiateDelegate(Closure delegate)
Remove the most recently added instance of the preInstantiate delegate.protected void
reset()
Clears the context stack.protected Closure
resolveExplicitMethod(java.lang.String methodName, java.lang.Object args)
This is a hook for subclasses to plugin a custom strategy for mapping names to explicit methods.protected Closure[]
resolveExplicitProperty(java.lang.String propertyName)
This is a hook for subclasses to plugin a custom strategy for mapping names to property methods.protected Factory
resolveFactory(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
This is a hook for subclasses to plugin a custom strategy for mapping names to factories.protected void
restoreFromContinuationData(java.util.Map<java.lang.String,java.lang.Object> data)
Restores the state of the current builder to the same state as an older build.protected void
setClosureDelegate(Closure closure, java.lang.Object node)
A strategy method to allow derived builders to use builder-trees and switch in different kinds of builders.void
setMethodMissingDelegate(Closure delegate)
void
setNameMappingClosure(Closure nameMappingClosure)
protected void
setNodeAttributes(java.lang.Object node, java.util.Map attributes)
Maps attributes key/values to properties on node.protected void
setParent(java.lang.Object parent, java.lang.Object child)
Strategy method to establish parent/child relationships.void
setProperty(java.lang.String property, java.lang.Object newValue)
Overloaded to make variables appear as bean properties or via the subscript operatorvoid
setPropertyMissingDelegate(Closure delegate)
protected void
setProxyBuilder(FactoryBuilderSupport proxyBuilder)
Sets the builder to be used as a proxy.void
setVariable(java.lang.String name, java.lang.Object value)
Sets the value of the given variablejava.lang.Object
withBuilder(FactoryBuilderSupport builder, Closure closure)
Switches the builder's proxyBuilder during the execution of a closure.
This is useful to temporary change the building context to another builder without the need for a contrived setup.java.lang.Object
withBuilder(FactoryBuilderSupport builder, java.lang.String name, Closure closure)
Switches the builder's proxyBuilder during the execution of a closure.
This is useful to temporary change the building context to another builder without the need for a contrived setup.java.lang.Object
withBuilder(java.util.Map attributes, FactoryBuilderSupport builder, java.lang.String name, Closure closure)
Switches the builder's proxyBuilder during the execution of a closure.
This is useful to temporary change the building context to another builder without the need for a contrived setup.Methods inherited from class groovy.lang.Binding
hasVariable, removeVariable
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, setMetaClass
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
CURRENT_FACTORY
public static final java.lang.String CURRENT_FACTORY- See Also:
- Constant Field Values
-
PARENT_FACTORY
public static final java.lang.String PARENT_FACTORY- See Also:
- Constant Field Values
-
PARENT_NODE
public static final java.lang.String PARENT_NODE- See Also:
- Constant Field Values
-
CURRENT_NODE
public static final java.lang.String CURRENT_NODE- See Also:
- Constant Field Values
-
PARENT_CONTEXT
public static final java.lang.String PARENT_CONTEXT- See Also:
- Constant Field Values
-
PARENT_NAME
public static final java.lang.String PARENT_NAME- See Also:
- Constant Field Values
-
CURRENT_NAME
public static final java.lang.String CURRENT_NAME- See Also:
- Constant Field Values
-
OWNER
public static final java.lang.String OWNER- See Also:
- Constant Field Values
-
PARENT_BUILDER
public static final java.lang.String PARENT_BUILDER- See Also:
- Constant Field Values
-
CURRENT_BUILDER
public static final java.lang.String CURRENT_BUILDER- See Also:
- Constant Field Values
-
CHILD_BUILDER
public static final java.lang.String CHILD_BUILDER- See Also:
- Constant Field Values
-
SCRIPT_CLASS_NAME
public static final java.lang.String SCRIPT_CLASS_NAME- See Also:
- Constant Field Values
-
attributeDelegates
-
preInstantiateDelegates
-
postInstantiateDelegates
-
postNodeCompletionDelegates
-
methodMissingDelegate
-
propertyMissingDelegate
-
explicitProperties
-
explicitMethods
-
registrationGroup
protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> registrationGroup -
registrationGroupName
protected java.lang.String registrationGroupName -
autoRegistrationRunning
protected boolean autoRegistrationRunning -
autoRegistrationComplete
protected boolean autoRegistrationComplete
-
-
Constructor Details
-
FactoryBuilderSupport
public FactoryBuilderSupport() -
FactoryBuilderSupport
public FactoryBuilderSupport(boolean init)
-
-
Method Details
-
checkValueIsNull
public static void checkValueIsNull(java.lang.Object value, java.lang.Object name)Throws an exception if value is null.- Parameters:
value
- the node's valuename
- the node's name
-
checkValueIsType
public static boolean checkValueIsType(java.lang.Object value, java.lang.Object name, java.lang.Class type)Checks type of value against builder type- Parameters:
value
- the node's valuename
- the node's nametype
- a Class that may be assignable to the value's class- Returns:
- true if type is assignable to the value's class, false if value is null.
-
checkValueIsTypeNotString
public static boolean checkValueIsTypeNotString(java.lang.Object value, java.lang.Object name, java.lang.Class type)Checks values against factory's type- Parameters:
value
- the node's valuename
- the node's nametype
- a Class that may be assignable to the value's class- Returns:
- Returns true if type is assignable to the value's class, false if value is null or a String.
-
autoRegisterNodes
public void autoRegisterNodes()Ask the nodes to be registered -
getVariable
public java.lang.Object getVariable(java.lang.String name)- Overrides:
getVariable
in classBinding
- Parameters:
name
- the name of the variable to lookup- Returns:
- the variable value
-
setVariable
public void setVariable(java.lang.String name, java.lang.Object value)Sets the value of the given variable- Overrides:
setVariable
in classBinding
- Parameters:
name
- the name of the variable to setvalue
- the new value for the given variable
-
getVariables
public java.util.Map getVariables()- Overrides:
getVariables
in classBinding
-
getProperty
public java.lang.Object getProperty(java.lang.String property)Overloaded to make variables appear as bean properties or via the subscript operator- Specified by:
getProperty
in interfaceGroovyObject
- Overrides:
getProperty
in classBinding
- Parameters:
property
- the name of the property of interest- Returns:
- the given property
-
setProperty
public void setProperty(java.lang.String property, java.lang.Object newValue)Overloaded to make variables appear as bean properties or via the subscript operator- Specified by:
setProperty
in interfaceGroovyObject
- Overrides:
setProperty
in classBinding
- Parameters:
property
- the name of the property of interestnewValue
- the new value for the property
-
getFactories
- Returns:
- the factory map (Unmodifiable Map).
-
getExplicitMethods
- Returns:
- the explicit methods map (Unmodifiable Map).
-
getExplicitProperties
- Returns:
- the explicit properties map (Unmodifiable Map).
-
getLocalFactories
- Returns:
- the factory map (Unmodifiable Map).
-
getLocalExplicitMethods
- Returns:
- the explicit methods map (Unmodifiable Map).
-
getLocalExplicitProperties
- Returns:
- the explicit properties map (Unmodifiable Map).
-
getRegistrationGroups
public java.util.Set<java.lang.String> getRegistrationGroups() -
getRegistrationGroupItems
public java.util.Set<java.lang.String> getRegistrationGroupItems(java.lang.String group) -
getAttributeDelegates
-
getPreInstantiateDelegates
-
getPostInstantiateDelegates
-
getPostNodeCompletionDelegates
-
getMethodMissingDelegate
-
setMethodMissingDelegate
-
getPropertyMissingDelegate
-
setPropertyMissingDelegate
-
getContext
public java.util.Map<java.lang.String,java.lang.Object> getContext()- Returns:
- the context of the current node.
-
getCurrent
public java.lang.Object getCurrent()- Returns:
- the current node being built.
-
getCurrentFactory
- Returns:
- the factory that built the current node.
-
getCurrentName
public java.lang.String getCurrentName()- Returns:
- the factory of the parent of the current node.
-
getCurrentBuilder
- Returns:
- the builder that built the current node.
-
getParentNode
public java.lang.Object getParentNode()- Returns:
- the node of the parent of the current node.
-
getParentFactory
- Returns:
- the factory of the parent of the current node.
-
getParentContext
public java.util.Map getParentContext()- Returns:
- the context of the parent of the current node.
-
getParentName
public java.lang.String getParentName()- Returns:
- the name of the parent of the current node.
-
getChildBuilder
-
getContextAttribute
public java.lang.Object getContextAttribute(java.lang.String key) -
invokeMethod
public java.lang.Object invokeMethod(java.lang.String methodName)Convenience method when no arguments are required- Parameters:
methodName
- the name of the method to invoke- Returns:
- the result of the call
-
invokeMethod
public java.lang.Object invokeMethod(java.lang.String methodName, java.lang.Object args)Description copied from interface:GroovyObject
Invokes the given method.- Parameters:
methodName
- the name of the method to callargs
- the arguments to use for the method call- Returns:
- the result of invoking the method
-
addAttributeDelegate
Add an attribute delegate so it can intercept attributes being set. Attribute delegates are fired in a FILO pattern, so that nested delegates get first crack.- Parameters:
attrDelegate
- the closure to be called- Returns:
- attrDelegate
-
removeAttributeDelegate
Remove the most recently added instance of the attribute delegate.- Parameters:
attrDelegate
- the instance of the closure to be removed
-
addPreInstantiateDelegate
Add a preInstantiate delegate so it can intercept nodes before they are created. PreInstantiate delegates are fired in a FILO pattern, so that nested delegates get first crack.- Parameters:
delegate
- the closure to invoke- Returns:
- delegate
-
removePreInstantiateDelegate
Remove the most recently added instance of the preInstantiate delegate.- Parameters:
delegate
- the closure to invoke
-
addPostInstantiateDelegate
Add a postInstantiate delegate so it can intercept nodes after they are created. PostInstantiate delegates are fired in a FILO pattern, so that nested delegates get first crack.- Parameters:
delegate
- the closure to invoke- Returns:
- delegate
-
removePostInstantiateDelegate
Remove the most recently added instance of the postInstantiate delegate.- Parameters:
delegate
- the closure to invoke
-
addPostNodeCompletionDelegate
Add a nodeCompletion delegate so it can intercept nodes after they done with building. NodeCompletion delegates are fired in a FILO pattern, so that nested delegates get first crack.- Parameters:
delegate
- the closure to invoke- Returns:
- delegate
-
removePostNodeCompletionDelegate
Remove the most recently added instance of the nodeCompletion delegate.- Parameters:
delegate
- the closure to be removed
-
registerExplicitProperty
-
registerExplicitProperty
-
registerExplicitMethod
-
registerExplicitMethod
public void registerExplicitMethod(java.lang.String name, java.lang.String groupName, Closure closure) -
registerBeanFactory
public void registerBeanFactory(java.lang.String theName, java.lang.Class beanClass)Registers a factory for a JavaBean.
The JavaBean class should have a no-args constructor.- Parameters:
theName
- name of the nodebeanClass
- the factory to handle the name
-
registerBeanFactory
public void registerBeanFactory(java.lang.String theName, java.lang.String groupName, java.lang.Class beanClass)Registers a factory for a JavaBean.
The JavaBean class should have a no-args constructor.- Parameters:
theName
- name of the nodegroupName
- thr group to register this node inbeanClass
- the factory to handle the name
-
registerFactory
Registers a factory for a node name.- Parameters:
name
- the name of the nodefactory
- the factory to return the values
-
registerFactory
Registers a factory for a node name.- Parameters:
name
- the name of the nodegroupName
- thr group to register this node infactory
- the factory to return the values
-
createNode
protected java.lang.Object createNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)This method is responsible for instantiating a node and configure its properties.- Parameters:
name
- the name of the nodeattributes
- the attributes for the nodevalue
- the value arguments for the node- Returns:
- the object return from the factory
-
resolveFactory
protected Factory resolveFactory(java.lang.Object name, java.util.Map attributes, java.lang.Object value)This is a hook for subclasses to plugin a custom strategy for mapping names to factories.- Parameters:
name
- the name of the factoryattributes
- the attributes from the nodevalue
- value arguments from te node- Returns:
- the Factory associated with name.
-
resolveExplicitMethod
This is a hook for subclasses to plugin a custom strategy for mapping names to explicit methods.- Parameters:
methodName
- the name of the explicit methodargs
- the arguments for the method- Returns:
- the closure for the matched explicit method.
-
resolveExplicitProperty
This is a hook for subclasses to plugin a custom strategy for mapping names to property methods.- Parameters:
propertyName
- the name of the explicit method- Returns:
- the get and set closures (in that order) for the matched explicit property.
-
checkExplicitMethod
protected boolean checkExplicitMethod(java.lang.String methodName, java.lang.Object args, Reference result) -
dispathNodeCall
@Deprecated protected java.lang.Object dispathNodeCall(java.lang.Object name, java.lang.Object args)Deprecated.UsedispatchNodeCall(Object, Object)
instead. -
dispatchNodeCall
protected java.lang.Object dispatchNodeCall(java.lang.Object name, java.lang.Object args) -
getName
public java.lang.Object getName(java.lang.String methodName)A hook to allow names to be converted into some other object such as a QName in XML or ObjectName in JMX.- Parameters:
methodName
- the name of the desired method- Returns:
- the object representing the name
-
getProxyBuilder
Proxy builders are useful for changing the building context, thus enabling mix & match builders.- Returns:
- the current builder that serves as a proxy.
-
setProxyBuilder
Sets the builder to be used as a proxy.- Parameters:
proxyBuilder
- the new proxy
-
getNameMappingClosure
-
setNameMappingClosure
-
handleNodeAttributes
protected void handleNodeAttributes(java.lang.Object node, java.util.Map attributes)Assigns any existing properties to the node.
It will call attributeDelegates before passing control to the factory that built the node.- Parameters:
node
- the object returned by tne node factoryattributes
- the attributes for the node
-
newContext
protected void newContext()Pushes a new context on the stack. -
nodeCompleted
protected void nodeCompleted(java.lang.Object parent, java.lang.Object node)A hook to allow nodes to be processed once they have had all of their children applied.- Parameters:
node
- the current node being processedparent
- the parent of the node being processed
-
popContext
protected java.util.Map<java.lang.String,java.lang.Object> popContext()Removes the last context from the stack.- Returns:
- the content just removed
-
postInstantiate
protected void postInstantiate(java.lang.Object name, java.util.Map attributes, java.lang.Object node)A hook after the factory creates the node and before attributes are set.
It will call any registered postInstantiateDelegates, if you override this method be sure to call this impl somewhere in your code.- Parameters:
name
- the name of the nodeattributes
- the attributes for the nodenode
- the object created by the node factory
-
postNodeCompletion
protected java.lang.Object postNodeCompletion(java.lang.Object parent, java.lang.Object node)A hook to allow nodes to be processed once they have had all of their children applied and allows the actual node object that represents the Markup element to be changed.
It will call any registered postNodeCompletionDelegates, if you override this method be sure to call this impl at the end of your code.- Parameters:
node
- the current node being processedparent
- the parent of the node being processed- Returns:
- the node, possibly new, that represents the markup element
-
preInstantiate
protected void preInstantiate(java.lang.Object name, java.util.Map attributes, java.lang.Object value)A hook before the factory creates the node.
It will call any registered preInstantiateDelegates, if you override this method be sure to call this impl somewhere in your code.- Parameters:
name
- the name of the nodeattributes
- the attributes of the nodevalue
- the value argument(s) of the node
-
reset
protected void reset()Clears the context stack. -
setClosureDelegate
A strategy method to allow derived builders to use builder-trees and switch in different kinds of builders. This method should call the setDelegate() method on the closure which by default passes in this but if node is-a builder we could pass that in instead (or do something wacky too)- Parameters:
closure
- the closure on which to call setDelegate()node
- the node value that we've just created, which could be a builder
-
setNodeAttributes
protected void setNodeAttributes(java.lang.Object node, java.util.Map attributes)Maps attributes key/values to properties on node.- Parameters:
node
- the object from the nodeattributes
- the attributes to be set
-
setParent
protected void setParent(java.lang.Object parent, java.lang.Object child)Strategy method to establish parent/child relationships.- Parameters:
parent
- the object from the parent nodechild
- the object from the child node
-
getContexts
protected java.util.LinkedList<java.util.Map<java.lang.String,java.lang.Object>> getContexts()- Returns:
- the stack of available contexts.
-
getContinuationData
protected java.util.Map<java.lang.String,java.lang.Object> getContinuationData()Stores the thread local states in a Map that can be passed across threads- Returns:
- the map
-
restoreFromContinuationData
protected void restoreFromContinuationData(java.util.Map<java.lang.String,java.lang.Object> data)Restores the state of the current builder to the same state as an older build. Caution, this will destroy rather than merge the current build context if there is any,- Parameters:
data
- the data retrieved from a compatible getContinuationData call
-
build
public java.lang.Object build(java.lang.Class viewClass) -
build
-
build
-
withBuilder
Switches the builder's proxyBuilder during the execution of a closure.
This is useful to temporary change the building context to another builder without the need for a contrived setup. It will also take care of restoring the previous proxyBuilder when the execution finishes, even if an exception was thrown from inside the closure.- Parameters:
builder
- the temporary builder to switch to as proxyBuilder.closure
- the closure to be executed under the temporary builder.- Returns:
- the execution result of the closure.
- Throws:
java.lang.RuntimeException
- - any exception the closure might have thrown during execution.
-
withBuilder
public java.lang.Object withBuilder(FactoryBuilderSupport builder, java.lang.String name, Closure closure)Switches the builder's proxyBuilder during the execution of a closure.
This is useful to temporary change the building context to another builder without the need for a contrived setup. It will also take care of restoring the previous proxyBuilder when the execution finishes, even if an exception was thrown from inside the closure. Additionally it will use the closure's result as the value for the node identified by 'name'.- Parameters:
builder
- the temporary builder to switch to as proxyBuilder.name
- the node to build on the 'parent' builder.closure
- the closure to be executed under the temporary builder.- Returns:
- a node that responds to value of name with the closure's result as its value.
- Throws:
java.lang.RuntimeException
- - any exception the closure might have thrown during execution.
-
withBuilder
public java.lang.Object withBuilder(java.util.Map attributes, FactoryBuilderSupport builder, java.lang.String name, Closure closure)Switches the builder's proxyBuilder during the execution of a closure.
This is useful to temporary change the building context to another builder without the need for a contrived setup. It will also take care of restoring the previous proxyBuilder when the execution finishes, even if an exception was thrown from inside the closure. Additionally it will use the closure's result as the value for the node identified by 'name' and assign any attributes that might have been set.- Parameters:
attributes
- additional properties for the node on the parent builder.builder
- the temporary builder to switch to as proxyBuilder.name
- the node to build on the 'parent' builder.closure
- the closure to be executed under the temporary builder.- Returns:
- a node that responds to value of name with the closure's result as its value.
- Throws:
java.lang.RuntimeException
- - any exception the closure might have thrown during execution.
-
addDisposalClosure
-
getDisposalClosures
-
dispose
public void dispose()
-