ilog.rules.brl.syntaxtree

Class IlrSyntaxTree.Node

  • All Implemented Interfaces:
    ilog.rules.brl.semantic.IlrBRLSemanticContext.Position, java.io.Serializable, java.lang.Cloneable
    Enclosing class:
    IlrSyntaxTree


    public class IlrSyntaxTree.Node
    extends IlrPropertyManager
    implements java.lang.Cloneable, java.io.Serializable, ilog.rules.brl.semantic.IlrBRLSemanticContext.Position
    The syntax tree is composed of nodes that are instances of IlrSyntaxTree.Node. Each node has a name, which is the name of the corresponding element in the schema definition.

    Each node can contain:

    The parent of a node can be obtained with the 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().

    Since:
    JRules 4.0
    See Also:
    Serialized Form
    • Method Detail

      • getName

        public java.lang.String getName()
        Gets the name of this node, which is the name of the corresponding element in the XML representation.
        Returns:
        The name of this node.
      • getType

        public java.lang.String getType()
        Gets the type of this node, which is the type of the corresponding element in the grammar.
        Returns:
        The type of this node.
      • hasContents

        public boolean hasContents()
        Checks if the node has text content.
        Returns:
        true if the node has some text content, false otherwise.
      • getContents

        public java.lang.String getContents()
        Gets the text content of the node, which is the content of the corresponding element in the XML representation.
        Returns:
        The text content of the node.
      • hasSuperNode

        public boolean hasSuperNode()
        Checks if the node has a super node.
        Returns:
        true if the node has a super node, false otherwise.
      • getSuperNode

        public IlrSyntaxTree.Node getSuperNode()
        Gets the parent node in the syntax tree.
        Returns:
        The parent node in the syntax tree.
      • getRoot

        public IlrSyntaxTree.Node getRoot()
        Gets the root node of the syntax tree.
        Returns:
        The root node of the syntax tree.
      • getSubNode

        public IlrSyntaxTree.Node getSubNode(java.lang.String name)
        Gets the first subnode that has a particular name.
        Since:
        JRules 4.5
        Parameters:
        name - The name of the subnode to search for.
        Returns:
        The first subnode with the specified name, or null if none is found.
      • hasSubNode

        public boolean hasSubNode(java.lang.String name)
        Checks if this node has a subnode with a particular name.
        Since:
        JRules 4.5
        Parameters:
        name - The name of the subnode to check for.
        Returns:
        true if this node has a subnode with the specified name, false otherwise.
      • getSubNode

        public IlrSyntaxTree.Node getSubNode(java.lang.String name,
                                    int index)
        Gets the nth subnode that has a particular name.
        Since:
        JRules 4.5
        Throws:
        java.lang.IllegalArgumentException - if index is not greater than 0.
        Parameters:
        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.
        Returns:
        The nth subnode with name name,null if none is found.
      • getSubNode

        public IlrSyntaxTree.Node getSubNode(int index)
        Gets the subnode at a specified position.
        Throws:
        java.lang.IllegalArgumentException - if index is not greater than 0.
        Parameters:
        index - The position of the subnode to search for, or null if index is greater than the number of subnodes.
        Returns:
        The subnode at the position indicated by index
      • getSubNode

        public IlrSyntaxTree.Node getSubNode(IlrSyntaxTree.NodeTester tester)
        Gets the first node to satisfy a particular test.
        Since:
        JRules 4.5
        Parameters:
        tester - The object used to test the nodes.
        Returns:
        The first subnode which satisfies the test, or null if none is found.
      • subNodesCount

        public int subNodesCount()
        Counts the subnodes for this node.
        Returns:
        The number of subnodes for this node.
      • nodeIndex

        public int nodeIndex(IlrSyntaxTree.Node node)
        Gets the index of the specified subnode.
        Since:
        JRules 4.5
        Parameters:
        node - The node for which the index is returned.
        Returns:
        The index of the specified node, or -1 if node is not a subnode of this node.
      • hasSubNodes

        public boolean hasSubNodes()
        Checks if this node has subnodes.
        Returns:
        true if this node has at least one subnode, false otherwise.
      • getSyntaxTree

        public IlrSyntaxTree getSyntaxTree()
        Gets the syntax tree that contains this node.
        Returns:
        The syntax tree that contains this node.
      • findSuperNode

        public IlrSyntaxTree.Node findSuperNode(java.lang.String name)
        Finds the first node among the ancestors of this node that has a particular name.
        Parameters:
        name - The name of the node to search for.
        Returns:
        The first node among the ancestors of this node with the specified name.
      • hasSuperNode

        public boolean hasSuperNode(IlrSyntaxTree.Node ancestor)
        Finds if the supplied node belong to the ancestors of this node
        Parameters:
        ancestor - A candidate ancestor
        Returns:
        True if supplied noe is in one of the ancestors of this node.
      • findSubNode

        public IlrSyntaxTree.Node findSubNode(java.lang.String name)
        Finds the first subnode among the children of this node that has a particular name.

        This method performs a depth-first search.

        Parameters:
        name - The name of the node to search for.
        Returns:
        The first subnode among the children of this node with the specified name.
      • findSubNode

        public IlrSyntaxTree.Node findSubNode(IlrSyntaxTree.NodeTester tester)
        Finds the first subnode among all the children of this node that satisfies a particular test.

        This method performs a depth-first search.

        Parameters:
        tester - The object used to test the nodes.
        Returns:
        The first subnode which satisfies the test, or null if none is found.
      • visit

        public final boolean visit(IlrSyntaxTree.Visitor visitor)
        Applies a visitor to this node. This method calls the method visit of the IlrSyntaxTree.Visitor with itself as its argument, then it calls it on all of its subnodes.
        Parameters:
        visitor - The visitor.
      • iterator

        public IlrSyntaxTree.Iterator iterator()
        Gets an iterator over the subnodes of this node. The iterator navigates through the children of this node in a depth-first manner.
        Returns:
        An Iterator object.
      • iterator

        public IlrSyntaxTree.Iterator iterator(java.lang.String name)
        Gets an iterator over the subnodes of this node. The iterator navigates through the children of the node in a depth-first manner. It iterates only over the nodes which have the name name.

        This is a shortcut for:

         new Iterator(this, new NameTester(name))
         

        Parameters:
        name - The name of the node(s) included in the iteration.
        Returns:
        An Iterator object.
      • iterator

        public 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.

        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)
         

        Since:
        JRules 4.5
        Parameters:
        name - The name of the node(s) included in the iteration.
        direction - The direction the iterator takes when it navigates through the syntax tree.
        Returns:
        An Iterator object.
      • getNodePath

        public java.lang.String getNodePath()
        Gets the absolute path to this node in an XPath-like syntax.
        Since:
        JRules 4.5
        Returns:
        The absolute path to this node.

© Copyright IBM Corp. 1987, 2017