org.nanocontainer.script.groovy
Class GroovyNodeBuilder

java.lang.Object
  extended bygroovy.lang.GroovyObjectSupport
      extended bygroovy.util.BuilderSupport
          extended byorg.nanocontainer.script.groovy.GroovyNodeBuilder
All Implemented Interfaces:
groovy.lang.GroovyObject
Direct Known Subclasses:
DynaopGroovyNodeBuilder

public class GroovyNodeBuilder
extends groovy.util.BuilderSupport

Builds node trees of PicoContainers and Pico components using GroovyMarkup.

Simple example usage in your groovy script:

 builder = new org.nanocontainer.script.groovy.GroovyNodeBuilder()
 pico = builder.container(parent:parent) {
   component(class:org.nanocontainer.testmodel.DefaultWebServerConfig)
   component(class:org.nanocontainer.testmodel.WebServerImpl)
 }
 

Extending/Enhancing GroovyNodeBuilder

Often-times people need there own assembly commands that are needed for extending/enhancing the node builder tree. The perfect example of this is DynaopGroovyNodeBuilder which provides a new vocabulary for the groovy node builder with terms such as 'aspect', 'pointcut', etc.

GroovyNodeBuilder provides two primary ways of enhancing the nodes supported by the groovy builder: NodeBuilderDecorationDelegate and special node handlers BuilderNode. Using NodeBuilderDecorationDelegate is often a preferred method because it is ultimately script independent. However, replacing an existing GroovyNodeBuilder's behavior is currently the only way to replace the behavior of an existing groovy node handler.

Version:
$Revision: 2695 $
Author:
James Strachan, Paul Hammant, Aslak Hellesøy, Michael Rimov, Mauro Talevi

Field Summary
static boolean PERFORM_ATTRIBUTE_VALIDATION
          Flag indicating that the attribute validation should be performed.
static boolean SKIP_ATTRIBUTE_VALIDATION
          Flag indicating that attribute validation should be skipped.
 
Constructor Summary
GroovyNodeBuilder()
          Default constructor.
GroovyNodeBuilder(org.nanocontainer.script.NodeBuilderDecorationDelegate decorationDelegate, boolean performAttributeValidation)
          Allows the composition of a NodeBuilderDecorationDelegate -- an object that extends the capabilities of the GroovyNodeBuilder with new tags, new capabilities, etc.
 
Method Summary
protected  java.lang.Object createNode(java.lang.Object name)
           
protected  java.lang.Object createNode(java.lang.Object name, java.util.Map attributes)
           
protected  java.lang.Object createNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
          Override of create node.
protected  java.lang.Object createNode(java.lang.Object name, java.lang.Object value)
           
protected  java.lang.Object doInvokeMethod(java.lang.String s, java.lang.Object name, java.lang.Object args)
           
 org.nanocontainer.script.NodeBuilderDecorationDelegate getDecorationDelegate()
          Retrieve the current decoration delegate.
 BuilderNode getNode(java.lang.String tagName)
          Returns an appropriate node handler for a given node and
 GroovyNodeBuilder setNode(BuilderNode newGroovyNode)
          Add's a groovy node handler to the table of possible handlers.
protected  void setParent(java.lang.Object parent, java.lang.Object child)
           
 
Methods inherited from class groovy.util.BuilderSupport
getCurrent, getName, invokeMethod, invokeMethod, nodeCompleted, setClosureDelegate, setCurrent
 
Methods inherited from class groovy.lang.GroovyObjectSupport
getMetaClass, getProperty, setMetaClass, setProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PERFORM_ATTRIBUTE_VALIDATION

public static boolean PERFORM_ATTRIBUTE_VALIDATION
Flag indicating that the attribute validation should be performed.


SKIP_ATTRIBUTE_VALIDATION

public static boolean SKIP_ATTRIBUTE_VALIDATION
Flag indicating that attribute validation should be skipped.

Constructor Detail

GroovyNodeBuilder

public GroovyNodeBuilder(org.nanocontainer.script.NodeBuilderDecorationDelegate decorationDelegate,
                         boolean performAttributeValidation)
Allows the composition of a NodeBuilderDecorationDelegate -- an object that extends the capabilities of the GroovyNodeBuilder with new tags, new capabilities, etc.

Parameters:
decorationDelegate - NodeBuilderDecorationDelegate
performAttributeValidation - should be set to PERFORM_ATTRIBUTE_VALIDATION or SKIP_ATTRIBUTE_VALIDATION
See Also:
AopNodeBuilderDecorationDelegate

GroovyNodeBuilder

public GroovyNodeBuilder()
Default constructor.

Method Detail

setParent

protected void setParent(java.lang.Object parent,
                         java.lang.Object child)

doInvokeMethod

protected java.lang.Object doInvokeMethod(java.lang.String s,
                                          java.lang.Object name,
                                          java.lang.Object args)

createNode

protected java.lang.Object createNode(java.lang.Object name)

createNode

protected java.lang.Object createNode(java.lang.Object name,
                                      java.lang.Object value)

createNode

protected java.lang.Object createNode(java.lang.Object name,
                                      java.util.Map attributes,
                                      java.lang.Object value)
Override of create node. Called by BuilderSupport. It examines the current state of the builder and the given parameters and dispatches the code to one of the create private functions in this object.

Parameters:
name - The name of the groovy node we're building. Examples are 'container', and 'grant',
attributes - Map attributes of the current invocation.
value - A closure passed into the node. Currently unused.
Returns:
Object the created object.

getDecorationDelegate

public org.nanocontainer.script.NodeBuilderDecorationDelegate getDecorationDelegate()
Retrieve the current decoration delegate.

Returns:
NodeBuilderDecorationDelegate, should never be null.

getNode

public BuilderNode getNode(java.lang.String tagName)
Returns an appropriate node handler for a given node and

Parameters:
tagName - String
Returns:
CustomGroovyNode the appropriate node builder for the given tag name, or null if no handler exists. (In which case, the Delegate receives the createChildContainer() call)

setNode

public GroovyNodeBuilder setNode(BuilderNode newGroovyNode)
Add's a groovy node handler to the table of possible handlers. If a node handler with the same node name already exists in the map of handlers, then the GroovyNode replaces the existing node handler.

Parameters:
newGroovyNode - CustomGroovyNode
Returns:
GroovyNodeBuilder to allow for method chaining.

createNode

protected java.lang.Object createNode(java.lang.Object name,
                                      java.util.Map attributes)


Copyright © 2003-2007 Codehaus. All Rights Reserved.