Package: groovy.util

## [Java] Class BuilderSupport

- groovy.util.BuilderSupport

-     public abstract class BuilderSupport
      extends GroovyObjectSupport

  Base class for creating arbitrary nested trees of objects or events.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `BuilderSupport()` Creates a builder that manages its own node lifecycle.
    `BuilderSupport(BuilderSupport proxyBuilder)` Creates a builder that delegates node operations to another builder.
    `BuilderSupport(Closure nameMappingClosure, BuilderSupport proxyBuilder)` Creates a builder with custom name mapping and delegated node operations.

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `protected abstract Object` | `createNode(Object name)` Creates a node with the given name.
    `` | `protected abstract Object` | `createNode(Object name, Object value)` Creates a node with the given name and value.
    `` | `protected abstract Object` | `createNode(Object name, Map attributes)` Creates a node with the given name and attributes.
    `` | `protected abstract Object` | `createNode(Object name, Map attributes, Object value)` Creates a node with the given name, attributes, and value.
    `` | `protected Object` | `doInvokeMethod(String methodName, Object name, Object args)` Creates a node for the given method invocation and processes any child closure.
    `` | `protected Object` | `getCurrent()` Returns the current node on the builder stack.
    `` | `protected 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.
    `` | `public Object` | `invokeMethod(String methodName)` Convenience method when no arguments are required.
    `` | `public Object` | `invokeMethod(String methodName, Object args)` Invokes the given method. Parameters: `name` - the name of the method to call `args` - the arguments to use for the method call Returns: the result of invoking the method
    `` | `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 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.
    `` | `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.
    `` | `protected void` | `setCurrent(Object current)` Updates the current node on the builder stack.
    `` | `protected abstract void` | `setParent(Object parent, Object child)` Links a newly created child node to its parent.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class GroovyObjectSupport` | `getMetaClass, setMetaClass`

- - ### Constructor Detail

    - #### public BuilderSupport()

      Creates a builder that manages its own node lifecycle.

    - #### public BuilderSupport(BuilderSupport proxyBuilder)

      Creates a builder that delegates node operations to another builder.

      Parameters:
        `proxyBuilder` - the builder handling node creation callbacks

    - #### public BuilderSupport(@ClosureParams(value=SimpleType.class, options="java.lang.String")
      Closure nameMappingClosure, BuilderSupport proxyBuilder)

      Creates a builder with custom name mapping and delegated node operations.

      Parameters:
        `nameMappingClosure` - converts method names before node creation
        `proxyBuilder` - the builder handling node creation callbacks

  - ### Method Detail

    - #### protected abstract Object createNode(Object name)

      Creates a node with the given name.

      Parameters:
        `name` - the node name
      Returns:
        the created node

    - #### protected abstract Object createNode(Object name, Object value)

      Creates a node with the given name and value.

      Parameters:
        `name` - the node name
        `value` - the node value
      Returns:
        the created node

    - #### protected abstract Object createNode(Object name, Map attributes)

      Creates a node with the given name and attributes.

      Parameters:
        `name` - the node name
        `attributes` - the node attributes
      Returns:
        the created node

    - #### protected abstract Object createNode(Object name, Map attributes, Object value)

      Creates a node with the given name, attributes, and value.

      Parameters:
        `name` - the node name
        `attributes` - the node attributes
        `value` - the node value
      Returns:
        the created node

    - #### protected Object doInvokeMethod(String methodName, Object name, Object args)

      Creates a node for the given method invocation and processes any child closure.

      Parameters:
        `methodName` - the original method name
        `name` - the mapped node name
        `args` - the invocation arguments
      Returns:
        the created node, or a replacement from postNodeCompletion(Object, Object)

    - #### protected Object getCurrent()

      Returns the current node on the builder stack.

      Returns:
        the current node, or `null` if none is active

    - #### protected 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.

      Parameters:
        `methodName` - the name of the desired method
      Returns:
        the object representing the name

    - #### public Object invokeMethod(String methodName)

      Convenience method when no arguments are required.

      Parameters:
        `methodName` - the name of the method to invoke
      Returns:
        the result of the call

    - #### public Object invokeMethod(String methodName, Object args)

      Invokes the given method.

      Parameters:
        `name` - the name of the method to call
        `args` - the arguments to use for the method call
      Returns:
        the result of invoking the method

    - #### protected void nodeCompleted(Object parent, Object node)

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

      Parameters:
        `node` - the current node being processed
        `parent` - the parent of the node being processed

    - #### 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.

      Parameters:
        `node` - the current node being processed
        `parent` - the parent of the node being processed
      Returns:
        the node, possibly new, that represents the markup element

    - #### 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. 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).

      Parameters:
        `closure` - the closure on which to call setDelegate()
        `node` - the node value that we've just created, which could be a builder

    - #### protected void setCurrent(Object current)

      Updates the current node on the builder stack.

      Parameters:
        `current` - the current node

    - #### protected abstract void setParent(Object parent, Object child)

      Links a newly created child node to its parent.

      Parameters:
        `parent` - the parent node
        `child` - the child node