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.
Modifiers | Name | Description |
---|---|---|
static String |
CHILD_BUILDER |
|
static String |
CURRENT_BUILDER |
|
static String |
CURRENT_FACTORY |
|
static String |
CURRENT_NAME |
|
static String |
CURRENT_NODE |
|
static String |
OWNER |
|
static String |
PARENT_BUILDER |
|
static String |
PARENT_CONTEXT |
|
static String |
PARENT_FACTORY |
|
static String |
PARENT_NAME |
|
static String |
PARENT_NODE |
|
static String |
SCRIPT_CLASS_NAME |
|
protected LinkedList<Closure> |
attributeDelegates |
|
protected boolean |
autoRegistrationComplete |
|
protected boolean |
autoRegistrationRunning |
|
protected Map<String, Closure> |
explicitMethods |
|
protected Map<String, Closure> |
explicitProperties |
|
protected Closure |
methodMissingDelegate |
|
protected LinkedList<Closure> |
postInstantiateDelegates |
|
protected LinkedList<Closure> |
postNodeCompletionDelegates |
|
protected LinkedList<Closure> |
preInstantiateDelegates |
|
protected Closure |
propertyMissingDelegate |
|
protected Map<String, Set<String>> |
registrationGroup |
|
protected String |
registrationGroupName |
Constructor and description |
---|
FactoryBuilderSupport() |
FactoryBuilderSupport(boolean init) |
Type Params | Return Type | Name and description |
---|---|---|
|
public Closure |
addAttributeDelegate(Closure attrDelegate) Add an attribute delegate so it can intercept attributes being set. |
|
public void |
addDisposalClosure(Closure closure) |
|
public Closure |
addPostInstantiateDelegate(Closure delegate) Add a postInstantiate delegate so it can intercept nodes after they are created. |
|
public Closure |
addPostNodeCompletionDelegate(Closure delegate) Add a nodeCompletion delegate so it can intercept nodes after they done with building. |
|
public Closure |
addPreInstantiateDelegate(Closure delegate) Add a preInstantiate delegate so it can intercept nodes before they are created. |
|
public void |
autoRegisterNodes() Ask the nodes to be registered |
|
public Object |
build(Class viewClass) |
|
public Object |
build(Script script) |
|
public Object |
build(String script, GroovyClassLoader loader) |
|
protected boolean |
checkExplicitMethod(String methodName, Object args, Reference result) |
|
public static void |
checkValueIsNull(Object value, Object name) Throws an exception if value is null. |
|
public static boolean |
checkValueIsType(Object value, Object name, Class type) Checks type of value against builder type |
|
public static boolean |
checkValueIsTypeNotString(Object value, Object name, Class type) Checks values against factory's type |
|
protected Object |
createNode(Object name, Map attributes, Object value) This method is responsible for instantiating a node and configure its properties. |
|
protected Object |
dispatchNodeCall(Object name, Object args) |
|
protected Object |
dispathNodeCall(Object name, Object args) Use FactoryBuilderSupport.dispatchNodeCall instead. |
|
public void |
dispose() |
|
public List<Closure> |
getAttributeDelegates() |
|
public FactoryBuilderSupport |
getChildBuilder() |
|
public Map<String, Object> |
getContext()
|
|
public Object |
getContextAttribute(String key) |
|
protected LinkedList<Map<String, Object>> |
getContexts()
|
|
protected Map<String, Object> |
getContinuationData() Stores the thread local states in a Map that can be passed across threads |
|
public Object |
getCurrent()
|
|
public FactoryBuilderSupport |
getCurrentBuilder()
|
|
public Factory |
getCurrentFactory()
|
|
public String |
getCurrentName()
|
|
public List<Closure> |
getDisposalClosures() |
|
public Map<String, Closure> |
getExplicitMethods()
|
|
public Map<String, Closure> |
getExplicitProperties()
|
|
public Map<String, Factory> |
getFactories()
|
|
public Map<String, Closure> |
getLocalExplicitMethods()
|
|
public Map<String, Closure> |
getLocalExplicitProperties()
|
|
public Map<String, Factory> |
getLocalFactories()
|
|
public Closure |
getMethodMissingDelegate() |
|
public Object |
getName(String methodName) A hook to allow names to be converted into some other object such as a QName in XML or ObjectName in JMX. |
|
public Closure |
getNameMappingClosure() |
|
public Map |
getParentContext()
|
|
public Factory |
getParentFactory()
|
|
public String |
getParentName()
|
|
public Object |
getParentNode()
|
|
public List<Closure> |
getPostInstantiateDelegates() |
|
public List<Closure> |
getPostNodeCompletionDelegates() |
|
public List<Closure> |
getPreInstantiateDelegates() |
|
public Object |
getProperty(String property) Overloaded to make variables appear as bean properties or via the subscript operator |
|
public Closure |
getPropertyMissingDelegate() |
|
protected FactoryBuilderSupport |
getProxyBuilder() Proxy builders are useful for changing the building context, thus enabling mix & match builders. |
|
public Set<String> |
getRegistrationGroupItems(String group) |
|
public Set<String> |
getRegistrationGroups() |
|
public Object |
getVariable(String name)
|
|
public Map |
getVariables() |
|
protected void |
handleNodeAttributes(Object node, Map attributes) Assigns any existing properties to the node. |
|
public Object |
invokeMethod(String methodName) Convenience method when no arguments are required |
|
public Object |
invokeMethod(String methodName, Object args) |
|
protected void |
newContext() Pushes a new context on the stack. |
|
public Object |
newInstance(FactoryBuilderSupport builder, Object name, Object value, Map properties) |
|
protected void |
nodeCompleted(Object parent, Object node) A hook to allow nodes to be processed once they have had all of their children applied. |
|
protected Map<String, Object> |
popContext() Removes the last context from the stack. |
|
protected void |
postInstantiate(Object name, Map attributes, Object node) A hook after the factory creates the node and before attributes are set. |
|
protected Object |
postNodeCompletion(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. |
|
protected void |
preInstantiate(Object name, Map attributes, Object value) A hook before the factory creates the node. |
|
public void |
registerBeanFactory(String theName, Class beanClass) Registers a factory for a JavaBean. |
|
public void |
registerBeanFactory(String theName, String groupName, Class beanClass) Registers a factory for a JavaBean. |
|
public void |
registerExplicitMethod(String name, Closure closure) |
|
public void |
registerExplicitMethod(String name, String groupName, Closure closure) |
|
public void |
registerExplicitProperty(String name, Closure getter, Closure setter) |
|
public void |
registerExplicitProperty(String name, String groupName, Closure getter, Closure setter) |
|
public void |
registerFactory(String name, Factory factory) Registers a factory for a node name. |
|
public void |
registerFactory(String name, String groupName, Factory factory) Registers a factory for a node name. |
|
public void |
removeAttributeDelegate(Closure attrDelegate) Remove the most recently added instance of the attribute delegate. |
|
public void |
removePostInstantiateDelegate(Closure delegate) Remove the most recently added instance of the postInstantiate delegate. |
|
public void |
removePostNodeCompletionDelegate(Closure delegate) Remove the most recently added instance of the nodeCompletion delegate. |
|
public void |
removePreInstantiateDelegate(Closure delegate) Remove the most recently added instance of the preInstantiate delegate. |
|
protected void |
reset() Clears the context stack. |
|
protected Closure |
resolveExplicitMethod(String methodName, Object args) This is a hook for subclasses to plugin a custom strategy for mapping names to explicit methods. |
|
protected Closure[] |
resolveExplicitProperty(String propertyName) This is a hook for subclasses to plugin a custom strategy for mapping names to property methods. |
|
protected Factory |
resolveFactory(Object name, Map attributes, Object value) This is a hook for subclasses to plugin a custom strategy for mapping names to factories. |
|
protected void |
restoreFromContinuationData(Map<String, Object> data) Restores the state of the current builder to the same state as an older build. |
|
protected void |
setClosureDelegate(Closure closure, Object node) A strategy method to allow derived builders to use builder-trees and switch in different kinds of builders. |
|
public void |
setMethodMissingDelegate(Closure delegate) |
|
public void |
setNameMappingClosure(Closure nameMappingClosure) |
|
protected void |
setNodeAttributes(Object node, Map attributes) Maps attributes key/values to properties on node. |
|
protected void |
setParent(Object parent, Object child) Strategy method to establish parent/child relationships. |
|
public void |
setProperty(String property, Object newValue) Overloaded to make variables appear as bean properties or via the subscript operator |
|
public void |
setPropertyMissingDelegate(Closure delegate) |
|
protected void |
setProxyBuilder(FactoryBuilderSupport proxyBuilder) Sets the builder to be used as a proxy. |
|
public void |
setVariable(String name, Object value) Sets the value of the given variable |
|
public Object |
withBuilder(FactoryBuilderSupport builder, Closure closure) Switches the builder's proxyBuilder during the execution of a closure. |
|
public Object |
withBuilder(FactoryBuilderSupport builder, String name, Closure closure) Switches the builder's proxyBuilder during the execution of a closure. |
|
public Object |
withBuilder(Map attributes, FactoryBuilderSupport builder, String name, Closure closure) Switches the builder's proxyBuilder during the execution of a closure. |
Methods inherited from class | Name |
---|---|
class Binding |
getProperty, getVariable, getVariables, hasVariable, removeVariable, setProperty, setVariable |
class GroovyObjectSupport |
getMetaClass, setMetaClass |
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.
attrDelegate
- the closure to be calledAdd 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.
delegate
- the closure to invokeAdd 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.
delegate
- the closure to invokeAdd 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.
delegate
- the closure to invokeAsk the nodes to be registered
Throws an exception if value is null.
value
- the node's valuename
- the node's nameChecks type of value against builder type
value
- the node's valuename
- the node's nametype
- a Class that may be assignable to the value's classChecks values against factory's type
value
- the node's valuename
- the node's nametype
- a Class that may be assignable to the value's classThis method is responsible for instantiating a node and configure its properties.
name
- the name of the nodeattributes
- the attributes for the nodevalue
- the value arguments for the nodeUse FactoryBuilderSupport.dispatchNodeCall instead.
Stores the thread local states in a Map that can be passed across threads
A hook to allow names to be converted into some other object such as a QName in XML or ObjectName in JMX.
methodName
- the name of the desired method
Overloaded to make variables appear as bean properties or via the subscript operator
Proxy builders are useful for changing the building context, thus enabling mix & match builders.
name
- the name of the variable to lookup Assigns any existing properties to the node.
It will call attributeDelegates before passing control to the factory
that built the node.
node
- the object returned by tne node factoryattributes
- the attributes for the nodeConvenience method when no arguments are required
methodName
- the name of the method to invokePushes a new context on the stack.
A hook to allow nodes to be processed once they have had all of their children applied.
node
- the current node being processedparent
- the parent of the node being processedRemoves the last context from the stack.
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.
name
- the name of the nodeattributes
- the attributes for the nodenode
- the object created by the node factory 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.
node
- the current node being processedparent
- the parent of the node being processed 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.
name
- the name of the nodeattributes
- the attributes of the nodevalue
- the value argument(s) of the node Registers a factory for a JavaBean.
The JavaBean class should have a no-args constructor.
theName
- name of the nodebeanClass
- the factory to handle the name Registers a factory for a JavaBean.
The JavaBean class should have a no-args constructor.
theName
- name of the nodegroupName
- thr group to register this node inbeanClass
- the factory to handle the nameRegisters a factory for a node name.
name
- the name of the nodefactory
- the factory to return the valuesRegisters a factory for a node name.
name
- the name of the nodegroupName
- thr group to register this node infactory
- the factory to return the valuesRemove the most recently added instance of the attribute delegate.
attrDelegate
- the instance of the closure to be removedRemove the most recently added instance of the postInstantiate delegate.
delegate
- the closure to invokeRemove the most recently added instance of the nodeCompletion delegate.
delegate
- the closure to be removedRemove the most recently added instance of the preInstantiate delegate.
delegate
- the closure to invokeClears the context stack.
This is a hook for subclasses to plugin a custom strategy for mapping names to explicit methods.
methodName
- the name of the explicit methodargs
- the arguments for the methodThis is a hook for subclasses to plugin a custom strategy for mapping names to property methods.
propertyName
- the name of the explicit methodThis is a hook for subclasses to plugin a custom strategy for mapping names to factories.
name
- the name of the factoryattributes
- the attributes from the nodevalue
- value arguments from te nodeRestores 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,
data
- the data retrieved from a compatible getContinuationData callA 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)
closure
- the closure on which to call setDelegate()node
- the node value that we've just created, which could be a
builderMaps attributes key/values to properties on node.
node
- the object from the nodeattributes
- the attributes to be setStrategy method to establish parent/child relationships.
parent
- the object from the parent nodechild
- the object from the child nodeOverloaded to make variables appear as bean properties or via the subscript operator
Sets the builder to be used as a proxy.
proxyBuilder
- the new proxySets the value of the given variable
name
- the name of the variable to setvalue
- the new value for the given variable 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.
builder
- the temporary builder to switch to as proxyBuilder.closure
- the closure to be executed under the temporary builder. 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'.
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. 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.
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.Copyright © 2003-2022 The Apache Software Foundation. All rights reserved.