net.sf.joost.grammar
Class Tree

java.lang.Object
  extended by net.sf.joost.grammar.Tree
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
AddTree, AndTree, AttrLocalWildcardTree, AttrTree, AttrUriWildcardTree, AttrWildcardTree, AvtTree, CDataTestTree, CommentTestTree, DivTree, EqTree, FunctionTree, GeTree, GtTree, LeTree, ListTree, LocalWildcardTree, LtTree, ModTree, MultTree, NameTestTree, NeTree, NodeTestTree, NumberTree, OrTree, PiTestTree, PredicateTree, ReversableTree, RootTree, SeqTree, StringTree, SubTree, TextTestTree, UnionTree, UriWildcardTree, ValueTree, VarTree, WildcardTree

public abstract class Tree
extends Object
implements Cloneable

Objects of Tree represent nodes in the syntax tree of a pattern or an STXPath expression.

Version:
$Revision: 2.14 $ $Date: 2008/10/04 17:13:14 $
Author:
Oliver Becker

Field Summary
static int ADD
          Node type constants for type
static int AND
          Node type constants for type
static int ATTR
          Node type constants for type
static int ATTR_LOCAL_WILDCARD
          Node type constants for type
static int ATTR_URI_WILDCARD
          Node type constants for type
static int ATTR_WILDCARD
          Node type constants for type
static int AVT
          Node type constants for type
static int CDATA_TEST
          Node type constants for type
static int CHILD
          Node type constants for type
static int COMMENT_TEST
          Node type constants for type
static int DDOT
          Node type constants for type
static int DESC
          Node type constants for type
static int DIV
          Node type constants for type
static int DOT
          Node type constants for type
static int EQ
          Node type constants for type
static int FUNCTION
          Node type constants for type
static int GE
          Node type constants for type
static int GT
          Node type constants for type
static int LE
          Node type constants for type
 Tree left
          The left subtree.
static int LIST
          Node type constants for type
 String lName
          Local name if value is a qualified name.
static int LOCAL_WILDCARD
          Node type constants for type
static int LT
          Node type constants for type
static int MOD
          Node type constants for type
static int MULT
          Node type constants for type
static int NAME_TEST
          Node type constants for type
static int NE
          Node type constants for type
static int NODE_TEST
          Node type constants for type
static int NUMBER
          Node type constants for type
static int OR
          Node type constants for type
static int PI_TEST
          Node type constants for type
static int PREDICATE
          Node type constants for type
 Tree right
          The right subtree.
static int ROOT
          Node type constants for type
static int SEQ
          Node type constants for type
static int STRING
          Node type constants for type
static int SUB
          Node type constants for type
static int TEXT_TEST
          Node type constants for type
 int type
          The type of the node in the Tree.
static int UNION
          Node type constants for type
 String uri
          URI if value is a qualified name.
static int URI_WILDCARD
          Node type constants for type
 Object value
          The value of this node as an object.
static int VALUE
          Node type constants for type
static int VAR
          Node type constants for type
static int WILDCARD
          Node type constants for type
 
Constructor Summary
  Tree(int type)
          Constructs a Tree object as a leaf without a value.
  Tree(int type, Object value)
          Constructs a Tree object as a leaf.
  Tree(int type, Tree left, Tree right)
          Constructs a Tree object as a node with two subtrees.
private Tree(int type, Tree left, Tree right, Object value)
          The most general constructor
 
Method Summary
 Tree deepCopy(HashMap copies)
          Creates a deep copy of this Tree
 Value evaluate(Context context, int top)
          Evaluates the current Tree if it represents an expression.
 Value evaluate(Context context, NodeBase instruction)
          Evaluates the current Tree if it represents an expression.
 double getPriority()
          Returns the default priority of the STXPath pattern represented by this tree.
 boolean isConstant()
           
 boolean matches(Context context, int top, boolean setPosition)
          Determines if the event stack matches the pattern represented by this Tree object.
 Tree reverseAssociativity()
          May be overridden to reconstruct the current tree
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ROOT

public static final int ROOT
Node type constants for type

See Also:
Constant Field Values

CHILD

public static final int CHILD
Node type constants for type

See Also:
Constant Field Values

DESC

public static final int DESC
Node type constants for type

See Also:
Constant Field Values

UNION

public static final int UNION
Node type constants for type

See Also:
Constant Field Values

NAME_TEST

public static final int NAME_TEST
Node type constants for type

See Also:
Constant Field Values

WILDCARD

public static final int WILDCARD
Node type constants for type

See Also:
Constant Field Values

URI_WILDCARD

public static final int URI_WILDCARD
Node type constants for type

See Also:
Constant Field Values

LOCAL_WILDCARD

public static final int LOCAL_WILDCARD
Node type constants for type

See Also:
Constant Field Values

NODE_TEST

public static final int NODE_TEST
Node type constants for type

See Also:
Constant Field Values

TEXT_TEST

public static final int TEXT_TEST
Node type constants for type

See Also:
Constant Field Values

CDATA_TEST

public static final int CDATA_TEST
Node type constants for type

