Top Description Fields Constructors Methods
groovy.util

public abstract Class FactoryBuilderSupport

Additional top-level class in compilation unit: FactoryInterceptorMetaClass.

extends Binding
Class Inheritance
Known Direct Subclasses
groovy.util.ObjectGraphBuilder
Imports
groovy.lang.Binding, .Closure, .DelegatingMetaClass, .GroovyClassLoader, .MetaClass, .MissingMethodException, .MissingPropertyException, .Reference, .Script, org.codehaus.groovy.runtime.InvokerHelper, org.codehaus.groovy.runtime.metaclass.MissingMethodExceptionNoStack, java.lang.reflect.InvocationTargetException, .Method, .Modifier, java.util.ArrayList, .Arrays, .Collections, .Comparator, .HashMap, .LinkedHashMap, .LinkedList, .List, .Map, .Set, .TreeSet, java.util.logging.Level, .Logger

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.

Field Summary

Modifier and TypeField and Description
protected LinkedList<Closure<V>>
protected boolean
protected boolean
public static final String
private final ThreadLocal<LinkedList<Map<String, Object>>>
public static final String
public static final String
public static final String
public static final String
private final List<Closure<V>>
protected Map<String, Closure<V>>
protected Map<String, Closure<V>[]>
private final Map<String, Factory>
private FactoryBuilderSupport
private final ThreadLocal<FactoryBuilderSupport>
private static final Logger
private static final Comparator<Method>
protected Closure<V>
private Closure<V>
public static final String
public static final String
public static final String
public static final String
public static final String
public static final String
protected LinkedList<Closure<V>>
protected LinkedList<Closure<V>>
protected LinkedList<Closure<V>>
protected Closure<V>
protected Map<String, Set<String>>
protected String
public static final String

Constructor Summary

AccessConstructor and Description
public
public
FactoryBuilderSupport(boolean init)

Method Summary

Modifier and TypeMethod and Description
public Closure<V>

Returns:

attrDelegate
addAttributeDelegate
(Closure<V>
the closure to be called
attrDelegate
)

Add an attribute delegate so it can intercept attributes being set.

public void
public Closure<V>

Returns:

delegate
addPostInstantiateDelegate
(Closure<V>
the closure to invoke
delegate
)

Add a postInstantiate delegate so it can intercept nodes after they are created.

public Closure<V>

Returns:

delegate
addPostNodeCompletionDelegate
(Closure<V>
the closure to invoke
delegate
)

Add a nodeCompletion delegate so it can intercept nodes after they done with building.

public Closure<V>

Returns:

delegate
addPreInstantiateDelegate
(Closure<V>
the closure to invoke
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<T> viewClass)

public Object
build(Script script)

public Object
build(final String script, GroovyClassLoader loader)

private void
callAutoRegisterMethods(Class<T> declaredClass)

protected boolean
checkExplicitMethod(String methodName, Object args, Reference<T> result)

public static void
checkValueIsNull(Object
the node's value
value
,
Object
the node's name
name
)

Throws an exception if value is null.

public static boolean

Returns:

true if type is assignable to the value's class, false if value is null.
checkValueIsType
(Object
the node's value
value
,
Object
the node's name
name
,
Class<T>
a Class that may be assignable to the value's class
type
)

Checks type of value against builder type

public static boolean

Returns:

Returns true if type is assignable to the value's class, false if value is null or a String.
checkValueIsTypeNotString
(Object
the node's value
value
,
Object
the node's name
name
,
Class<T>
a Class that may be assignable to the value's class
type
)

Checks values against factory's type

protected Object

Returns:

the object return from the factory
createNode
(Object
the name of the node
name
,
Map<K, V>
the attributes for the node
attributes
,
Object
the value arguments for the node
value
)

This method is responsible for instantiating a node and configure its properties.

protected Object
protected Object
public void
private Object
private Object
private Map<K, V>
private Object

Returns:

the object from the factory
doInvokeMethod
(String
the name of the method being invoked
methodName
,
Object
the name of the node
name
,
Object
the arguments passed into the node
args
)

This method is the workhorse of the builder.

private void
doSetProperty(String property, Object newValue)

private void
public List<Closure<V>>
public FactoryBuilderSupport
public Map<String, Object>

Returns:

the context of the current node.
getContext
()

public Object
protected LinkedList<Map<String, Object>>

Returns:

