public class TreeNode
extends java.lang.Object
org.w3c.dom
need
not be visible to the remainder of Jasper.
WARNING - Construction of a new tree, or modifications to an existing one, are not thread-safe and such accesses must be synchronized.
Modifier and Type | Field and Description |
---|---|
protected java.util.HashMap<java.lang.String,java.lang.String> |
attributes
The attributes of this node, keyed by attribute name,
Instantiated only if required.
|
protected java.lang.String |
body
The body text associated with this node (if any).
|
protected java.util.ArrayList<TreeNode> |
children
The children of this node, instantiated only if required.
|
protected java.lang.String |
name
The name of this node.
|
protected TreeNode |
parent
The parent node of this node.
|
Constructor and Description |
---|
TreeNode(java.lang.String name)
Construct a new node with no parent.
|
TreeNode(java.lang.String name,
TreeNode parent)
Construct a new node with the specified parent.
|
Modifier and Type | Method and Description |
---|---|
void |
addAttribute(java.lang.String name,
java.lang.String value)
Add an attribute to this node, replacing any existing attribute
with the same name.
|
void |
addChild(TreeNode node)
Add a new child node to this node.
|
java.lang.String |
findAttribute(java.lang.String name)
Return the value of the specified node attribute if it exists, or
null otherwise. |
java.util.Iterator<java.lang.String> |
findAttributes()
Return an Iterator of the attribute names of this node.
|
TreeNode |
findChild(java.lang.String name)
Return the first child node of this node with the specified name,
if there is one; otherwise, return
null . |
java.util.Iterator<TreeNode> |
findChildren()
Return an Iterator of all children of this node.
|
java.util.Iterator<TreeNode> |
findChildren(java.lang.String name)
Return an Iterator over all children of this node that have the
specified name.
|
java.lang.String |
getBody()
Return the body text associated with this node (if any).
|
java.lang.String |
getName()
Return the name of this node.
|
void |
removeAttribute(java.lang.String name)
Remove any existing value for the specified attribute name.
|
void |
removeNode(TreeNode node)
Remove a child node from this node, if it is one.
|
void |
setBody(java.lang.String body)
Set the body text associated with this node (if any).
|
java.lang.String |
toString()
Return a String representation of this TreeNode.
|
protected void |
toString(java.lang.StringBuilder sb,
int indent,
TreeNode node)
Append to the specified StringBuilder a character representation of
this node, with the specified amount of indentation.
|
protected java.util.HashMap<java.lang.String,java.lang.String> attributes
protected java.lang.String body
protected java.util.ArrayList<TreeNode> children
protected java.lang.String name
protected TreeNode parent
public TreeNode(java.lang.String name)
name
- The name of this nodepublic TreeNode(java.lang.String name, TreeNode parent)
name
- The name of this nodeparent
- The node that is the parent of this nodepublic void addAttribute(java.lang.String name, java.lang.String value)
name
- The attribute name to addvalue
- The new attribute valuepublic void addChild(TreeNode node)
node
- The new child nodepublic java.lang.String findAttribute(java.lang.String name)
null
otherwise.name
- Name of the requested attributepublic java.util.Iterator<java.lang.String> findAttributes()
public TreeNode findChild(java.lang.String name)
null
.name
- Name of the desired child elementpublic java.util.Iterator<TreeNode> findChildren()
public java.util.Iterator<TreeNode> findChildren(java.lang.String name)
name
- Name used to select childrenpublic java.lang.String getBody()
public java.lang.String getName()
public void removeAttribute(java.lang.String name)
name
- The attribute name to removepublic void removeNode(TreeNode node)
node
- The child node to removepublic void setBody(java.lang.String body)
body
- The body text (if any)public java.lang.String toString()
toString
in class java.lang.Object
protected void toString(java.lang.StringBuilder sb, int indent, TreeNode node)
sb
- The StringBuilder to append toindent
- Number of characters of indentationnode
- The TreeNode to be printed