See Also:
Constant Field Values

COMMENT_TEST

public static final int COMMENT_TEST
Node type constants for type

See Also:
Constant Field Values

PI_TEST

public static final int PI_TEST
Node type constants for type

See Also:
Constant Field Values

FUNCTION

public static final int FUNCTION
Node type constants for type

See Also:
Constant Field Values

PREDICATE

public static final int PREDICATE
Node type constants for type

See Also:
Constant Field Values

NUMBER

public static final int NUMBER
Node type constants for type

See Also:
Constant Field Values

STRING

public static final int STRING
Node type constants for type

See Also:
Constant Field Values

ADD

public static final int ADD
Node type constants for type

See Also:
Constant Field Values

SUB

public static final int SUB
Node type constants for type

See Also:
Constant Field Values

MULT

public static final int MULT
Node type constants for type

See Also:
Constant Field Values

DIV

public static final int DIV
Node type constants for type

See Also:
Constant Field Values

MOD

public static final int MOD
Node type constants for type

See Also:
Constant Field Values

AND

public static final int AND
Node type constants for type

See Also:
Constant Field Values

OR

public static final int OR
Node type constants for type

See Also:
Constant Field Values

EQ

public static final int EQ
Node type constants for type

See Also:
Constant Field Values

NE

public static final int NE
Node type constants for type

See Also:
Constant Field Values

LT

public static final int LT
Node type constants for type

See Also:
Constant Field Values

LE

public static final int LE
Node type constants for type

See Also:
Constant Field Values

GT

public static final int GT
Node type constants for type

See Also:
Constant Field Values

GE

public static final int GE
Node type constants for type

See Also:
Constant Field Values

ATTR

public static final int ATTR
Node type constants for type

See Also:
Constant Field Values

ATTR_WILDCARD

public static final int ATTR_WILDCARD
Node type constants for type

See Also:
Constant Field Values

ATTR_URI_WILDCARD

public static final int ATTR_URI_WILDCARD
Node type constants for type

See Also:
Constant Field Values

ATTR_LOCAL_WILDCARD

public static final int ATTR_LOCAL_WILDCARD
Node type constants for type

See Also:
Constant Field Values

LIST

public static final int LIST
Node type constants for type

See Also:
Constant Field Values

SEQ

public static final int SEQ
Node type constants for type

See Also:
Constant Field Values

AVT

public static final int AVT
Node type constants for type

See Also:
Constant Field Values

VAR

public static final int VAR
Node type constants for type

See Also:
Constant Field Values

DOT

public static final int DOT
Node type constants for type

See Also:
Constant Field Values

DDOT

public static final int DDOT
Node type constants for type

See Also:
Constant Field Values

VALUE

public static final int VALUE
Node type constants for type

See Also:
Constant Field Values

type

public int type
The type of the node in the Tree.


left

public Tree left
The left subtree.


right

public Tree right
The right subtree.


value

public Object value
The value of this node as an object.


uri

public String uri
URI if value is a qualified name.


lName

public String lName
Local name if value is a qualified name.

Constructor Detail

Tree

private Tree(int type,
             Tree left,
             Tree right,
             Object value)
The most general constructor


Tree

public Tree(int type,
            Tree left,
            Tree right)
Constructs a Tree object as a node with two subtrees.


Tree

public Tree(int type,
            Object value)
Constructs a Tree object as a leaf.


Tree

public Tree(int type)
Constructs a Tree object as a leaf without a value.

Method Detail

matches

public boolean matches(Context context,
                       int top,
                       boolean setPosition)
                throws SAXException
Determines if the event stack matches the pattern represented by this Tree object.

Parameters:
context - the Context object
top - the part of the stack to be considered while matching (the upper most element is at position top-1)
setPosition - true if the context position (Context.position) should be set in case the event stack matches this pattern
Returns:
true if the stack matches the pattern represented by this Tree.
Throws:
SAXException

evaluate

public Value evaluate(Context context,
                      NodeBase instruction)
               throws SAXException
Evaluates the current Tree if it represents an expression.

Parameters:
context - the current Context
instruction - the current instruction, needed for providing locator information in the event of an error
Returns:
a new computed Value object containing the result
Throws:
SAXException

evaluate

public Value evaluate(Context context,
                      int top)
               throws SAXException
Evaluates the current Tree if it represents an expression.

Parameters:
context - the current Context
top - the part of the stack to be considered for the evaluation (the upper most element is at position top-1)
Returns:
a new computed Value object containing the result
Throws:
SAXException

reverseAssociativity

public Tree reverseAssociativity()
May be overridden to reconstruct the current tree


getPriority

public double getPriority()
Returns the default priority of the STXPath pattern represented by this tree.


isConstant

public boolean isConstant()
Returns:
whether the expression represented by this tree is constant

deepCopy

public Tree deepCopy(HashMap copies)
Creates a deep copy of this Tree

Parameters:
copies - the map of already copied objects that need to be remembered (mainly of AbstractInstruction)
Returns:
the created copy

toString

public String toString()
Overrides:
toString in class Object