jag
Class Rule

java.lang.Object
  extended by jag.Rule
All Implemented Interfaces:
Serializable

public class Rule
extends Object
implements Serializable

describes a subtree situation and contains the action index; provides static method implementing rule search.

See Also:
Serialized Form

Field Summary
protected  int action
          action index; < 0 rejects the match.
protected  Class[] sub
          not null; contains ordered list of classes of root nodes of each subtree, if any; a null entry designates a non-existing subtree.
protected  boolean var
          if true, more subtrees are permitted.
static boolean verbose
          jag.verbose.
 
Constructor Summary
Rule(Class[] sub, boolean var, int action)
           
 
Method Summary
 boolean matches(int degree, List list)
          determines if rule matches tree.
static Object visit(Visitor visitor, HashMap rules, Object object, int degree, List list)
          class search to visit an object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

verbose

public static boolean verbose
jag.verbose.


sub

protected final Class[] sub
not null; contains ordered list of classes of root nodes of each subtree, if any; a null entry designates a non-existing subtree.


var

protected final boolean var
if true, more subtrees are permitted.


action

protected final int action
action index; < 0 rejects the match.

Constructor Detail

Rule

public Rule(Class[] sub,
            boolean var,
            int action)
Method Detail

matches

public boolean matches(int degree,
                       List list)
determines if rule matches tree.

Parameters:
degree - number of subtrees to match, >= zero.
list - subtrees to match, large enough if degree > 0.
Returns:
true if degree matches sub.length and list.get() matches sub[].

visit

public static Object visit(Visitor visitor,
                           HashMap rules,
                           Object object,
                           int degree,
                           List list)
                    throws Exception
class search to visit an object. A search queue is initialized with the object's class. For each dequeued class the interfaces and the superclass are enqueued if necessary. Each dequeued class is tested if there is a rule matching the class and subtree situation.

Parameters:
visitor - implementing the action switch, not null.
rules - maps class to Rule[].
object - to be visited, not null.
degree - number of subtrees to match, >= zero.
list - subtrees to match, large enough if degree > 0.
Returns:
result of action.
Throws:
NoRuleException - if no rule can be found.
Exception