home *** CD-ROM | disk | FTP | other *** search
/ PC Online 1997 August / PCO0897.ISO / filesbbs / os2 / fp1os2.arj / OS2 / DATA / 49 / C / 0 / F_26836 / JScriptDebugger.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-05-15  |  5.2 KB  |  249 lines

  1. public class JScriptDebugger extends SJMTObject implements JScriptDebugInterface {
  2.    private JScriptRuntimeInstance aRuntimeInstance;
  3.    private String aIDString;
  4.    private Thread aModuleThread;
  5.    private JScriptManager aJScriptManager;
  6.  
  7.    public JScriptDebugger(JScriptManager var1, JScriptRuntimeInstance var2, String var3, ThreadGroup var4) {
  8.       super(var1, var3, var4);
  9.       this.aJScriptManager = var1;
  10.       this.aRuntimeInstance = var2;
  11.       this.aRuntimeInstance.SetDebugInterface(this);
  12.       this.aIDString = var3;
  13.       this.aModuleThread = null;
  14.    }
  15.  
  16.    public JScriptDebugger(JScriptManager var1, JScriptRuntimeInstance var2, String var3) {
  17.       this(var1, var2, var3, (ThreadGroup)null);
  18.    }
  19.  
  20.    public void HandleMessage(SJMessage var1) {
  21.       if (var1 instanceof JScriptAction) {
  22.          JScriptAction var2 = (JScriptAction)var1;
  23.          if (this.CanProcessAction(var2)) {
  24.             ((SJMTObject)this).AddToMessageQueue(var2);
  25.          } else {
  26.             if (var2.GetSourceObject() instanceof JScriptRuntimeInstance) {
  27.                this.NotifyObservers(var2);
  28.             }
  29.  
  30.          }
  31.       }
  32.    }
  33.  
  34.    protected void ProcessMessage(SJMessage var1) {
  35.       this.ProcessAction(var1);
  36.    }
  37.  
  38.    public final void UpdateBrowserSync() {
  39.       this.aRuntimeInstance.YieldBrowser();
  40.    }
  41.  
  42.    private final void ClearAllRTFlags() {
  43.       this.aRuntimeInstance.ClearSingleSourceStepFlag();
  44.       this.aRuntimeInstance.ClearSinglePCodeStepFlag();
  45.       this.aRuntimeInstance.ClearStepOverFlag();
  46.       this.aRuntimeInstance.ClearStepOutFlag();
  47.    }
  48.  
  49.    private final void Do_Start() {
  50.       this.StartModuleDebugThread();
  51.       this.aRuntimeInstance.SetDebugFlag();
  52.       this.aRuntimeInstance.SetSinglePCodeStepFlag();
  53.       this.NotifyObservers(new JScriptAction(5003, "start"));
  54.    }
  55.  
  56.    private final void Do_Step() {
  57.       this.StartModuleDebugThread();
  58.       this.aRuntimeInstance.SetDebugFlag();
  59.       this.ClearAllRTFlags();
  60.       this.aRuntimeInstance.SetSingleSourceStepFlag();
  61.       if (this.aRuntimeInstance.IsSleeping()) {
  62.          this.aRuntimeInstance.SetDebugContinueFlag();
  63.       }
  64.  
  65.       this.NotifyObservers(new JScriptAction(5003, "step"));
  66.    }
  67.  
  68.    private final void Do_StepOver() {
  69.       this.StartModuleDebugThread();
  70.       this.aRuntimeInstance.SetDebugFlag();
  71.       this.ClearAllRTFlags();
  72.       this.aRuntimeInstance.SetStepOverFlag();
  73.       if (this.aRuntimeInstance.IsSleeping()) {
  74.          this.aRuntimeInstance.SetDebugContinueFlag();
  75.       }
  76.  
  77.       this.NotifyObservers(new JScriptAction(5003, "step over"));
  78.    }
  79.  
  80.    private final void Do_StepOut() {
  81.       this.StartModuleDebugThread();
  82.       this.aRuntimeInstance.SetDebugFlag();
  83.       this.ClearAllRTFlags();
  84.       this.aRuntimeInstance.SetStepOutFlag();
  85.       if (this.aRuntimeInstance.IsSleeping()) {
  86.          this.aRuntimeInstance.SetDebugContinueFlag();
  87.       }
  88.  
  89.       this.NotifyObservers(new JScriptAction(5003, "step over"));
  90.    }
  91.  
  92.    private final void Do_PCodeStepOver() {
  93.       this.StartModuleDebugThread();
  94.       this.aRuntimeInstance.SetDebugFlag();
  95.       this.ClearAllRTFlags();
  96.       this.aRuntimeInstance.SetSinglePCodeStepFlag();
  97.       this.aRuntimeInstance.SetStepOverFlag();
  98.       if (this.aRuntimeInstance.IsSleeping()) {
  99.          this.aRuntimeInstance.SetDebugContinueFlag();
  100.       }
  101.  
  102.       this.NotifyObservers(new JScriptAction(5003, "P-code step over"));
  103.    }
  104.  
  105.    private final void Do_PCodeStep() {
  106.       this.StartModuleDebugThread();
  107.       this.aRuntimeInstance.SetDebugFlag();
  108.       this.ClearAllRTFlags();
  109.       this.aRuntimeInstance.SetSinglePCodeStepFlag();
  110.       if (this.aRuntimeInstance.IsSleeping()) {
  111.          this.aRuntimeInstance.SetDebugContinueFlag();
  112.       }
  113.  
  114.       this.NotifyObservers(new JScriptAction(5003, "P-code step"));
  115.    }
  116.  
  117.    private final void Do_Run() {
  118.       this.StartModuleDebugThread();
  119.       this.aRuntimeInstance.SetDebugFlag();
  120.       this.ClearAllRTFlags();
  121.       if (this.aRuntimeInstance.IsSleeping()) {
  122.          this.aRuntimeInstance.SetDebugContinueFlag();
  123.       }
  124.  
  125.       this.NotifyObservers(new JScriptAction(5003, "running..."));
  126.    }
  127.  
  128.    private final void Do_KillProgram() {
  129.       if (this.aModuleThread != null) {
  130.          this.NotifyObservers(new JScriptAction(5003, "killing..."));
  131.          this.aRuntimeInstance.ClearDebugFlag();
  132.          this.ClearAllRTFlags();
  133.          this.aRuntimeInstance.SetBreakFlag();
  134.          if (this.aRuntimeInstance.IsSleeping()) {
  135.             this.aRuntimeInstance.SetDebugContinueFlag();
  136.          }
  137.  
  138.          this.WaitForModuleThread();
  139.          this.aRuntimeInstance.ClearBreakFlag();
  140.          this.NotifyObservers(new JScriptAction(5003, "Program killed."));
  141.          this.NotifyObservers(new JScriptAction(218, this, this.aRuntimeInstance));
  142.       }
  143.    }
  144.  
  145.    private final void Do_ResetProgram() {
  146.       this.Do_KillProgram();
  147.    }
  148.  
  149.    private final void Do_Halt() {
  150.       if (!this.aRuntimeInstance.IsSleeping()) {
  151.          this.NotifyObservers(new JScriptAction(5003, "breaking..."));
  152.          this.aRuntimeInstance.SetDebugFlag();
  153.          this.aRuntimeInstance.SetSinglePCodeStepFlag();
  154.       } else {
  155.          this.NotifyObservers(new JScriptAction(5003, "allready breaked..."));
  156.       }
  157.    }
  158.  
  159.    private final boolean CanProcessAction(Object var1) {
  160.       return var1 instanceof JScriptAction && ((JScriptAction)var1).GetID() >= 1000 && ((JScriptAction)var1).GetID() <= 1100;
  161.    }
  162.  
  163.    private final boolean ProcessAction(Object var1) {
  164.       if (var1 instanceof JScriptAction) {
  165.          switch (((JScriptAction)var1).GetID()) {
  166.             case 1000:
  167.                this.Do_Start();
  168.                break;
  169.             case 1001:
  170.                this.Do_Step();
  171.                break;
  172.             case 1002:
  173.                this.Do_PCodeStep();
  174.             case 1003:
  175.                break;
  176.             case 1004:
  177.                this.Do_ResetProgram();
  178.                break;
  179.             case 1005:
  180.                this.Do_Run();
  181.                break;
  182.             case 1006:
  183.                this.Do_Halt();
  184.                this.NotifyObservers(new JScriptAction(5003, "program breaked."));
  185.                break;
  186.             case 1007:
  187.                this.NotifyObservers(new JScriptAction(203, this, this.aRuntimeInstance));
  188.                this.NotifyObservers(new JScriptAction(5003, "program finished."));
  189.                this.aModuleThread = null;
  190.                break;
  191.             case 1008:
  192.                this.NotifyObservers(new JScriptAction(202, this, this.aRuntimeInstance));
  193.                this.NotifyObservers(new JScriptAction(5003, "program started..."));
  194.                break;
  195.             case 1009:
  196.             default:
  197.                return false;
  198.             case 1010:
  199.                this.Do_KillProgram();
  200.                ((SJMTObject)this).StopMessageLoop();
  201.                break;
  202.             case 1011:
  203.                this.Do_StepOver();
  204.                break;
  205.             case 1012:
  206.                this.Do_StepOut();
  207.                break;
  208.             case 1013:
  209.                this.NotifyObservers(new JScriptAction(218, this, this.aRuntimeInstance));
  210.                this.NotifyObservers(new JScriptAction(5003, "thread finished."));
  211.                break;
  212.             case 1014:
  213.                this.NotifyObservers(new JScriptAction(217, this, this.aRuntimeInstance));
  214.                this.NotifyObservers(new JScriptAction(5003, "thread started..."));
  215.                break;
  216.             case 1015:
  217.                this.Do_PCodeStepOver();
  218.                break;
  219.             case 1016:
  220.                this.UpdateBrowserSync();
  221.          }
  222.  
  223.          return true;
  224.       } else {
  225.          return false;
  226.       }
  227.    }
  228.  
  229.    private final void StartModuleDebugThread() {
  230.       if (this.aModuleThread == null) {
  231.          JScriptModule var1 = this.aJScriptManager.GetActModule();
  232.          this.aRuntimeInstance.SetModule(var1);
  233.          this.aRuntimeInstance.SetDebugFlag();
  234.          this.aModuleThread = new Thread(this.aRuntimeInstance, new String("RT-Instance (used by: " + this.aIDString + ")"));
  235.          this.aModuleThread.start();
  236.       }
  237.  
  238.    }
  239.  
  240.    private final void WaitForModuleThread() {
  241.       this.aRuntimeInstance.WaitForThreadEnd();
  242.       this.aModuleThread = null;
  243.    }
  244.  
  245.    private final void NotifyObservers(JScriptAction var1) {
  246.       this.aJScriptManager.HandleMessage(var1);
  247.    }
  248. }
  249.