|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovy.lang.GroovyObjectSupport
groovy.lang.Binding
groovy.util.FactoryBuilderSupport
public abstract class FactoryBuilderSupport
Mix of BuilderSupport and SwingBuilder's factory support.
Field Summary | |
---|---|
private java.util.LinkedList |
attributeDelegates
|
private java.util.LinkedList |
contexts
|
static java.lang.String |
CURRENT_FACTORY
|
static java.lang.String |
CURRENT_NAME
|
static java.lang.String |
CURRENT_NODE
|
private java.util.List |
disposalClosures
|
private java.util.Map |
factories
|
private static java.util.logging.Logger |
LOG
|
private Closure |
nameMappingClosure
|
static java.lang.String |
OWNER
|
static java.lang.String |
PARENT_CONTEXT
|
static java.lang.String |
PARENT_FACTORY
|
static java.lang.String |
PARENT_NAME
|
static java.lang.String |
PARENT_NODE
|
private java.util.LinkedList |
postInstantiateDelegates
|
private java.util.LinkedList |
postNodeCompletionDelegates
|
private java.util.LinkedList |
preInstantiateDelegates
|
private FactoryBuilderSupport |
proxyBuilder
|
Constructor Summary | |
---|---|
FactoryBuilderSupport()
|
|
FactoryBuilderSupport(Closure nameMappingClosure)
|
Method Summary | |
---|---|
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. |
java.lang.Object |
build(java.lang.Class viewClass)
|
java.lang.Object |
build(Script script)
|
java.lang.Object |
build(java.lang.String script,
GroovyClassLoader loader)
|
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)
Returns true if type is assignalbe to the value's class, false if value is null. |
static boolean |
checkValueIsTypeNotString(java.lang.Object value,
java.lang.Object name,
java.lang.Class type)
Returns true if type is assignale to the value's class, false if value is null or a String. |
protected java.lang.Object |
createNode(java.lang.Object name,
java.util.Map attributes,
java.lang.Object value)
This method is responsible for instanciating a node and configure its properties. |
void |
dispose()
|
private java.lang.Object |
doInvokeMethod(java.lang.String methodName,
java.lang.Object name,
java.lang.Object args)
This method is the workhorse of the builder. |
java.util.Map |
getContext()
Returns the context of the current node. |
private java.lang.Object |
getContextAttribute(java.lang.String key)
|
protected java.util.LinkedList |
getContexts()
Returns the stack of available contexts. |
java.lang.Object |
getCurrent()
Returns the current node being built. |
Factory |
getCurrentFactory()
Returns the factory that built the current node. |
java.lang.String |
getCurrentName()
Returns the current node's name. |
java.util.Map |
getFactories()
Returns the factory map (Unmodifiable Map). |
protected 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. |
java.util.Map |
getParentContext()
Returns the context of the parent of the current node. |
Factory |
getParentFactory()
Returns the factory of the parent of the current node. |
java.lang.String |
getParentName()
Returns the parent's name of the current node. |
java.lang.Object |
getParentNode()
Returns the parent of the current node. |
protected FactoryBuilderSupport |
getProxyBuilder()
Returns the current builder that serves as a proxy. Proxy builders are useful for changing the building context, thus enabling mix & match builders. |
protected void |
handleNodeAttributes(java.lang.Object node,
java.util.Map attributes)
Assigns any existing properties to the node. It will call attributeDelegates before passing control to the factory that built 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 |
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. It will call any registered postInstantiateDelegates, if you override this method be sure to call this impl somewhere in your code. |
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. 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(java.lang.Object name,
java.util.Map attributes,
java.lang.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(java.lang.String theName,
java.lang.Class beanClass)
Registers a factory for a JavaBean. The JavaBean clas should have a no-args constructor. |
void |
registerFactory(java.lang.String name,
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 Factory |
resolveFactory(java.lang.Object name,
java.util.Map attributes,
java.lang.Object value)
Returns the Factory associated with name. This is a hook for subclasses to plugin a custom strategy for mapping names to factories. |
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. |
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 stablish parent/child relationships. |
protected void |
setProxyBuilder(FactoryBuilderSupport proxyBuilder)
Sets the builder to be used as a proxy. |
java.lang.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. |
java.lang.Object |
withBuilder(FactoryBuilderSupport builder,
java.lang.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. |
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. 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.Binding |
---|
getProperty, getVariable, getVariables, setProperty, setVariable |
Methods inherited from class groovy.lang.GroovyObjectSupport |
---|
getMetaClass, setMetaClass |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
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
private static final java.util.logging.Logger LOG
private java.util.LinkedList contexts
private java.util.LinkedList attributeDelegates
private java.util.List disposalClosures
private java.util.Map factories
private Closure nameMappingClosure
private FactoryBuilderSupport proxyBuilder
private java.util.LinkedList preInstantiateDelegates
private java.util.LinkedList postInstantiateDelegates
private java.util.LinkedList postNodeCompletionDelegates
Constructor Detail |
---|
public FactoryBuilderSupport()
public FactoryBuilderSupport(Closure nameMappingClosure)
Method Detail |
---|
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 java.util.Map getFactories()
public java.util.Map getContext()
public java.lang.Object getCurrent()
public Factory getCurrentFactory()
public java.lang.String getCurrentName()
public Factory getParentFactory()
public java.lang.Object getParentNode()
public java.lang.String getParentName()
public java.util.Map getParentContext()
private java.lang.Object getContextAttribute(java.lang.String key)
public java.lang.Object invokeMethod(java.lang.String methodName)
methodName
- the name of the method to invoke
public 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 call
public Closure addAttributeDelegate(Closure attrDelegate)
attrDelegate
- public void removeAttributeDelegate(Closure attrDelegate)
attrDelegate
- public Closure addPreInstantiateDelegate(Closure delegate)
delegate
- public void removePreInstantiateDelegate(Closure delegate)
delegate
- public Closure addPostInstantiateDelegate(Closure delegate)
delegate
- public void removePostInstantiateDelegate(Closure delegate)
delegate
- public Closure addPostNodeCompletionDelegate(Closure delegate)
delegate
- public void removePostNodeCompletionDelegate(Closure delegate)
delegate
- public void registerBeanFactory(java.lang.String theName, java.lang.Class beanClass)
public void registerFactory(java.lang.String name, Factory factory)
protected java.lang.Object createNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
protected Factory resolveFactory(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
private java.lang.Object doInvokeMethod(java.lang.String methodName, java.lang.Object name, java.lang.Object args)
protected java.lang.Object getName(java.lang.String methodName)
methodName
- the name of the desired method
protected FactoryBuilderSupport getProxyBuilder()
protected void handleNodeAttributes(java.lang.Object node, java.util.Map attributes)
protected 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 popContext()
protected void postInstantiate(java.lang.Object name, java.util.Map attributes, java.lang.Object node)
protected java.lang.Object postNodeCompletion(java.lang.Object parent, java.lang.Object node)
node
- the current node being processedparent
- the parent of the node being processed
protected void preInstantiate(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
protected 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)
protected void setParent(java.lang.Object parent, java.lang.Object child)
protected void setProxyBuilder(FactoryBuilderSupport proxyBuilder)
protected java.util.LinkedList getContexts()
public 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()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |