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 |
attributeDelegates |
|
protected boolean |
autoRegistrationComplete |
|
protected boolean |
autoRegistrationRunning |
|
protected Map |
explicitMethods |
|
protected Map |
explicitProperties |
|
protected Closure |
methodMissingDelegate |
|
protected LinkedList |
postInstantiateDelegates |
|
protected LinkedList |
postNodeCompletionDelegates |
|
protected LinkedList |
preInstantiateDelegates |
|
protected Closure |
propertyMissingDelegate |
|
protected Map |
registrationGroup |
|
protected String |
registrationGroupName |
| Constructor and description |
|---|
FactoryBuilderSupport
() |
FactoryBuilderSupport
(boolean init) |
| Type | Name and description |
|---|---|
Closure |
addAttributeDelegate(Closure attrDelegate)Add an attribute delegate so it can intercept attributes being set. |
void |
addDisposalClosure(Closure closure) |
Closure |
addPostInstantiateDelegate(Closure delegate) |
Closure |
addPostNodeCompletionDelegate(Closure delegate) |
Closure |
addPreInstantiateDelegate(Closure delegate) |
void |
autoRegisterNodes()Ask the nodes to be registered |
Object |
build(Class viewClass) |
Object |
build(Script script) |
Object |
build(String script, GroovyClassLoader loader) |
protected boolean |
checkExplicitMethod(String methodName, Object args, Reference result) |
static void |
checkValueIsNull(Object value, Object name)Throws an exception if value is null. |
static boolean |
checkValueIsType(Object value, Object name, Class type)Checks type of value against builder type |
static boolean |
checkValueIsTypeNotString(Object value, Object name, Class type)Checks values against factory's type |
protected Object |
createNode(Object name, Map attributes, Object value) |
protected Object |
dispatchNodeCall(Object name, Object args) |
protected Object |
dispathNodeCall(Object name, Object args)Use FactoryBuilderSupport.dispatchNodeCall instead. |
void |
dispose() |
List |
getAttributeDelegates() |
FactoryBuilderSupport |
getChildBuilder() |
Map |
getContext() |
Object |
getContextAttribute(String key) |
protected LinkedList |
getContexts()Restores the state of the current builder to the same state as an older build. |
protected Map |
getContinuationData() |
Object |
getCurrent()@return the current node being built. |
FactoryBuilderSupport |
getCurrentBuilder()@return the node of the parent of the current node. |
Factory |
getCurrentFactory()@return the factory of the parent of the current node. |
String |
getCurrentName()@return the builder that built the current node. |
List |
getDisposalClosures() |
Map |
getExplicitMethods()@return the explicit properties map (Unmodifiable Map). |
Map |
getExplicitProperties()@return the factory map (Unmodifiable Map). |
Map |
getFactories()@return the factory map (Unmodifiable Map). |
Map |
getLocalExplicitMethods()@return the explicit properties map (Unmodifiable Map). |
Map |
getLocalExplicitProperties() |
Map |
getLocalFactories()@return the explicit methods map (Unmodifiable Map). |
Closure |
getMethodMissingDelegate() |
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. |
Closure |
getNameMappingClosure() |
Map |
getParentContext()@return the name of the parent of the current node. |
Factory |
getParentFactory()@return the context of the parent of the current node. |
String |
getParentName() |
Object |
getParentNode()@return the factory of the parent of the current node. |
List |
getPostInstantiateDelegates() |
List |
getPostNodeCompletionDelegates() |
List |
getPreInstantiateDelegates() |
Object |
getProperty(String property) |
Closure |
getPropertyMissingDelegate() |
protected FactoryBuilderSupport |
getProxyBuilder() |
Set |
getRegistrationGroupItems(String group) |
Set |
getRegistrationGroups() |
Object |
getVariable(String name)@param name the name of the variable to lookup |
Map |
getVariables() |
protected void |
handleNodeAttributes(Object node, Map attributes) |
Object |
invokeMethod(String methodName)Convenience method when no arguments are required |
Object |
invokeMethod(String methodName, Object args) |
protected void |
newContext()A hook to allow nodes to be processed once they have had all of their children applied. |
protected void |
nodeCompleted(Object parent, Object node) |
protected Map |
popContext() |
protected void |
postInstantiate(Object name, Map attributes, Object node) |
protected Object |
postNodeCompletion(Object parent, Object node)A hook before the factory creates the node. |
protected void |
preInstantiate(Object name, Map attributes, Object value)A strategy method to allow derived builders to use builder-trees and switch in different kinds of builders. |
void |
registerBeanFactory(String theName, Class beanClass) |
void |
registerBeanFactory(String theName, String groupName, Class beanClass) |
void |
registerExplicitMethod(String name, Closure closure) |
void |
registerExplicitMethod(String name, String groupName, Closure closure) |
void |
registerExplicitProperty(String name, Closure getter, Closure setter) |
void |
registerExplicitProperty(String name, String groupName, Closure getter, Closure setter) |
void |
registerFactory(String name, Factory factory)Registers a factory for a node name. |
void |
registerFactory(String name, String groupName, Factory factory) |
void |
removeAttributeDelegate(Closure attrDelegate) |
void |
removePostInstantiateDelegate(Closure delegate) |
void |
removePostNodeCompletionDelegate(Closure delegate) |
void |
removePreInstantiateDelegate(Closure delegate) |
protected void |
reset() |
protected Closure |
resolveExplicitMethod(String methodName, Object args) |
protected Closure[] |
resolveExplicitProperty(String propertyName) |
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 data) |
protected void |
setClosureDelegate(Closure closure, Object node) |
void |
setMethodMissingDelegate(Closure delegate) |
void |
setNameMappingClosure(Closure nameMappingClosure) |
protected void |
setNodeAttributes(Object node, Map attributes) |
protected void |
setParent(Object parent, Object child)@return the stack of available contexts. |
void |
setProperty(String property, Object newValue)Overloaded to make variables appear as bean properties or via the subscript operator |
void |
setPropertyMissingDelegate(Closure delegate)@return the context of the current node. |
protected void |
setProxyBuilder(FactoryBuilderSupport proxyBuilder)Assigns any existing properties to the node. |
void |
setVariable(String name, Object value) |
Object |
withBuilder(FactoryBuilderSupport builder, Closure closure) |
Object |
withBuilder(FactoryBuilderSupport builder, String name, Closure closure)Switches the builder's proxyBuilder during the execution of a closure. |
Object |
withBuilder(Map attributes, FactoryBuilderSupport builder, String name, Closure closure) |
| Methods inherited from class | Name |
|---|---|
class Binding |
getProperty, getVariable, getVariables, hasVariable, setProperty, setVariable |
class GroovyObjectSupport |
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty |
class Object |
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll |
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 calledAsk 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 classUse FactoryBuilderSupport.dispatchNodeCall instead.
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,
data - the data retrieved from a compatible getContinuationData call
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
name - the name of the variable to lookupConvenience method when no arguments are required
methodName - the name of the method to invokeA 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 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 nodeA 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
builderRegisters a factory for a node name.
name - the name of the nodefactory - the factory to return the valuesThis 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 nodeOverloaded to make variables appear as bean properties or via the subscript operator
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 node 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.Copyright © 2003-2014 The Codehaus. All rights reserved.