001    package nl.cwi.sen1.tide.tool.support;
002    
003    import java.util.Iterator;
004    
005    public class Rule
006    {
007      private static int TYPE_UNKNOWN    = 0;
008      private static int TYPE_BREAKPOINT = 1;
009      private static int TYPE_WATCHPOINT = 2;
010    
011      private int  rid;
012      private boolean enabled;
013      private Port port;
014      private Expr cond;
015      private Expr act;
016      private String tag;
017    
018      private int type;
019    
020      //{{{ public Rule(int rid, Port port, Expr cond, Expr act, tag, enabled)
021    
022      public Rule(int rid, Port port, Expr cond, Expr act, String tag, boolean enabled)
023      {
024        this.rid  = rid;
025        this.port = port;
026        this.cond = cond;
027        this.act  = act;
028        this.tag  = tag;
029        this.enabled = enabled;
030      }
031    
032      //}}}
033      //{{{ public int getRid()
034    
035      public int getRid()
036      {
037        return rid;
038      }
039    
040      //}}}
041      //{{{ public Port getPort()
042    
043      public Port getPort()
044      {
045        return port;
046      }
047    
048      //}}}
049      //{{{ public Expr getCondition()
050    
051      public Expr getCondition()
052      {
053        return cond;
054      }
055    
056      //}}}
057      //{{{ public Expr getAction()
058    
059      public Expr getAction()
060      {
061        return act;
062      }
063    
064      //}}}
065      //{{{ public void modify(Expr condition, Expr action, boolean enabled)
066    
067      public void modify(Port port, Expr condition, Expr action, boolean enabled)
068      {
069        this.port = port;
070        this.cond = condition;
071        this.act  = action;
072        this.enabled = enabled;
073      }
074    
075      //}}}
076      //{{{ public String getTag()
077    
078      public String getTag()
079      {
080        return tag;
081      }
082    
083      //}}}
084      //{{{ public boolean isEnabled()
085    
086      public boolean isEnabled()
087      {
088        return enabled;
089      }
090    
091      //}}}
092    
093      //{{{ public Expr getLocation()
094    
095      public Expr getLocation()
096      {
097        Iterator<Expr> iter = cond.iterator();
098    
099        while (iter.hasNext()) {
100          Expr expr = iter.next();
101          if (expr.isLocation()) {
102            return expr;
103          }
104        }
105    
106        return null;
107      }
108    
109      //}}}
110      //{{{ public boolean isBreakpoint()
111    
112      public boolean isBreakpoint()
113      {
114        if (type == TYPE_UNKNOWN) {
115          type = TYPE_WATCHPOINT;
116    
117          Iterator<Expr> iter = act.iterator();
118    
119          while (iter.hasNext()) {
120            Expr expr = iter.next();
121            if (expr.isBreak()) {
122              type = TYPE_BREAKPOINT;
123              break;
124            }
125          }
126        }
127    
128        return type == TYPE_BREAKPOINT;
129      }
130    
131      //}}}
132      //{{{ public Str ing toString()
133    
134      public String toString()
135      {
136        return "rule " + rid + " [" + tag + "," + enabled + "]: " + port.toTerm() + ","
137          + cond.toTerm() + "," + act.toTerm();
138      }
139    
140      //}}}
141    }