public class Node extends Object implements Serializable, Cloneable
{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,
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,
Object name,
Map attributes)
Creates a new Node named
name with
attributes specified in the attributes Map. |
Node(Node parent,
Object name,
Map attributes,
Object value)
Creates a new Node named
name with value value and
with attributes specified in the attributes Map. |
Node(Node parent,
Object name,
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)
Appends a child to the current node.
|
Node |
appendNode(Object name)
Creates a new node as a child of the current node.
|
Node |
appendNode(Object name,
Map attributes)
Creates a new node as a child of the current node.
|
Node |
appendNode(Object name,
Map attributes,
Object value)
Creates a new node as a child of the current node.
|
Node |
appendNode(Object name,
Object value)
Creates a new node as a child of the current node.
|
Object |
attribute(Object key)
Provides lookup of attributes by key.
|
Map |
attributes()
Returns a
Map of the attributes of the node or an empty Map
if the node does not have any attributes. |
List |
breadthFirst()
Provides a collection of all the nodes in the tree
using a breadth-first preorder traversal.
|
List |
breadthFirst(boolean preorder)
Provides a collection of all the nodes in the tree
using a breadth-first traversal.
|
void |
breadthFirst(Closure c)
Calls the provided closure for all the nodes in the tree
using a breadth-first preorder traversal.
|
void |
breadthFirst(Map<String,Object> options,
Closure c)
Calls the provided closure for all the nodes in the tree
using a breadth-first traversal.
|
List |
children()
Returns a
List of the nodes children. |
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.
|
List |
depthFirst()
Provides a collection of all the nodes in the tree
using a depth-first preorder traversal.
|
List |
depthFirst(boolean preorder)
Provides a collection of all the nodes in the tree
using a depth-first traversal.
|
void |
depthFirst(Closure c)
Provides a collection of all the nodes in the tree
using a depth-first preorder traversal.
|
void |
depthFirst(Map<String,Object> options,
Closure c)
Provides a collection of all the nodes in the tree
using a depth-first traversal.
|
Object |
get(String key)
Provides lookup of elements by non-namespaced name
|
NodeList |
getAt(QName name)
Provides lookup of elements by QName.
|
Iterator |
iterator()
Returns an
Iterator of the children of the node. |
List<String> |
localText()
Returns the list of any direct String nodes of this node.
|
Object |
name()
Returns an
Object representing the name of the node. |
Node |
parent()
Returns the parent of the node.
|
void |
plus(Closure c)
Adds sibling nodes (defined using builder-style notation via a Closure) after the current node.
|
void |
print(PrintWriter out)
Writes the node to the specified
PrintWriter . |
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.
|
Node |
replaceNode(Node n)
Replaces the current node with the supplied node.
|
protected static void |
setMetaClass(MetaClass metaClass,
Class nodeClass)
Extension point for subclasses to override the metaclass.
|
protected void |
setParent(Node parent)
Adds or replaces the parent of the node.
|
void |
setValue(Object value)
Adds or replaces the value of the node.
|
String |
text()
Returns the textual representation of the current node and all its child nodes.
|
BigDecimal |
toBigDecimal()
Converts the text of this GPathResult to a BigDecimal object.
|
BigInteger |
toBigInteger()
Converts the text of this GPathResult to a BigInteger object.
|
Double |
toDouble()
Converts the text of this GPathResult to a Double object.
|
Float |
toFloat()
Converts the text of this GPathResult to a Float object.
|
Integer |
toInteger()
Converts the text of this GPathResult to a Integer object.
|
Long |
toLong()
Converts the text of this GPathResult to a Long object.
|
String |
toString() |
Object |
value()
Returns an
Object representing the value of the node. |
public Node(Node parent, 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, Object name, 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, Object name, 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, Object name, Map attributes, 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 Object clone()
public boolean append(Node child)
child
- the child to appendtrue
public boolean remove(Node child)
child
- the child to removetrue
if the param was a child of the current nodepublic Node appendNode(Object name, Map attributes)
name
- the name of the new nodeattributes
- the attributes of the new nodeNode
public Node appendNode(Object name)
name
- the name of the new nodeNode
public Node appendNode(Object name, Object value)
name
- the name of the new nodevalue
- the value of the new nodeNode
public Node appendNode(Object name, Map attributes, Object value)
name
- the name of the new nodeattributes
- the attributes of the new nodevalue
- the value of the new nodeNode
public Node replaceNode(Closure c)
c
- A Closure defining the new nodes using builder-style notation.public Node replaceNode(Node n)
n
- the new Nodepublic void plus(Closure c)
c
- A Closure defining the new sibling nodes to add using builder-style notation.protected static void setMetaClass(MetaClass metaClass, Class nodeClass)
metaClass
- the original metaclassnodeClass
- the class whose metaclass we wish to override (this class or a subclass)public String text()
public Iterator iterator()
Iterator
of the children of the node.public List children()
List
of the nodes children.public Map attributes()
Map
of the attributes of the node or an empty Map
if the node does not have any attributes.public Object attribute(Object key)
key
- the key of interestnull
if no match existspublic Object name()
Object
representing the name of the node.null
if name is emptypublic Object value()
Object
representing the value of the node.null
if value is emptypublic void setValue(Object value)
value
- the new value of the nodepublic Node parent()
null
for the root nodeprotected void setParent(Node parent)
parent
- the new parent of the nodepublic Object get(String key)
key
- the name (or shortcut key) of the node(s) of interestpublic NodeList getAt(QName name)
name
- the QName of interestpublic List depthFirst()
public List depthFirst(boolean preorder)
preorder
- if false, a postorder depth-first traversal will be performedpublic void depthFirst(Closure c)
c
- the closure to run for each node (a one or two parameter can be used; if one parameter is given the
closure will be passed the node, for a two param closure the second parameter will be the level).public void depthFirst(Map<String,Object> options, Closure c)
options
- map containing optionsc
- the closure to run for each node (a one or two parameter can be used; if one parameter is given the
closure will be passed the node, for a two param closure the second parameter will be the level).public List breadthFirst()
public List breadthFirst(boolean preorder)
preorder
- if false, a postorder breadth-first traversal will be performedpublic void breadthFirst(Closure c)
c
- the closure to run for each node (a one or two parameter can be used; if one parameter is given the
closure will be passed the node, for a two param closure the second parameter will be the level).public void breadthFirst(Map<String,Object> options, Closure c)
options
- map containing optionsc
- the closure to run for each node (a one or two parameter can be used; if one parameter is given the
closure will be passed the node, for a two param closure the second parameter will be the level).public List<String> localText()
public void print(PrintWriter out)
PrintWriter
.out
- the writer receiving the outputpublic Integer toInteger()
Integer
public Long toLong()
Long
public Float toFloat()
Float
public Double toDouble()
Double
public BigDecimal toBigDecimal()
BigDecimal
public BigInteger toBigInteger()
BigInteger