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
Mix of BuilderSupport and SwingBuilder's factory support.
 Warning: this implementation is not thread safe and should not be used
 across threads in a multithreaded environment.  A locking mechanism
 should be implemented by the subclass if use is expected across
 multiple threads.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected LinkedList<Closure>protected booleanprotected booleanstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected Closurestatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringprotected LinkedList<Closure>protected LinkedList<Closure>protected LinkedList<Closure>protected Closureprotected Stringstatic final String
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionaddAttributeDelegate(Closure attrDelegate) Add an attribute delegate so it can intercept attributes being set.voidaddDisposalClosure(Closure closure) addPostInstantiateDelegate(Closure delegate) Add a postInstantiate delegate so it can intercept nodes after they are created.addPostNodeCompletionDelegate(Closure delegate) Add a nodeCompletion delegate so it can intercept nodes after they done with building.addPreInstantiateDelegate(Closure delegate) Add a preInstantiate delegate so it can intercept nodes before they are created.voidAsk the nodes to be registeredbuild(String script, GroovyClassLoader loader) protected booleancheckExplicitMethod(String methodName, Object args, Reference result) static voidcheckValueIsNull(Object value, Object name) Throws an exception if value is null.static booleancheckValueIsType(Object value, Object name, Class type) Checks type of value against builder typestatic booleancheckValueIsTypeNotString(Object value, Object name, Class type) Checks values against factory's typeprotected ObjectcreateNode(Object name, Map attributes, Object value) This method is responsible for instantiating a node and configure its properties.protected ObjectdispatchNodeCall(Object name, Object args) protected ObjectdispathNodeCall(Object name, Object args) Deprecated.voiddispose()protected LinkedList<Map<String,Object>> Stores the thread local states in a Map that can be passed across threadsA hook to allow names to be converted into some other object such as a QName in XML or ObjectName in JMX.getProperty(String property) Overloaded to make variables appear as bean properties or via the subscript operatorprotected FactoryBuilderSupportProxy builders are useful for changing the building context, thus enabling mix & match builders.getRegistrationGroupItems(String group) getVariable(String name) protected voidhandleNodeAttributes(Object node, Map attributes) Assigns any existing properties to the node.
 It will call attributeDelegates before passing control to the factory that built the node.invokeMethod(String methodName) Convenience method when no arguments are requiredinvokeMethod(String methodName, Object args) Invokes the given method.protected voidPushes a new context on the stack.protected voidnodeCompleted(Object parent, Object node) A hook to allow nodes to be processed once they have had all of their children applied.Removes the last context from the stack.protected voidpostInstantiate(Object name, Map attributes, 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 ObjectpostNodeCompletion(Object parent, 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 voidpreInstantiate(Object name, Map attributes, 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.voidregisterBeanFactory(String theName, Class beanClass) Registers a factory for a JavaBean.
 The JavaBean class should have a no-arg constructor.voidregisterBeanFactory(String theName, String groupName, Class beanClass) Registers a factory for a JavaBean.
 The JavaBean class should have a no-arg constructor.voidregisterExplicitMethod(String name, Closure closure) voidregisterExplicitMethod(String name, String groupName, Closure closure) voidregisterExplicitProperty(String name, Closure getter, Closure setter) voidregisterExplicitProperty(String name, String groupName, Closure getter, Closure setter) voidregisterFactory(String name, Factory factory) Registers a factory for a node name.voidregisterFactory(String name, String groupName, Factory factory) Registers a factory for a node name.voidremoveAttributeDelegate(Closure attrDelegate) Remove the most recently added instance of the attribute delegate.voidremovePostInstantiateDelegate(Closure delegate) Remove the most recently added instance of the postInstantiate delegate.voidremovePostNodeCompletionDelegate(Closure delegate) Remove the most recently added instance of the nodeCompletion delegate.voidremovePreInstantiateDelegate(Closure delegate) Remove the most recently added instance of the preInstantiate delegate.protected voidreset()Clears the context stack.protected ClosureresolveExplicitMethod(String methodName, Object args) This is a hook for subclasses to plug in a custom strategy for mapping names to explicit methods.protected Closure[]resolveExplicitProperty(String propertyName) This is a hook for subclasses to plug in a custom strategy for mapping names to property methods.protected FactoryresolveFactory(Object name, Map attributes, Object value) This is a hook for subclasses to plug in a custom strategy for mapping names to factories.protected voidRestores the state of the current builder to the same state as an older build.protected voidsetClosureDelegate(Closure closure, Object node) A strategy method to allow derived builders to use builder-trees and switch in different kinds of builders.voidsetMethodMissingDelegate(Closure delegate) voidsetNameMappingClosure(Closure nameMappingClosure) protected voidsetNodeAttributes(Object node, Map attributes) Maps attributes key/values to properties on node.protected voidStrategy method to establish parent/child relationships.voidsetProperty(String property, Object newValue) Overloaded to make variables appear as bean properties or via the subscript operatorvoidsetPropertyMissingDelegate(Closure delegate) protected voidsetProxyBuilder(FactoryBuilderSupport proxyBuilder) Sets the builder to be used as a proxy.voidsetVariable(String name, Object value) Sets the value of the given variablewithBuilder(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.withBuilder(FactoryBuilderSupport builder, 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.withBuilder(Map attributes, FactoryBuilderSupport builder, 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.BindinghasVariable, removeVariableMethods inherited from class groovy.lang.GroovyObjectSupportgetMetaClass, setMetaClass
- 
Field Details- 
CURRENT_FACTORY- See Also:
 
- 
PARENT_FACTORY- See Also:
 
- 
PARENT_NODE- See Also:
 
- 
CURRENT_NODE- See Also:
 
- 
PARENT_CONTEXT- See Also:
 
- 
PARENT_NAME- See Also:
 
- 
CURRENT_NAME- See Also:
 
- 
OWNER- See Also:
 
- 
PARENT_BUILDER- See Also:
 
- 
CURRENT_BUILDER- See Also:
 
- 
CHILD_BUILDER- See Also:
 
- 
SCRIPT_CLASS_NAME- See Also:
 
- 
attributeDelegates
- 
preInstantiateDelegates
- 
postInstantiateDelegates
- 
postNodeCompletionDelegates
- 
methodMissingDelegate
- 
propertyMissingDelegate
- 
explicitProperties
- 
explicitMethods
- 
registrationGroup
- 
registrationGroupName
- 
autoRegistrationRunningprotected boolean autoRegistrationRunning
- 
autoRegistrationCompleteprotected boolean autoRegistrationComplete
 
- 
- 
Constructor Details- 
FactoryBuilderSupportpublic FactoryBuilderSupport()
- 
FactoryBuilderSupportpublic FactoryBuilderSupport(boolean init) 
 
- 
- 
Method Details- 
checkValueIsNullThrows an exception if value is null.- Parameters:
- value- the node's value
- name- the node's name
 
- 
checkValueIsTypeChecks type of value against builder type- Parameters:
- value- the node's value
- name- the node's name
- type- 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.
 
- 
checkValueIsTypeNotStringChecks values against factory's type- Parameters:
- value- the node's value
- name- the node's name
- type- 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.
 
- 
autoRegisterNodespublic void autoRegisterNodes()Ask the nodes to be registered
- 
getVariable- Overrides:
- getVariablein class- Binding
- Parameters:
- name- the name of the variable to lookup
- Returns:
- the variable value
 
- 
setVariableSets the value of the given variable- Overrides:
- setVariablein class- Binding
- Parameters:
- name- the name of the variable to set
- value- the new value for the given variable
 
- 
getVariables- Overrides:
- getVariablesin class- Binding
 
- 
getPropertyOverloaded to make variables appear as bean properties or via the subscript operator- Specified by:
- getPropertyin interface- GroovyObject
- Overrides:
- getPropertyin class- Binding
- Parameters:
- property- the name of the property of interest
- Returns:
- the given property
 
- 
setPropertyOverloaded to make variables appear as bean properties or via the subscript operator- Specified by:
- setPropertyin interface- GroovyObject
- Overrides:
- setPropertyin class- Binding
- Parameters:
- property- the name of the property of interest
- newValue- 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
- 
getRegistrationGroupItems
- 
getAttributeDelegates
- 
getPreInstantiateDelegates
- 
getPostInstantiateDelegates
- 
getPostNodeCompletionDelegates
- 
getMethodMissingDelegate
- 
setMethodMissingDelegate
- 
getPropertyMissingDelegate
- 
setPropertyMissingDelegate
- 
getContext- Returns:
- the context of the current node.
 
- 
getCurrent- Returns:
- the current node being built.
 
- 
getCurrentFactory- Returns:
- the factory that built the current node.
 
- 
getCurrentName- Returns:
- the factory of the parent of the current node.
 
- 
getCurrentBuilder- Returns:
- the builder that built the current node.
 
- 
getParentNode- Returns:
- the node of the parent of the current node.
 
- 
getParentFactory- Returns:
- the factory of the parent of the current node.
 
- 
getParentContext- Returns:
- the context of the parent of the current node.
 
- 
getParentName- Returns:
- the name of the parent of the current node.
 
- 
getChildBuilder
- 
getContextAttribute
- 
invokeMethodConvenience method when no arguments are required- Parameters:
- methodName- the name of the method to invoke
- Returns:
- the result of the call
 
- 
invokeMethodDescription copied from interface:GroovyObjectInvokes the given method.- Parameters:
- methodName- the name of the method to call
- args- the arguments to use for the method call
- Returns:
- the result of invoking the method
 
- 
addAttributeDelegateAdd 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
 
- 
removeAttributeDelegateRemove the most recently added instance of the attribute delegate.- Parameters:
- attrDelegate- the instance of the closure to be removed
 
- 
addPreInstantiateDelegateAdd 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
 
- 
removePreInstantiateDelegateRemove the most recently added instance of the preInstantiate delegate.- Parameters:
- delegate- the closure to invoke
 
- 
addPostInstantiateDelegateAdd 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
 
- 
removePostInstantiateDelegateRemove the most recently added instance of the postInstantiate delegate.- Parameters:
- delegate- the closure to invoke
 
- 
addPostNodeCompletionDelegateAdd 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
 
- 
removePostNodeCompletionDelegateRemove the most recently added instance of the nodeCompletion delegate.- Parameters:
- delegate- the closure to be removed
 
- 
registerExplicitProperty
- 
registerExplicitProperty
- 
registerExplicitMethod
- 
registerExplicitMethod
- 
registerBeanFactoryRegisters a factory for a JavaBean.
 The JavaBean class should have a no-arg constructor.- Parameters:
- theName- name of the node
- beanClass- the factory to handle the name
 
- 
registerBeanFactoryRegisters a factory for a JavaBean.
 The JavaBean class should have a no-arg constructor.- Parameters:
- theName- name of the node
- groupName- thr group to register this node in
- beanClass- the factory to handle the name
 
- 
registerFactoryRegisters a factory for a node name.- Parameters:
- name- the name of the node
- factory- the factory to return the values
 
- 
registerFactoryRegisters a factory for a node name.- Parameters:
- name- the name of the node
- groupName- thr group to register this node in
- factory- the factory to return the values
 
- 
createNodeThis method is responsible for instantiating a node and configure its properties.- Parameters:
- name- the name of the node
- attributes- the attributes for the node
- value- the value arguments for the node
- Returns:
- the object return from the factory
 
- 
resolveFactoryThis is a hook for subclasses to plug in a custom strategy for mapping names to factories.- Parameters:
- name- the name of the factory
- attributes- the attributes from the node
- value- value arguments from te node
- Returns:
- the Factory associated with name.
 
- 
resolveExplicitMethodThis is a hook for subclasses to plug in a custom strategy for mapping names to explicit methods.- Parameters:
- methodName- the name of the explicit method
- args- the arguments for the method
- Returns:
- the closure for the matched explicit method.
 
- 
resolveExplicitPropertyThis is a hook for subclasses to plug in 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
- 
dispathNodeCallDeprecated.UsedispatchNodeCall(Object, Object)instead.
- 
dispatchNodeCall
- 
getNameA 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
 
- 
getProxyBuilderProxy builders are useful for changing the building context, thus enabling mix & match builders.- Returns:
- the current builder that serves as a proxy.
 
- 
setProxyBuilderSets the builder to be used as a proxy.- Parameters:
- proxyBuilder- the new proxy
 
- 
getNameMappingClosure
- 
setNameMappingClosure
- 
handleNodeAttributesAssigns 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 factory
- attributes- the attributes for the node
 
- 
newContextprotected void newContext()Pushes a new context on the stack.
- 
nodeCompletedA hook to allow nodes to be processed once they have had all of their children applied.- Parameters:
- node- the current node being processed
- parent- the parent of the node being processed
 
- 
popContextRemoves the last context from the stack.- Returns:
- the content just removed
 
- 
postInstantiateA 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 node
- attributes- the attributes for the node
- node- the object created by the node factory
 
- 
postNodeCompletionA 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 processed
- parent- the parent of the node being processed
- Returns:
- the node, possibly new, that represents the markup element
 
- 
preInstantiateA 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 node
- attributes- the attributes of the node
- value- the value argument(s) of the node
 
- 
resetprotected void reset()Clears the context stack.
- 
setClosureDelegateA 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
 
- 
setNodeAttributesMaps attributes key/values to properties on node.- Parameters:
- node- the object from the node
- attributes- the attributes to be set
 
- 
setParentStrategy method to establish parent/child relationships.- Parameters:
- parent- the object from the parent node
- child- the object from the child node
 
- 
getContexts- Returns:
- the stack of available contexts.
 
- 
getContinuationDataStores the thread local states in a Map that can be passed across threads- Returns:
- the map
 
- 
restoreFromContinuationDataRestores 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
- 
build
- 
build
- 
withBuilderSwitches 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:
- RuntimeException- - any exception the closure might have thrown during execution.
 
- 
withBuilderSwitches 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:
- RuntimeException- - any exception the closure might have thrown during execution.
 
- 
withBuilderpublic Object withBuilder(Map attributes, FactoryBuilderSupport builder, 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:
- RuntimeException- - any exception the closure might have thrown during execution.
 
- 
addDisposalClosure
- 
getDisposalClosures
- 
disposepublic void dispose()
 
-