public class Node extends Object implements Serializable, Cloneable
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 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, 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, 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. |
Type Params | Return Type | Name and description |
---|---|---|
|
public boolean |
append(Node child) Appends a child to the current node. |
|
public Node |
appendNode(Object name, Map attributes) Creates a new node as a child of the current node. |
|
public Node |
appendNode(Object name) Creates a new node as a child of the current node. |
|
public Node |
appendNode(Object name, Object value) Creates a new node as a child of the current node. |
|
public Node |
appendNode(Object name, Map attributes, Object value) Creates a new node as a child of the current node. |
|
public Object |
attribute(Object key) Provides lookup of attributes by key. |
|
public Map |
attributes() Returns a Map of the attributes of the node or an empty Map
if the node does not have any attributes. |
|
public List |
breadthFirst() Provides a collection of all the nodes in the tree using a breadth-first preorder traversal. |
|
public List |
breadthFirst(boolean preorder) Provides a collection of all the nodes in the tree using a breadth-first traversal. |
|
public void |
breadthFirst(Closure c) Calls the provided closure for all the nodes in the tree using a breadth-first preorder traversal. |
|
public void |
breadthFirst(Map<String, Object> options, Closure c) Calls the provided closure for all the nodes in the tree using a breadth-first traversal. |
|
public List |
children() Returns a List of the nodes children. |
|
public 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. |
|
public List |
depthFirst() Provides a collection of all the nodes in the tree using a depth-first preorder traversal. |
|
public List |
depthFirst(boolean preorder) Provides a collection of all the nodes in the tree using a depth-first traversal. |
|
public void |
depthFirst(Closure c) Provides a collection of all the nodes in the tree using a depth-first preorder traversal. |
|
public void |
depthFirst(Map<String, Object> options, Closure c) Provides a collection of all the nodes in the tree using a depth-first traversal. |
|
public Object |
get(String key) Provides lookup of elements by non-namespaced name |
|
public NodeList |
getAt(QName name) Provides lookup of elements by QName. |
|
public NodeList |
getAt(QName name) Provides lookup of elements by QName. |
|
public Object |
getAttribute(Object object, String attribute) |
|
public Object |
getProperty(Object object, String property) |
|
public Iterator |
iterator() Returns an Iterator of the children of the node. |
|
public List<String> |
localText() Returns the list of any direct String nodes of this node. |
|
public Object |
name() Returns an Object representing the name of the node. |
|
public Node |
parent() Returns the parent of the node. |
|
public void |
plus(Closure c) Adds sibling nodes (defined using builder-style notation via a Closure) after the current node. |
|
public void |
print(PrintWriter out) Writes the node to the specified PrintWriter . |
|
public boolean |
remove(Node child) Removes a child of the current node. |
|
public Node |
replaceNode(Closure c) Replaces the current node with nodes defined using builder-style notation via a Closure. |
|
public Node |
replaceNode(Node n) Replaces the current node with the supplied node. |
|
public void |
setAttribute(Object object, String attribute, Object newValue) |
|
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. |
|
public void |
setProperty(Object object, String property, Object newValue) |
|
public void |
setValue(Object value) Adds or replaces the value of the node. |
|
public String |
text() Returns the textual representation of the current node and all its child nodes. |
|
public BigDecimal |
toBigDecimal() Converts the text of this GPathResult to a BigDecimal object. |
|
public BigInteger |
toBigInteger() Converts the text of this GPathResult to a BigInteger object. |
|
public Double |
toDouble() Converts the text of this GPathResult to a Double object. |
|
public Float |
toFloat() Converts the text of this GPathResult to a Float object. |
|
public Integer |
toInteger() Converts the text of this GPathResult to a Integer object. |
|
public Long |
toLong() Converts the text of this GPathResult to a Long object. |
|
public String |
toString() |
|
public Object |
value() Returns an Object representing the value of the node. |
Creates a new Node named 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 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.
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 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.
parent
- the parent node or null if no parentname
- the name of the nodeattributes
- a Map of name-value pairs 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.
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 ObjectAppends a child to the current node.
child
- the child to appendtrue
Creates a new node as a child of the current node.
name
- the name of the new nodeattributes
- the attributes of the new nodeNode
Creates a new node as a child of the current node.
name
- the name of the new nodeNode
Creates a new node as a child of the current node.
name
- the name of the new nodevalue
- the value of the new nodeNode
Creates a new node as a child of the current node.
name
- the name of the new nodeattributes
- the attributes of the new nodevalue
- the value of the new nodeNode
Provides lookup of attributes by key.
key
- the key of interestnull
if no match exists Returns a Map
of the attributes of the node or an empty Map
if the node does not have any attributes.
Provides a collection of all the nodes in the tree using a breadth-first preorder traversal.
Provides a collection of all the nodes in the tree using a breadth-first traversal.
preorder
- if false, a postorder breadth-first traversal will be performedCalls the provided closure for all the nodes in the tree using a breadth-first preorder traversal.
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).Calls the provided closure for all the nodes in the tree using a breadth-first traversal. A boolean 'preorder' options is supported.
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). Returns a List
of the nodes children.
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.
Provides a collection of all the nodes in the tree using a depth-first preorder traversal.
Provides a collection of all the nodes in the tree using a depth-first traversal.
preorder
- if false, a postorder depth-first traversal will be performedProvides a collection of all the nodes in the tree using a depth-first preorder traversal.
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).Provides a collection of all the nodes in the tree using a depth-first traversal. A boolean 'preorder' options is supported.
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).Provides lookup of elements by non-namespaced name
key
- the name (or shortcut key) of the node(s) of interestProvides lookup of elements by QName.
name
- the QName of interestProvides lookup of elements by QName.
name
- the QName of interest Returns an Iterator
of the children of the node.
Returns the list of any direct String nodes of this node.
Returns an Object
representing the name of the node.
null
if name is emptyReturns the parent of the node.
null
for the root nodeAdds sibling nodes (defined using builder-style notation via a Closure) after the current node.
c
- A Closure defining the new sibling nodes to add using builder-style notation. Writes the node to the specified PrintWriter
.
out
- the writer receiving the outputRemoves a child of the current node.
child
- the child to removetrue
if the param was a child of the current nodeReplaces the current node with nodes defined using builder-style notation via a Closure.
c
- A Closure defining the new nodes using builder-style notation.Replaces the current node with the supplied node.
n
- the new NodeExtension point for subclasses to override the metaclass. The default one supports the property and @ attribute notations.
metaClass
- the original metaclassnodeClass
- the class whose metaclass we wish to override (this class or a subclass)Adds or replaces the parent of the node.
parent
- the new parent of the nodeAdds or replaces the value of the node.
value
- the new value of the nodeReturns the textual representation of the current node and all its child nodes.
Converts the text of this GPathResult to a BigDecimal object.
BigDecimal
Converts the text of this GPathResult to a BigInteger object.
BigInteger
Converts the text of this GPathResult to a Double object.
Double
Converts the text of this GPathResult to a Float object.
Float
Converts the text of this GPathResult to a Integer object.
Integer
Converts the text of this GPathResult to a Long object.
Long
Returns an Object
representing the value of the node.
null
if value is emptyCopyright © 2003-2021 The Apache Software Foundation. All rights reserved.