public class Node
extends java.lang.Object
implements java.io.Serializable
{foo a=1 b="abc"}
or nested
metadata like {foo a=1 b="123" { bar x=12 text="hello" }}
Constructor and Description |
---|
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.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. |
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. |
Modifier and Type | Method and Description |
---|---|
boolean |
append(Node child) |
Node |
appendNode(java.lang.Object name) |
Node |
appendNode(java.lang.Object name,
java.util.Map attributes) |
Node |
appendNode(java.lang.Object name,
java.util.Map attributes,
java.lang.Object value) |
Node |
appendNode(java.lang.Object name,
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)
Provides lookup of elements by non-namespaced name
|
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() |
public Node(Node parent, java.lang.Object name)
name
and if a parent is supplied, adds
the newly created node as a child of the parent.parent
- the parent node or null if no parentname
- the name of the nodepublic Node(Node parent, java.lang.Object name, java.lang.Object value)
name
with value value
and
if a parent is supplied, adds the newly created node as a child of the parent.parent
- the parent node or null if no parentname
- the name of the nodevalue
- the Node value, e.g. some text but in general any Objectpublic Node(Node parent, java.lang.Object name, java.util.Map attributes)
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.parent
- the parent node or null if no parentname
- the name of the nodeattributes
- a Map of name-value pairspublic Node(Node parent, java.lang.Object name, java.util.Map attributes, java.lang.Object value)
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.parent
- the parent node or null if no parentname
- the name of the nodeattributes
- a Map of name-value pairsvalue
- the Node value, e.g. some text but in general any Objectpublic boolean append(Node child)
public boolean remove(Node child)
public Node appendNode(java.lang.Object name, java.util.Map attributes)
public Node appendNode(java.lang.Object name)
public Node appendNode(java.lang.Object name, java.lang.Object value)
public Node appendNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
public Node replaceNode(Closure c)
c
- A Closure defining the new nodes using builder-style notation.public void plus(Closure c)
c
- A Closure defining the new sibling nodes to add using builder-style notation.protected static void setMetaClass(MetaClass metaClass, java.lang.Class nodeClass)
public java.lang.String text()
public java.util.Iterator iterator()
public java.util.List children()
public java.util.Map attributes()
public java.lang.Object attribute(java.lang.Object key)
public java.lang.Object name()
public java.lang.Object value()
public void setValue(java.lang.Object value)
public Node parent()
protected void setParent(Node parent)
public java.lang.Object get(java.lang.String key)
key
- the name (or shortcut key) of the node(s) of interestpublic NodeList getAt(QName name)
name
- the QName of interestpublic java.util.List depthFirst()
public java.util.List breadthFirst()
public java.lang.String toString()
toString
in class java.lang.Object
public void print(java.io.PrintWriter out)