Overview | Package | Class | Deprecated | Index | Help
| Groovy Documentation
| FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## groovy.util
[Java] Class Node

    java.lang.Object
      groovy.util.Node

All Implemented Interfaces:
  java.io.Serializable

    public class Node
    extends java.lang.Object

Represents an arbitrary tree node which can be used for structured metadata or any arbitrary XML-like tree. A node can have a name, a value and an optional Map of attributes. Typically the name is a String and a value is either a String or a List of other Nodes, though the types are extensible to provide a flexible structure, e.g. you could use a QName as the name which includes a namespace URI and a local name. Or a JMX ObjectName etc. So this class can represent metadata like `{foo a=1 b="abc"}` or nested metadata like `{foo a=1 b="123" { bar x=12 text="hello" }}`

Authors:
  James Strachan
  Paul King

Version:
  \$Revision\$

Constructor Summary
`Node(Node parent, java.lang.Object name)` Creates a new Node named `name` and if a parent is supplied, adds the newly created node as a child of the parent.
`Node(Node parent, java.lang.Object name, java.lang.Object value)` Creates a new Node named `name` with value `value` and if a parent is supplied, adds the newly created node as a child of the parent.
`Node(Node parent, java.lang.Object name, java.util.Map attributes)` Creates a new Node named `name` with attributes specified in the `attributes` Map.
`Node(Node parent, java.lang.Object name, java.util.Map attributes, java.lang.Object value)` Creates a new Node named `name` with value `value` and with attributes specified in the `attributes` Map.

Method Summary
`boolean` | `append(Node child)`
`Node` | `appendNode(java.lang.Object name, java.util.Map attributes)`
`Node` | `appendNode(java.lang.Object name)`
`Node` | `appendNode(java.lang.Object name, java.lang.Object value)`
`Node` | `appendNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)`
`java.lang.Object` | `attribute(java.lang.Object key)`
`java.util.Map` | `attributes()`
`java.util.List` | `breadthFirst()` Provide a collection of all the nodes in the tree using a breadth-first traversal.
`java.util.List` | `children()`
`java.util.List` | `depthFirst()` Provide a collection of all the nodes in the tree using a depth first traversal.
`java.lang.Object` | `get(java.lang.String key)`
`NodeList` | `getAt(QName name)` Provides lookup of elements by QName.
`java.util.Iterator` | `iterator()`
`java.lang.Object` | `name()`
`Node` | `parent()`
`void` | `plus(Closure c)` Adds sibling nodes (defined using builder-style notation via a Closure) after the current node.
`void` | `print(java.io.PrintWriter out)`
`boolean` | `remove(Node child)`
`Node` | `replaceNode(Closure c)` Replaces the current node with nodes defined using builder-style notation via a Closure.
`protected static void` | `setMetaClass(MetaClass metaClass, java.lang.Class nodeClass)`
`protected void` | `setParent(Node parent)`
`void` | `setValue(java.lang.Object value)`
`java.lang.String` | `text()`
`java.lang.String` | `toString()`
`java.lang.Object` | `value()`

Methods inherited from class java.lang.Object
java.lang.Object#wait(long), java.lang.Object#wait(long, int), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()

Constructor Detail

### Node

    public Node(Node parent, java.lang.Object name)

  Creates a new Node named `name` and if a parent is supplied, adds the newly created node as a child of the parent.
  Parameters:
    `parent` - the parent node or null if no parent
    `name` - the name of the node

### Node

    public Node(Node parent, java.lang.Object name, java.lang.Object value)

  Creates a new Node named `name` with value `value` and if a parent is supplied, adds the newly created node as a child of the parent.
  Parameters:
    `parent` - the parent node or null if no parent
    `name` - the name of the node
    `value` - the Node value, e.g. some text but in general any Object

### Node

    public Node(Node parent, java.lang.Object name, java.util.Map attributes)

  Creates a new Node named `name` with attributes specified in the `attributes` Map. If a parent is supplied, the newly created node is added as a child of the parent.
  Parameters:
    `parent` - the parent node or null if no parent
    `name` - the name of the node
    `attributes` - a Map of name-value pairs

### Node

    public Node(Node parent, java.lang.Object name, java.util.Map attributes, java.lang.Object value)

  Creates a new Node named `name` with value `value` and with attributes specified in the `attributes` Map. If a parent is supplied, the newly created node is added as a child of the parent.
  Parameters:
    `parent` - the parent node or null if no parent
    `name` - the name of the node
    `attributes` - a Map of name-value pairs
    `value` - the Node value, e.g. some text but in general any Object

Method Detail

### append

    public boolean append(Node child)

### appendNode

    public Node appendNode(java.lang.Object name, java.util.Map attributes)

### appendNode

    public Node appendNode(java.lang.Object name)

### appendNode

    public Node appendNode(java.lang.Object name, java.lang.Object value)

### appendNode

    public Node appendNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)

### attribute

    public java.lang.Object attribute(java.lang.Object key)

### attributes

    public java.util.Map attributes()

### breadthFirst

    public java.util.List breadthFirst()

  Provide a collection of all the nodes in the tree using a breadth-first traversal.
  Returns:
    the list of (breadth-first) ordered nodes

### children

    public java.util.List children()

### depthFirst

    public java.util.List depthFirst()

  Provide a collection of all the nodes in the tree using a depth first traversal.
  Returns:
    the list of (depth-first) ordered nodes

### get

    public java.lang.Object get(java.lang.String key)

### getAt

    public NodeList getAt(QName name)

  Provides lookup of elements by QName.
  Parameters:
    `name` - the QName of interest
  Returns:
    the nodes matching name

### iterator

    public java.util.Iterator iterator()

### name

    public java.lang.Object name()

### parent

    public Node parent()

### plus

    public void plus(Closure c)

  Adds sibling nodes (defined using builder-style notation via a Closure) after the current node.
  Parameters:
    `c` - A Closure defining the new sibling nodes to add using builder-style notation.

### print

    public void print(java.io.PrintWriter out)

### remove

    public boolean remove(Node child)

### replaceNode

    public Node replaceNode(Closure c)

  Replaces the current node with nodes defined using builder-style notation via a Closure.
  Parameters:
    `c` - A Closure defining the new nodes using builder-style notation.
  Returns:
    the last appended node

### setMetaClass

    protected static void setMetaClass(MetaClass metaClass, java.lang.Class nodeClass)

### setParent

    protected void setParent(Node parent)

### setValue

    public void setValue(java.lang.Object value)

### text

    public java.lang.String text()

### toString

    public java.lang.String toString()

### value

    public java.lang.Object value()

Groovy Documentation