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

  1. import java.util.Vector;
  2.  
  3. class JScriptRunAsync implements Runnable {
  4.    private static final int CALLBACK_ID_NOT_USED = -1;
  5.    private Object aRunObj;
  6.    private String aSourceStrg;
  7.    private String aModuleName;
  8.    private JavaScript aJSObj;
  9.    private Object aModule;
  10.    private JSbxObject aEvalObj;
  11.    private JSbxProperty aMethodProp;
  12.    private JSbxVector aParamVector;
  13.    private int nCallbackID;
  14.    private boolean bCallbackDone;
  15.    private boolean bEvalCallback;
  16.    private boolean bIsLiveConnectCall;
  17.    private boolean bLiveConnectSyncTask;
  18.    private Thread pRunThread;
  19.    public JScriptRunParam aRP;
  20.    private JScriptScheduler aMyTask;
  21.    private static Vector aThreadList = new Vector(5);
  22.    private boolean bLiveConnectReady;
  23.    private boolean bLiveConnectDone;
  24.  
  25.    public String getSource() {
  26.       return this.aSourceStrg;
  27.    }
  28.  
  29.    public static boolean StopThreadWithCallbackID(int var0) {
  30.       int var1 = aThreadList.size();
  31.  
  32.       for(int var2 = 0; var2 < var1; ++var2) {
  33.          JScriptRunAsync var3 = (JScriptRunAsync)aThreadList.elementAt(var2);
  34.          if (var3.GetCallbackID() == var0) {
  35.             if (var3.pRunThread != null) {
  36.                var3.pRunThread.stop();
  37.             } else if (var3.aRP.aRTI != null) {
  38.                var3.aRP.aRTI.StopExecution();
  39.             } else {
  40.                var3.aRP.bStoped = true;
  41.             }
  42.  
  43.             aThreadList.removeElementAt(var2);
  44.             aThreadList.trimToSize();
  45.             return true;
  46.          }
  47.       }
  48.  
  49.       return false;
  50.    }
  51.  
  52.    public void SetEvalCallbackFlag(boolean var1) {
  53.       this.bEvalCallback = var1;
  54.    }
  55.  
  56.    public boolean GetEvalCallbackFlag() {
  57.       return this.bEvalCallback;
  58.    }
  59.  
  60.    public JScriptRunAsync(JSbxObject var1, JavaScript var2) {
  61.       this(var1, "", "", var2, (Object)null, (JSbxObject)null, -1, false, false);
  62.       this.bLiveConnectSyncTask = true;
  63.    }
  64.  
  65.    public JScriptRunAsync(JSbxObject var1, String var2, JavaScript var3, JSbxObject var4) {
  66.       this(var1, var2, "", var3, (Object)null, var4, -1, false, false);
  67.    }
  68.  
  69.    public JScriptRunAsync(JSbxObject var1, JSbxProperty var2, JSbxVector var3, JavaScript var4) {
  70.       this(var1, "", "", var4, (Object)null, var1, -1, false, false);
  71.       this.aMethodProp = var2;
  72.       this.aParamVector = var3;
  73.    }
  74.  
  75.    public JScriptRunAsync(JSbxObject var1, String var2, JavaScript var3, Object var4, int var5, boolean var6) {
  76.       this(var1, var2, "", var3, var4, (JSbxObject)null, var5, false, var6);
  77.    }
  78.  
  79.    public JScriptRunAsync(JavaScript var1, String var2, String var3, Object var4, int var5, boolean var6) {
  80.       this(var1, var2, var3, var1, var4, (JSbxObject)null, var5, false, var6);
  81.    }
  82.  
  83.    private JScriptRunAsync(Object var1, String var2, String var3, JavaScript var4, Object var5, JSbxObject var6, int var7, boolean var8, boolean var9) {
  84.       this.aRunObj = var1;
  85.       this.aSourceStrg = var2;
  86.       this.aModuleName = var3;
  87.       this.aJSObj = var4;
  88.       this.aModule = var5;
  89.       this.nCallbackID = var7;
  90.       this.aEvalObj = var6;
  91.       this.bIsLiveConnectCall = this.aMethodProp != null;
  92.       this.aRP = new JScriptRunParam();
  93.       if (var8) {
  94.          this.aMyTask = null;
  95.          this.pRunThread = new Thread(this, "(run async thread) " + this);
  96.          this.pRunThread.start();
  97.       } else {
  98.          this.pRunThread = null;
  99.          JScriptScheduler var10 = new JScriptScheduler(this, var9);
  100.          this.aRP.aTask = var10;
  101.          JScriptScheduler.SuspendExecutionAndStart(var10);
  102.       }
  103.  
  104.       this.AddToTaskList();
  105.    }
  106.  
  107.    public final void AddToTaskList() {
  108.       aThreadList.addElement(this);
  109.    }
  110.  
  111.    public final void RemoveFromTaskList() {
  112.       aThreadList.removeElement(this);
  113.    }
  114.  
  115.    public final JavaScript getDocManager() {
  116.       return this.aJSObj;
  117.    }
  118.  
  119.    public final int GetCallbackID() {
  120.       return this.nCallbackID;
  121.    }
  122.  
  123.    public final boolean isCallbackDone() {
  124.       return this.bCallbackDone;
  125.    }
  126.  
  127.    public final int GetAndResetCallbackID() {
  128.       this.bCallbackDone = true;
  129.       return this.nCallbackID;
  130.    }
  131.  
  132.    public boolean IsLiveConnectCallReady() {
  133.       return this.bLiveConnectReady;
  134.    }
  135.  
  136.    public synchronized void WaitForLiveConnectReady() {
  137.       if (!this.bLiveConnectReady) {
  138.          try {
  139.             while(!this.bLiveConnectReady) {
  140.                this.wait();
  141.             }
  142.  
  143.             this.bLiveConnectReady = false;
  144.          } catch (InterruptedException var1) {
  145.          }
  146.       }
  147.    }
  148.  
  149.    private synchronized void NotifyLiveConnectReady() {
  150.       this.bLiveConnectReady = true;
  151.       this.notifyAll();
  152.    }
  153.  
  154.    public synchronized void WaitForLiveConnectDone() {
  155.       if (!this.bLiveConnectDone) {
  156.          try {
  157.             while(!this.bLiveConnectDone) {
  158.                this.wait();
  159.             }
  160.  
  161.             this.bLiveConnectDone = false;
  162.          } catch (InterruptedException var1) {
  163.          }
  164.       }
  165.    }
  166.  
  167.    public synchronized void NotifyLiveConnectDone() {
  168.       this.bLiveConnectDone = true;
  169.       this.notifyAll();
  170.    }
  171.  
  172.    public void run() {
  173.       SJCallByReference_String var1 = this.aEvalObj == null ? new SJCallByReference_String() : null;
  174.       SJCallByReference_int var2 = new SJCallByReference_int();
  175.       this.aRP.aRetStrg = var1;
  176.       this.aRP.aErrCode = var2;
  177.       this.aRP.bDbgFlag = false;
  178.       this.aRP.aJSObj = this.aJSObj;
  179.       this.aRP.aMethodProp = this.aMethodProp;
  180.       this.aRP.aParamVector = this.aParamVector;
  181.       if (this.bLiveConnectSyncTask) {
  182.          this.NotifyLiveConnectReady();
  183.          this.WaitForLiveConnectDone();
  184.       } else {
  185.          if (this.aRunObj instanceof JSbxObject) {
  186.             JSbxObject var5 = (JSbxObject)this.aRunObj;
  187.             this.aRP.aThisObj = var5;
  188.             if (this.aModule == null) {
  189.                var5.RunCodeWithMyThis(this.aSourceStrg, this.aRP);
  190.             } else {
  191.                int var6 = var5.RunModuleWithMyThis(this.aRP);
  192.                var2.SetValue(var6);
  193.             }
  194.          } else {
  195.             if (!(this.aRunObj instanceof JavaScript)) {
  196.                var2.SetValue(-9);
  197.                return;
  198.             }
  199.  
  200.             JavaScript var3 = (JavaScript)this.aRunObj;
  201.             if (this.aModule == null && this.aModuleName != null) {
  202.                int var4 = var3.CreateAndRunModule(this.aSourceStrg, this.aModuleName, this.aRP);
  203.                var2.SetValue(var4);
  204.             } else {
  205.                var3.DoExecuteSync(this.aSourceStrg, this.aRP);
  206.             }
  207.          }
  208.  
  209.          if (!this.bCallbackDone) {
  210.             this.bCallbackDone = true;
  211.             if (this.nCallbackID != -1) {
  212.                this.aJSObj.DoCallback(var2.GetValue(), var1.GetValue(), this.nCallbackID);
  213.             }
  214.  
  215.             if (this.aEvalObj != null) {
  216.                this.aEvalObj.NotifyCallback(this);
  217.             }
  218.          }
  219.       }
  220.  
  221.       this.RemoveFromTaskList();
  222.    }
  223. }
  224.