|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovy.util.Node
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" }}
Constructor Summary | |
Node(Node parent, java.lang.Object name)
Creates a new Node named |
|
Node(Node parent, java.lang.Object name, java.lang.Object value)
Creates a new Node named |
|
Node(Node parent, java.lang.Object name, java.util.Map attributes)
Creates a new Node named |
|
Node(Node parent, java.lang.Object name, java.util.Map attributes, java.lang.Object value)
Creates a new Node named |
Method Summary | |
---|---|
boolean
|
append(Node child)
Appends a child to the current node. |
Node
|
appendNode(java.lang.Object name, java.util.Map attributes)
Creates a new node as a child of the current node. |
Node
|
appendNode(java.lang.Object name)
Creates a new node as a child of the current node. |
Node
|
appendNode(java.lang.Object name, java.lang.Object value)
Creates a new node as a child of the current node. |
Node
|
appendNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
Creates a new node as a child of the current node. |
java.lang.Object
|
attribute(java.lang.Object key)
|
java.util.Map
|
attributes()
Returns a |
java.util.List
|
breadthFirst()
Provides a collection of all the nodes in the tree using a breadth-first traversal. |
java.util.List
|
children()
|
java.lang.Object
|
clone()
Creates a new Node with the same name, no parent, shallow cloned attributes and if the value is a NodeList, a (deep) clone of those nodes. |
java.util.List
|
depthFirst()
Provides 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()
Returns an |
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)
Removes a child of the current node. |
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)
Extension point for subclasses to override the metaclass. |
protected void
|
setParent(Node parent)
|
void
|
setValue(java.lang.Object value)
|
java.lang.String
|
text()
Returns the textual representation of the current node and all its child nodes. |
java.lang.String
|
toString()
|
java.lang.Object
|
value()
|
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long, int), java.lang.Object#wait(long), 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 |
---|
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 node
public 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 Object
public 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 pairs
public 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 Object
Method Detail |
---|
public boolean append(Node child)
child
- the child to appendtrue
public Node appendNode(java.lang.Object name, java.util.Map attributes)
name
- the name of the new nodeattributes
- the attributes of the new nodeNode
public Node appendNode(java.lang.Object name)
name
- the name of the new nodeNode
public Node appendNode(java.lang.Object name, java.lang.Object value)
name
- the name of the new nodevalue
- the value of the new nodeNode
public Node appendNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
name
- the name of the new nodeattributes
- the attributes of the new nodevalue
- the value of the new nodeNode
public java.lang.Object attribute(java.lang.Object key)
public java.util.Map attributes()
Map
of the attributes of the node or an empty Map
if the node does not have any attributes.
public java.util.List breadthFirst()
public java.util.List children()
public Object clone() { public java.lang.Object clone()
public java.util.List depthFirst()
public java.lang.Object get(java.lang.String key)
public NodeList getAt(QName name)
name
- the QName of interest
public java.util.Iterator iterator()
Iterator
of the children of the node.
public java.lang.Object name()
public Node parent()
public void plus(Closure c)
c
- A Closure defining the new sibling nodes to add using builder-style notation.
public void print(java.io.PrintWriter out)
public boolean remove(Node child)
child
- the child to removetrue
if the param was a child of the current node
public Node replaceNode(Closure c)
c
- A Closure defining the new nodes using builder-style notation.
protected static void setMetaClass(MetaClass metaClass, java.lang.Class nodeClass)
metaClass
- the original metaclassnodeClass
- the class whose metaclass we wish to override (this class or a subclass)
protected void setParent(Node parent)
public void setValue(java.lang.Object value)
public java.lang.String text()
public java.lang.String toString()
public java.lang.Object value()
Groovy Documentation