public abstract class FactoryBuilderSupport extends Binding
Modifier and Type | Field and 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 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
|
java.lang.Object |
build(java.lang.Class viewClass) |
java.lang.Object |
build(Script script) |
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 type
|
static boolean |
checkValueIsTypeNotString(java.lang.Object value,
java.lang.Object name,
java.lang.Class type)
Checks values against factory's type
|
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.
|
protected java.lang.Object |
dispathNodeCall(java.lang.Object name,
java.lang.Object args) |
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 threads
|
java.lang.Object |
getCurrent() |
FactoryBuilderSupport |
getCurrentBuilder() |
Factory |
getCurrentFactory() |
java.lang.String |
getCurrentName() |
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 operator
|
Closure |
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.
|
java.lang.Object |
invokeMethod(java.lang.String methodName)
Convenience method when no arguments are required
|
java.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.
|
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.
|
protected void |
preInstantiate(java.lang.Object name,
java.util.Map attributes,
java.lang.Object value)
A hook before the factory creates the node.
|
void |
registerBeanFactory(java.lang.String theName,
java.lang.Class beanClass)
Registers a factory for a JavaBean.
|
void |
registerBeanFactory(java.lang.String theName,
java.lang.String groupName,
java.lang.Class beanClass)
Registers a factory for a JavaBean.
|
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 operator
|
void |
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 variable
|
java.lang.Object |
withBuilder(FactoryBuilderSupport builder,
Closure closure)
Switches the builder's proxyBuilder during the execution of a closure.
|
java.lang.Object |
withBuilder(FactoryBuilderSupport builder,
java.lang.String name,
Closure closure)
Switches the builder's proxyBuilder during the execution of a closure.
|
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.
|
hasVariable
getMetaClass, setMetaClass
public static final java.lang.String CURRENT_FACTORY
public static final java.lang.String PARENT_FACTORY
public static final java.lang.String PARENT_NODE
public static final java.lang.String CURRENT_NODE
public static final java.lang.String PARENT_CONTEXT
public static final java.lang.String PARENT_NAME
public static final java.lang.String CURRENT_NAME
public static final java.lang.String OWNER
public static final java.lang.String PARENT_BUILDER
public static final java.lang.String CURRENT_BUILDER
public static final java.lang.String CHILD_BUILDER
public static final java.lang.String SCRIPT_CLASS_NAME
protected java.util.LinkedList<Closure> attributeDelegates
protected java.util.LinkedList<Closure> preInstantiateDelegates
protected java.util.LinkedList<Closure> postInstantiateDelegates
protected java.util.LinkedList<Closure> postNodeCompletionDelegates
protected Closure methodMissingDelegate
protected Closure propertyMissingDelegate
protected java.util.Map<java.lang.String,Closure[]> explicitProperties
protected java.util.Map<java.lang.String,Closure> explicitMethods
protected java.util.Map<java.lang.String,java.util.Set<java.lang.String>> registrationGroup
protected java.lang.String registrationGroupName
protected boolean autoRegistrationRunning
protected boolean autoRegistrationComplete
public FactoryBuilderSupport()
public FactoryBuilderSupport(boolean init)
public static void checkValueIsNull(java.lang.Object value, java.lang.Object name)
value
- the node's valuename
- the node's namepublic static boolean checkValueIsType(java.lang.Object value, java.lang.Object name, java.lang.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(java.lang.Object value, java.lang.Object name, java.lang.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 java.lang.Object getVariable(java.lang.String name)
getVariable
in class Binding
name
- the name of the variable to lookuppublic void setVariable(java.lang.String name, java.lang.Object value)
setVariable
in class Binding
name
- the name of the variable to setvalue
- the new value for the given variablepublic java.util.Map getVariables()
getVariables
in class Binding
public java.lang.Object getProperty(java.lang.String property)
getProperty
in interface GroovyObject
getProperty
in class Binding
property
- the name of the property of interestpublic void setProperty(java.lang.String property, java.lang.Object newValue)
setProperty
in interface GroovyObject
setProperty
in class Binding
property
- the name of the property of interestnewValue
- the new value for the propertypublic java.util.Map<java.lang.String,Factory> getFactories()
public java.util.Map<java.lang.String,Closure> getExplicitMethods()
public java.util.Map<java.lang.String,Closure[]> getExplicitProperties()
public java.util.Map<java.lang.String,Factory> getLocalFactories()
public java.util.Map<java.lang.String,Closure> getLocalExplicitMethods()
public java.util.Map<java.lang.String,Closure[]> getLocalExplicitProperties()
public java.util.Set<java.lang.String> getRegistrationGroups()
public java.util.Set<java.lang.String> getRegistrationGroupItems(java.lang.String group)
public java.util.List<Closure> getAttributeDelegates()
public java.util.List<Closure> getPreInstantiateDelegates()
public java.util.List<Closure> getPostInstantiateDelegates()
public java.util.List<Closure> getPostNodeCompletionDelegates()
public Closure getMethodMissingDelegate()
public void setMethodMissingDelegate(Closure delegate)
public Closure getPropertyMissingDelegate()
public void setPropertyMissingDelegate(Closure delegate)
public java.util.Map<java.lang.String,java.lang.Object> getContext()
public java.lang.Object getCurrent()
public Factory getCurrentFactory()
public java.lang.String getCurrentName()
public FactoryBuilderSupport getCurrentBuilder()
public java.lang.Object getParentNode()
public Factory getParentFactory()
public java.util.Map getParentContext()
public java.lang.String getParentName()
public FactoryBuilderSupport getChildBuilder()
public java.lang.Object getContextAttribute(java.lang.String key)
public java.lang.Object invokeMethod(java.lang.String methodName)
methodName
- the name of the method to invokepublic java.lang.Object invokeMethod(java.lang.String methodName, java.lang.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(java.lang.String name, Closure getter, Closure setter)
public void registerExplicitProperty(java.lang.String name, java.lang.String groupName, Closure getter, Closure setter)
public void registerExplicitMethod(java.lang.String name, Closure closure)
public void registerExplicitMethod(java.lang.String name, java.lang.String groupName, Closure closure)
public void registerBeanFactory(java.lang.String theName, java.lang.Class beanClass)
theName
- name of the nodebeanClass
- the factory to handle the namepublic void registerBeanFactory(java.lang.String theName, java.lang.String groupName, java.lang.Class beanClass)
theName
- name of the nodegroupName
- thr group to register this node inbeanClass
- the factory to handle the namepublic void registerFactory(java.lang.String name, Factory factory)
name
- the name of the nodefactory
- the factory to return the valuespublic void registerFactory(java.lang.String name, java.lang.String groupName, Factory factory)
name
- the name of the nodegroupName
- thr group to register this node infactory
- the factory to return the valuesprotected java.lang.Object createNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
name
- the name of the nodeattributes
- the attributes for the nodevalue
- the value arguments for the nodeprotected Factory resolveFactory(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
name
- the name of the factoryattributes
- the attributes from the nodevalue
- value arguments from te nodeprotected Closure resolveExplicitMethod(java.lang.String methodName, java.lang.Object args)
methodName
- the name of the explicit methodargs
- the arguments for the methodprotected Closure[] resolveExplicitProperty(java.lang.String propertyName)
propertyName
- the name of the explicit methodprotected boolean checkExplicitMethod(java.lang.String methodName, java.lang.Object args, Reference result)
protected java.lang.Object dispathNodeCall(java.lang.Object name, java.lang.Object args)
public java.lang.Object getName(java.lang.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(java.lang.Object node, java.util.Map attributes)
node
- the object returned by tne node factoryattributes
- the attributes for the nodeprotected void newContext()
protected void nodeCompleted(java.lang.Object parent, java.lang.Object node)
node
- the current node being processedparent
- the parent of the node being processedprotected java.util.Map<java.lang.String,java.lang.Object> popContext()
protected void postInstantiate(java.lang.Object name, java.util.Map attributes, java.lang.Object node)
name
- the name of the nodeattributes
- the attributes for the nodenode
- the object created by the node factoryprotected java.lang.Object postNodeCompletion(java.lang.Object parent, java.lang.Object node)
node
- the current node being processedparent
- the parent of the node being processedprotected void preInstantiate(java.lang.Object name, java.util.Map attributes, java.lang.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, java.lang.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(java.lang.Object node, java.util.Map attributes)
node
- the object from the nodeattributes
- the attributes to be setprotected void setParent(java.lang.Object parent, java.lang.Object child)
parent
- the object from the parent nodechild
- the object from the child nodeprotected java.util.LinkedList<java.util.Map<java.lang.String,java.lang.Object>> getContexts()
protected java.util.Map<java.lang.String,java.lang.Object> getContinuationData()
protected void restoreFromContinuationData(java.util.Map<java.lang.String,java.lang.Object> data)
data
- the data retrieved from a compatible getContinuationData callpublic java.lang.Object build(java.lang.Class viewClass)
public java.lang.Object build(Script script)
public java.lang.Object build(java.lang.String script, GroovyClassLoader loader)
public java.lang.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.java.lang.RuntimeException
- - any exception the closure might have thrown during
execution.public java.lang.Object withBuilder(FactoryBuilderSupport builder, java.lang.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.java.lang.RuntimeException
- - any exception the closure might have thrown during
execution.public java.lang.Object withBuilder(java.util.Map attributes, FactoryBuilderSupport builder, java.lang.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.java.lang.RuntimeException
- - any exception the closure might have thrown during
execution.public void addDisposalClosure(Closure closure)
public void dispose()