the stack of available contexts.
getContexts
()

protected Map<String, Object>

Returns:

the map
getContinuationData
()

Stores the thread local states in a Map that can be passed across threads

public Object

Returns:

the current node being built.
getCurrent
()

public FactoryBuilderSupport

Returns:

the builder that built the current node.
getCurrentBuilder
()

public Factory

Returns:

the factory that built the current node.
getCurrentFactory
()

public String

Returns:

the factory of the parent of the current node.
getCurrentName
()

public List<Closure<V>>
public Map<String, Closure<V>>

Returns:

the explicit methods map (Unmodifiable Map).
getExplicitMethods
()

public Map<String, Closure<V>[]>

Returns:

the explicit properties map (Unmodifiable Map).
getExplicitProperties
()

public Map<String, Factory>

Returns:

the factory map (Unmodifiable Map).
getFactories
()

public Map<String, Closure<V>>

Returns:

the explicit methods map (Unmodifiable Map).
getLocalExplicitMethods
()

public Map<String, Closure<V>[]>

Returns:

the explicit properties map (Unmodifiable Map).
getLocalExplicitProperties
()

public Map<String, Factory>

Returns:

the factory map (Unmodifiable Map).
getLocalFactories
()

public Closure<V>
public Object

Returns:

the object representing the name
getName
(String
the name of the desired method
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<V>
public Map<K, V>

Returns:

the context of the parent of the current node.
getParentContext
()

public Factory

Returns:

the factory of the parent of the current node.
getParentFactory
()

public String

Returns:

the name of the parent of the current node.
getParentName
()

public Object

Returns:

the node of the parent of the current node.
getParentNode
()

public List<Closure<V>>
public List<Closure<V>>
public List<Closure<V>>
public Object
getProperty(String
the name of the property of interest
property
)

Overrides groovy.lang.Binding.getProperty.

Overrides default groovy.lang.GroovyObject.getProperty.

Overloaded to make variables appear as bean properties or via the subscript operator
public Closure<V>
protected FactoryBuilderSupport

Returns:

the current builder that serves as a proxy.
getProxyBuilder
()

Proxy builders are useful for changing the building context, thus enabling mix & match builders.

private Set<String>
public Set<String>
public Set<String>
public Object

Returns:

the variable value
getVariable
(String
the name of the variable to lookup
name
)

Overrides groovy.lang.Binding.getVariable.

public Map<K, V>
protected void
handleNodeAttributes(Object
the object returned by tne node factory
node
,
Map<K, V>
the attributes for the node
attributes
)

Assigns any existing properties to the node.

public Object

Returns:

the result of the call
invokeMethod
(String
the name of the method to invoke
methodName
)

Convenience method when no arguments are required

public Object
invokeMethod(String
the name of the method to call
methodName
,
Object
the arguments to use for the method call
args
)

Overrides default groovy.lang.GroovyObject.invokeMethod.

Invokes the given method.
protected void
newContext()

Pushes a new context on the stack.

protected void
nodeCompleted(Object
the parent of the node being processed
parent
,
Object
the current node being processed
node
)

A hook to allow nodes to be processed once they have had all of their children applied.

protected Map<String, Object>

Returns:

the content just removed
popContext
()

Removes the last context from the stack.

protected void
postInstantiate(Object
the name of the node
name
,
Map<K, V>
the attributes for the node
attributes
,
Object
the object created by the node factory
node
)

A hook after the factory creates the node and before attributes are set.

protected Object

Returns:

the node, possibly new, that represents the markup element
postNodeCompletion
(Object
the parent of the node being processed
parent
,
Object
the current node being processed
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
the name of the node
name
,
Map<K, V>
the attributes of the node
attributes
,
Object
the value argument(s) of the node
value
)

A hook before the factory creates the node.

public void
registerBeanFactory(String
name of the node
theName
,
Class<T>
the factory to handle the name
beanClass
)

Registers a factory for a JavaBean.

public void
registerBeanFactory(String
name of the node
theName
,
String
thr group to register this node in
groupName
,
final Class<T>
the factory to handle the name
beanClass
)

Registers a factory for a JavaBean.

public void
public void
registerExplicitMethod(String name, String groupName, Closure<V> closure)

public void
registerExplicitProperty(String name, Closure<V> getter, Closure<V> setter)

public void
registerExplicitProperty(String name, String groupName, Closure<V> getter, Closure<V> setter)

public void
registerFactory(String
the name of the node
name
,
Factory
the factory to return the values
factory
)

Registers a factory for a node name.

public void
registerFactory(String
the name of the node
name
,
String
thr group to register this node in
groupName
,
Factory
the factory to return the values
factory
)

Registers a factory for a node name.

public void
removeAttributeDelegate(Closure<V>
the instance of the closure to be removed
attrDelegate
)

Remove the most recently added instance of the attribute delegate.

public void
removePostInstantiateDelegate(Closure<V>
the closure to invoke
delegate
)

Remove the most recently added instance of the postInstantiate delegate.

public void
removePostNodeCompletionDelegate(Closure<V>
the closure to be removed
delegate
)

Remove the most recently added instance of the nodeCompletion delegate.

public void
removePreInstantiateDelegate(Closure<V>
the closure to invoke
delegate
)

Remove the most recently added instance of the preInstantiate delegate.

protected void
reset()

Clears the context stack.

protected Closure<V>

Returns:

the closure for the matched explicit method.
resolveExplicitMethod
(String
the name of the explicit method
methodName
,
Object
the arguments for the method
args
)

This is a hook for subclasses to plugin a custom strategy for mapping names to explicit methods.

protected Closure<V>[]

Returns:

the get and set closures (in that order) for the matched explicit property.
resolveExplicitProperty
(String
the name of the explicit method
propertyName
)

This is a hook for subclasses to plugin a custom strategy for mapping names to property methods.

protected Factory

Returns:

the Factory associated with name.
resolveFactory
(Object
the name of the factory
name
,
Map<K, V>
the attributes from the node
attributes
,
Object
value arguments from te node
value
)

This is a hook for subclasses to plugin a custom strategy for mapping names to factories.

protected void
restoreFromContinuationData(Map<String, Object>
the data retrieved from a compatible getContinuationData call
data
)

Restores the state of the current builder to the same state as an older build.

protected void
setClosureDelegate(Closure<V>
the closure on which to call setDelegate()
closure
,
Object
the node value that we've just created, which could be a builder
node
)

A strategy method to allow derived builders to use builder-trees and switch in different kinds of builders.

public void
public void
setNameMappingClosure(Closure<V> nameMappingClosure)

protected void
setNodeAttributes(Object
the object from the node
node
,
Map<K, V>
the attributes to be set
attributes
)

Maps attributes key/values to properties on node.

protected void
setParent(Object
the object from the parent node
parent
,
Object
the object from the child node
child
)

Strategy method to establish parent/child relationships.

public void
setProperty(String
the name of the property of interest
property
,
Object
the new value for the property
newValue
)

Overrides groovy.lang.Binding.setProperty.

Overrides default groovy.lang.GroovyObject.setProperty.

Overloaded to make variables appear as bean properties or via the subscript operator
public void
protected void
setProxyBuilder(FactoryBuilderSupport
the new proxy
proxyBuilder
)

Sets the builder to be used as a proxy.

public void
setVariable(String
the name of the variable to set
name
,
Object
the new value for the given variable
value
)

Overrides groovy.lang.Binding.setVariable.

Sets the value of the given variable
public Object

Returns:

the execution result of the closure.
withBuilder
(FactoryBuilderSupport
the temporary builder to switch to as proxyBuilder.
builder
,
Closure<V>
the closure to be executed under the temporary builder.
closure
)

Switches the builder's proxyBuilder during the execution of a closure.

public Object

Returns:

a node that responds to value of name with the closure's result as its value.
withBuilder
(FactoryBuilderSupport
the temporary builder to switch to as proxyBuilder.
builder
,
String
the node to build on the 'parent' builder.
name
,
Closure<V>
the closure to be executed under the temporary builder.
closure
)

Switches the builder's proxyBuilder during the execution of a closure.

public Object

Returns:

a node that responds to value of name with the closure's result as its value.
withBuilder
(Map<K, V>
additional properties for the node on the parent builder.
attributes
,
FactoryBuilderSupport
the temporary builder to switch to as proxyBuilder.
builder
,
String
the node to build on the 'parent' builder.
name
,
Closure<V>
the closure to be executed under the temporary builder.
closure
)

Switches the builder's proxyBuilder during the execution of a closure.

Inherited from groovy.lang.Binding:
hasVariableremoveVariable