public abstract class FactoryBuilderSupport extends Binding
Modifier and Type | Field and Description |
---|---|
protected LinkedList<Closure> |
attributeDelegates |
protected boolean |
autoRegistrationComplete |
protected boolean |
autoRegistrationRunning |
static String |
CHILD_BUILDER |
static String |
CURRENT_BUILDER |
static String |
CURRENT_FACTORY |
static String |
CURRENT_NAME |
static String |
CURRENT_NODE |
protected Map<String,Closure> |
explicitMethods |
protected Map<String,Closure[]> |
explicitProperties |
protected Closure |
methodMissingDelegate |
static String |
OWNER |
static String |
PARENT_BUILDER |
static String |
PARENT_CONTEXT |
static String |
PARENT_FACTORY |
static String |
PARENT_NAME |
static String |
PARENT_NODE |
protected LinkedList<Closure> |
postInstantiateDelegates |
protected LinkedList<Closure> |
postNodeCompletionDelegates |
protected LinkedList<Closure> |
preInstantiateDelegates |
protected Closure |
propertyMissingDelegate |
protected Map<String,Set<String>> |
registrationGroup |
protected String |
registrationGroupName |
static String |
SCRIPT_CLASS_NAME |
Constructor and Description |
---|
FactoryBuilderSupport() |
FactoryBuilderSupport(boolean init) |
Modifier and Type | Method 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)
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 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)
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)
Deprecated.
|
void |
dispose() |
List<Closure> |
getAttributeDelegates() |
FactoryBuilderSupport |
getChildBuilder() |
Map<String,Object> |
getContext() |
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
|
Object |
getCurrent() |
FactoryBuilderSupport |
getCurrentBuilder() |
Factory |
getCurrentFactory() |
String |
getCurrentName() |
List<Closure> |
getDisposalClosures() |
Map<String,Closure> |
getExplicitMethods() |
Map<String,Closure[]> |
getExplicitProperties() |
Map<String,Factory> |
getFactories() |
Map<String,Closure> |
getLocalExplicitMethods() |
Map<String,Closure[]> |
getLocalExplicitProperties() |
Map<String,Factory> |
getLocalFactories() |
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() |
Factory |
getParentFactory() |
String |
getParentName() |
Object |
getParentNode() |
List<Closure> |
getPostInstantiateDelegates() |
List<Closure> |
getPostNodeCompletionDelegates() |
List<Closure> |
getPreInstantiateDelegates() |
Object |
getProperty(String property)
Overloaded to make variables appear as bean properties or via the subscript operator
|
Closure |
getPropertyMissingDelegate() |
protected FactoryBuilderSupport |
getProxyBuilder()
Proxy builders are useful for changing the building context, thus
enabling mix & match builders.
|
Set<String> |
getRegistrationGroupItems(String group) |
Set<String> |
getRegistrationGroups() |
Object |
getVariable(String name) |
Map |
getVariables() |
protected void |
handleNodeAttributes(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. |
Object |
invokeMethod(String methodName)
Convenience method when no arguments are required
|
Object |
invokeMethod(String methodName,
Object args)
Invokes the given method.
|
protected void |
newContext()
Pushes a new context on the stack.
|
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.
It will call any registered postInstantiateDelegates, if you override this method be sure to call this impl somewhere in your code. |
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.
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(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. |
void |
registerBeanFactory(String theName,
Class beanClass)
Registers a factory for a JavaBean.
The JavaBean class should have a no-args constructor. |
void |
registerBeanFactory(String theName,
String groupName,
Class beanClass)
Registers a factory for a JavaBean.
The JavaBean class should have a no-args constructor. |
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)
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(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.
|
void |
setMethodMissingDelegate(Closure delegate) |
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.
|
void |
setProperty(String property,
Object newValue)
Overloaded to make variables appear as bean properties or via the subscript operator
|
void |
setPropertyMissingDelegate(Closure delegate) |
protected void |
setProxyBuilder(FactoryBuilderSupport proxyBuilder)
Sets the builder to be used as a proxy.
|
void |
setVariable(String name,
Object value)
Sets the value of the given variable
|
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. |
Object |
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. |
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. |
hasVariable
getMetaClass, setMetaClass
public static final String CURRENT_FACTORY
public static final String PARENT_FACTORY
public static final String PARENT_NODE
public static final String CURRENT_NODE
public static final String PARENT_CONTEXT
public static final String PARENT_NAME
public static final String CURRENT_NAME
public static final String OWNER
public static final String PARENT_BUILDER
public static final String CURRENT_BUILDER
public static final String CHILD_BUILDER
public static final String SCRIPT_CLASS_NAME
protected LinkedList<Closure> attributeDelegates
protected LinkedList<Closure> preInstantiateDelegates
protected LinkedList<Closure> postInstantiateDelegates
protected LinkedList<Closure> postNodeCompletionDelegates
protected Closure methodMissingDelegate
protected Closure propertyMissingDelegate
protected String registrationGroupName
protected boolean autoRegistrationRunning
protected boolean autoRegistrationComplete
public FactoryBuilderSupport()
public FactoryBuilderSupport(boolean init)
public static void checkValueIsNull(Object value, Object name)
value
- the node's valuename
- the node's namepublic static boolean checkValueIsType(Object value, Object name, Class type)
value
- the node's valuename
- the node's nametype
- a Class that may be assignable to the value's classpublic static boolean checkValueIsTypeNotString(Object value, Object name, Class type)
value
- the node's valuename
- the node's nametype
- a Class that may be assignable to the value's classpublic void autoRegisterNodes()
public Object getVariable(String name)
getVariable
in class Binding
name
- the name of the variable to lookuppublic void setVariable(String name, Object value)
setVariable
in class Binding
name
- the name of the variable to setvalue
- the new value for the given variablepublic Map getVariables()
getVariables
in class Binding
public Object getProperty(String property)
getProperty
in interface GroovyObject
getProperty
in class Binding
property
- the name of the property of interestpublic void setProperty(String property, Object newValue)
setProperty
in interface GroovyObject
setProperty
in class Binding
property
- the name of the property of interestnewValue
- the new value for the propertypublic Map<String,Closure> getExplicitMethods()
public Map<String,Closure[]> getExplicitProperties()
public Map<String,Factory> getLocalFactories()
public Map<String,Closure> getLocalExplicitMethods()
public Map<String,Closure[]> getLocalExplicitProperties()
public Closure getMethodMissingDelegate()
public void setMethodMissingDelegate(Closure delegate)
public Closure getPropertyMissingDelegate()
public void setPropertyMissingDelegate(Closure delegate)
public Object getCurrent()
public Factory getCurrentFactory()
public String getCurrentName()
public FactoryBuilderSupport getCurrentBuilder()
public Object getParentNode()
public Factory getParentFactory()
public Map getParentContext()
public String getParentName()
public FactoryBuilderSupport getChildBuilder()
public Object invokeMethod(String methodName)
methodName
- the name of the method to invokepublic Object invokeMethod(String methodName, Object args)
GroovyObject
invokeMethod
in interface GroovyObject
invokeMethod
in class GroovyObjectSupport
methodName
- the name of the method to callargs
- the arguments to use for the method callpublic Closure addAttributeDelegate(Closure attrDelegate)
attrDelegate
- the closure to be calledpublic void removeAttributeDelegate(Closure attrDelegate)
attrDelegate
- the instance of the closure to be removedpublic Closure addPreInstantiateDelegate(Closure delegate)
delegate
- the closure to invokepublic void removePreInstantiateDelegate(Closure delegate)
delegate
- the closure to invokepublic Closure addPostInstantiateDelegate(Closure delegate)
delegate
- the closure to invokepublic void removePostInstantiateDelegate(Closure delegate)
delegate
- the closure to invokepublic Closure addPostNodeCompletionDelegate(Closure delegate)
delegate
- the closure to invokepublic void removePostNodeCompletionDelegate(Closure delegate)
delegate
- the closure to be removedpublic void registerExplicitProperty(String name, Closure getter, Closure setter)
public void registerExplicitProperty(String name, String groupName, Closure getter, Closure setter)
public void registerExplicitMethod(String name, String groupName, Closure closure)
public void registerBeanFactory(String theName, Class beanClass)
theName
- name of the nodebeanClass
- the factory to handle the namepublic void registerBeanFactory(String theName, String groupName, Class beanClass)
theName
- name of the nodegroupName
- thr group to register this node inbeanClass
- the factory to handle the namepublic void registerFactory(String name, Factory factory)
name
- the name of the nodefactory
- the factory to return the valuespublic void registerFactory(String name, String groupName, Factory factory)
name
- the name of the nodegroupName
- thr group to register this node infactory
- the factory to return the valuesprotected Object createNode(Object name, Map attributes, Object value)
name
- the name of the nodeattributes
- the attributes for the nodevalue
- the value arguments for the nodeprotected Factory resolveFactory(Object name, Map attributes, Object value)
name
- the name of the factoryattributes
- the attributes from the nodevalue
- value arguments from te nodeprotected Closure resolveExplicitMethod(String methodName, Object args)
methodName
- the name of the explicit methodargs
- the arguments for the methodprotected Closure[] resolveExplicitProperty(String propertyName)
propertyName
- the name of the explicit methodprotected boolean checkExplicitMethod(String methodName, Object args, Reference result)
@Deprecated protected Object dispathNodeCall(Object name, Object args)
dispatchNodeCall(Object, Object)
instead.public Object getName(String methodName)
methodName
- the name of the desired methodprotected FactoryBuilderSupport getProxyBuilder()
protected void setProxyBuilder(FactoryBuilderSupport proxyBuilder)
proxyBuilder
- the new proxypublic Closure getNameMappingClosure()
public void setNameMappingClosure(Closure nameMappingClosure)
protected void handleNodeAttributes(Object node, Map attributes)
node
- the object returned by tne node factoryattributes
- the attributes for the nodeprotected void newContext()
protected void nodeCompleted(Object parent, Object node)
node
- the current node being processedparent
- the parent of the node being processedprotected Map<String,Object> popContext()
protected void postInstantiate(Object name, Map attributes, Object node)
name
- the name of the nodeattributes
- the attributes for the nodenode
- the object created by the node factoryprotected Object postNodeCompletion(Object parent, Object node)
node
- the current node being processedparent
- the parent of the node being processedprotected void preInstantiate(Object name, Map attributes, Object value)
name
- the name of the nodeattributes
- the attributes of the nodevalue
- the value argument(s) of the nodeprotected void reset()
protected void setClosureDelegate(Closure closure, Object node)
closure
- the closure on which to call setDelegate()node
- the node value that we've just created, which could be a
builderprotected void setNodeAttributes(Object node, Map attributes)
node
- the object from the nodeattributes
- the attributes to be setprotected void setParent(Object parent, Object child)
parent
- the object from the parent nodechild
- the object from the child nodeprotected LinkedList<Map<String,Object>> getContexts()
protected Map<String,Object> getContinuationData()
protected void restoreFromContinuationData(Map<String,Object> data)
data
- the data retrieved from a compatible getContinuationData callpublic Object build(String script, GroovyClassLoader loader)
public Object withBuilder(FactoryBuilderSupport builder, Closure closure)
builder
- the temporary builder to switch to as proxyBuilder.closure
- the closure to be executed under the temporary builder.RuntimeException
- - any exception the closure might have thrown during
execution.public Object withBuilder(FactoryBuilderSupport builder, String name, Closure closure)
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.RuntimeException
- - any exception the closure might have thrown during
execution.public Object withBuilder(Map attributes, FactoryBuilderSupport builder, String name, Closure closure)
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.RuntimeException
- - any exception the closure might have thrown during
execution.public void addDisposalClosure(Closure closure)
public void dispose()