public class IlrSyntaxTree.Node extends IlrPropertyManager implements java.lang.Cloneable, java.io.Serializable, ilog.rules.brl.semantic.IlrBRLSemanticContext.Position
IlrSyntaxTree.Node. Each node has a name, which is the name of the
corresponding element in the schema definition.
Each node can contain:
subNodesCount()
and getSubNode(int).getContents()
method.getSuperNode(), which returns null if the node is the root node
of the syntax tree.
An instance of this class is given as the first argument to the callback attached to an element in a concrete syntax property file.
This class has methods for easily navigating in the syntax tree. For
example, findSuperNode(java.lang.String), findSubNode(IlrSyntaxTree.NodeTester), and
iterator().
IlrPropertyManager.Property| Modifier and Type | Method and Description |
|---|---|
IlrSyntaxTree.Node |
findSubNode(IlrSyntaxTree.NodeTester tester)
Finds the first subnode among all the children of this node that
satisfies a particular test.
|
IlrSyntaxTree.Node |
findSubNode(java.lang.String name)
Finds the first subnode among the children of this node that has a
particular name.
|
IlrSyntaxTree.Node |
findSuperNode(java.lang.String name)
Finds the first node among the ancestors of this node that has a
particular name.
|
java.lang.String |
getContents()
Gets the text content of the node, which is the content of the
corresponding element in the XML representation.
|
java.lang.String |
getName()
Gets the name of this node, which is the name of the corresponding
element in the XML representation.
|
java.lang.String |
getNodePath()
Gets the absolute path to this node in an XPath-like syntax.
|
IlrSyntaxTree.Node |
getRoot()
Gets the root node of the syntax tree.
|
IlrSyntaxTree.Node |
getSubNode(IlrSyntaxTree.NodeTester tester)
Gets the first node to satisfy a particular test.
|
IlrSyntaxTree.Node |
getSubNode(int index)
Gets the subnode at a specified position.
|
IlrSyntaxTree.Node |
getSubNode(java.lang.String name)
Gets the first subnode that has a particular name.
|
IlrSyntaxTree.Node |
getSubNode(java.lang.String name,
int index)
Gets the nth subnode that has a particular name.
|
IlrSyntaxTree.Node |
getSuperNode()
Gets the parent node in the syntax tree.
|
IlrSyntaxTree |
getSyntaxTree()
Gets the syntax tree that contains this node.
|
java.lang.String |
getType()
Gets the type of this node, which is the type of the corresponding
element in the grammar.
|
boolean |
hasContents()
Checks if the node has text content.
|
boolean |
hasSubNode(java.lang.String name)
Checks if this node has a subnode with a particular name.
|
boolean |
hasSubNodes()
Checks if this node has subnodes.
|
boolean |
hasSuperNode()
Checks if the node has a super node.
|
boolean |
hasSuperNode(IlrSyntaxTree.Node ancestor)
Finds if the supplied node belong to the ancestors of this node
|
IlrSyntaxTree.Iterator |
iterator()
Gets an iterator over the subnodes of this node.
|
IlrSyntaxTree.Iterator |
iterator(IlrSyntaxTree.NodeTester tester)
Gets an iterator over the subnodes of this node.
|
IlrSyntaxTree.Iterator |
iterator(IlrSyntaxTree.NodeTester tester,
int direction)
Gets an iterator that navigates through the syntax tree, starting from
this node, in the specified direction.
|
IlrSyntaxTree.Iterator |
iterator(int direction)
Gets an iterator that navigates through the syntax tree, starting from
this node, in the specified direction.
|
IlrSyntaxTree.Iterator |
iterator(java.lang.String name)
Gets an iterator over the subnodes of this node.
|
IlrSyntaxTree.Iterator |
iterator(java.lang.String name,
int direction)
Gets an iterator that navigates through the syntax tree, starting from
this node, in the specified direction.
|
int |
nodeIndex(IlrSyntaxTree.Node node)
Gets the index of the specified subnode.
|
int |
subNodesCount()
Counts the subnodes for this node.
|
boolean |
visit(IlrSyntaxTree.Visitor visitor)
Applies a visitor to this node.
|
getProperty, getProperty, hasProperty, hasProperty, properties, removeAllProperties, removeProperty, removeProperty, setProperty, setPropertypublic java.lang.String getName()
public java.lang.String getType()
public boolean hasContents()
true if the node has some text content,
false otherwise.public java.lang.String getContents()
public boolean hasSuperNode()
true if the node has a super node,
false otherwise.public IlrSyntaxTree.Node getSuperNode()
public IlrSyntaxTree.Node getRoot()
public IlrSyntaxTree.Node getSubNode(java.lang.String name)
name - The name of the subnode to search for.null
if none is found.public boolean hasSubNode(java.lang.String name)
name - The name of the subnode to check for.true if this node has a subnode with the specified
name, false otherwise.public IlrSyntaxTree.Node getSubNode(java.lang.String name, int index)
java.lang.IllegalArgumentException - if index is not greater
than 0.name - The name of the node to search for.index - The index of the node. For instance, if index is 2, this
method returns the third node with the specified name.name,null
if none is found.public IlrSyntaxTree.Node getSubNode(int index)
java.lang.IllegalArgumentException - if index is not greater
than 0.index - The position of the subnode to search for, or
null if index is greater than the
number of subnodes.indexpublic IlrSyntaxTree.Node getSubNode(IlrSyntaxTree.NodeTester tester)
tester - The object used to test the nodes.null
if none is found.public int subNodesCount()
public int nodeIndex(IlrSyntaxTree.Node node)
node - The node for which the index is returned.node is
not a subnode of this node.public boolean hasSubNodes()
true if this node has at least one subnode,
false otherwise.public IlrSyntaxTree getSyntaxTree()
public IlrSyntaxTree.Node findSuperNode(java.lang.String name)
name - The name of the node to search for.public boolean hasSuperNode(IlrSyntaxTree.Node ancestor)
ancestor - A candidate ancestorpublic IlrSyntaxTree.Node findSubNode(java.lang.String name)
This method performs a depth-first search.
name - The name of the node to search for.public IlrSyntaxTree.Node findSubNode(IlrSyntaxTree.NodeTester tester)
This method performs a depth-first search.
tester - The object used to test the nodes.null
if none is found.public final boolean visit(IlrSyntaxTree.Visitor visitor)
visit of the IlrSyntaxTree.Visitor with itself as its argument,
then it calls it on all of its subnodes.visitor - The visitor.public IlrSyntaxTree.Iterator iterator()
Iterator object.public IlrSyntaxTree.Iterator iterator(IlrSyntaxTree.NodeTester tester)
The tester argument allows you to filter the nodes over
which the iterator actually iterates. If the method
IlrSyntaxTree.NodeTester.acceptNode(ilog.rules.brl.syntaxtree.IlrSyntaxTree.Node)returns false,
the subnode is skipped.
tester - A filter for the iterations.Iterator object.public IlrSyntaxTree.Iterator iterator(java.lang.String name)
name.
This is a shortcut for:
new Iterator(this, new NameTester(name))
name - The name of the node(s) included in the iteration.Iterator object.public IlrSyntaxTree.Iterator iterator(int direction)
The direction must be one of the following: IlrSyntaxTree.UP,
IlrSyntaxTree.DOWN,IlrSyntaxTree.LEFT,IlrSyntaxTree.RIGHT,IlrSyntaxTree.SUBNODES.
direction - The direction the iterator takes when it navigates
through the syntax tree.Iterator object.public IlrSyntaxTree.Iterator iterator(IlrSyntaxTree.NodeTester tester, int direction)
The tester argument allows you to filter the nodes over
which the iterator actually iterates. If the method
IlrSyntaxTree.NodeTester.acceptNode(ilog.rules.brl.syntaxtree.IlrSyntaxTree.Node)returns false,
the node is skipped.
The direction must be one of the following :IlrSyntaxTree.UP,
IlrSyntaxTree.DOWN,IlrSyntaxTree.LEFT,IlrSyntaxTree.RIGHT,IlrSyntaxTree.SUBNODES.
tester - A filter for the iterations.direction - The direction the iterator takes when it navigates
through the syntax tree.Iterator object.public IlrSyntaxTree.Iterator iterator(java.lang.String name, int direction)
It iterates only over the node which have the specified name.
The direction must be one of the following :IlrSyntaxTree.UP,
IlrSyntaxTree.DOWN,IlrSyntaxTree.LEFT,IlrSyntaxTree.RIGHT,IlrSyntaxTree.SUBNODES.
This is a shortcut for:
new Iterator(this, new NameTester(name), direction)
name - The name of the node(s) included in the iteration.direction - The direction the iterator takes when it navigates
through the syntax tree.Iterator object.public java.lang.String getNodePath()
© Copyright IBM Corp. 1987, 2017