home *** CD-ROM | disk | FTP | other *** search
- import java.util.Vector;
-
- class JScriptRunAsync implements Runnable {
- private static final int CALLBACK_ID_NOT_USED = -1;
- private Object aRunObj;
- private String aSourceStrg;
- private String aModuleName;
- private JavaScript aJSObj;
- private Object aModule;
- private JSbxObject aEvalObj;
- private JSbxProperty aMethodProp;
- private JSbxVector aParamVector;
- private int nCallbackID;
- private boolean bCallbackDone;
- private boolean bEvalCallback;
- private boolean bIsLiveConnectCall;
- private boolean bLiveConnectSyncTask;
- private Thread pRunThread;
- public JScriptRunParam aRP;
- private JScriptScheduler aMyTask;
- private static Vector aThreadList = new Vector(5);
- private boolean bLiveConnectReady;
- private boolean bLiveConnectDone;
-
- public String getSource() {
- return this.aSourceStrg;
- }
-
- public static boolean StopThreadWithCallbackID(int var0) {
- int var1 = aThreadList.size();
-
- for(int var2 = 0; var2 < var1; ++var2) {
- JScriptRunAsync var3 = (JScriptRunAsync)aThreadList.elementAt(var2);
- if (var3.GetCallbackID() == var0) {
- if (var3.pRunThread != null) {
- var3.pRunThread.stop();
- } else if (var3.aRP.aRTI != null) {
- var3.aRP.aRTI.StopExecution();
- } else {
- var3.aRP.bStoped = true;
- }
-
- aThreadList.removeElementAt(var2);
- aThreadList.trimToSize();
- return true;
- }
- }
-
- return false;
- }
-
- public void SetEvalCallbackFlag(boolean var1) {
- this.bEvalCallback = var1;
- }
-
- public boolean GetEvalCallbackFlag() {
- return this.bEvalCallback;
- }
-
- public JScriptRunAsync(JSbxObject var1, JavaScript var2) {
- this(var1, "", "", var2, (Object)null, (JSbxObject)null, -1, false, false);
- this.bLiveConnectSyncTask = true;
- }
-
- public JScriptRunAsync(JSbxObject var1, String var2, JavaScript var3, JSbxObject var4) {
- this(var1, var2, "", var3, (Object)null, var4, -1, false, false);
- }
-
- public JScriptRunAsync(JSbxObject var1, JSbxProperty var2, JSbxVector var3, JavaScript var4) {
- this(var1, "", "", var4, (Object)null, var1, -1, false, false);
- this.aMethodProp = var2;
- this.aParamVector = var3;
- }
-
- public JScriptRunAsync(JSbxObject var1, String var2, JavaScript var3, Object var4, int var5, boolean var6) {
- this(var1, var2, "", var3, var4, (JSbxObject)null, var5, false, var6);
- }
-
- public JScriptRunAsync(JavaScript var1, String var2, String var3, Object var4, int var5, boolean var6) {
- this(var1, var2, var3, var1, var4, (JSbxObject)null, var5, false, var6);
- }
-
- private JScriptRunAsync(Object var1, String var2, String var3, JavaScript var4, Object var5, JSbxObject var6, int var7, boolean var8, boolean var9) {
- this.aRunObj = var1;
- this.aSourceStrg = var2;
- this.aModuleName = var3;
- this.aJSObj = var4;
- this.aModule = var5;
- this.nCallbackID = var7;
- this.aEvalObj = var6;
- this.bIsLiveConnectCall = this.aMethodProp != null;
- this.aRP = new JScriptRunParam();
- if (var8) {
- this.aMyTask = null;
- this.pRunThread = new Thread(this, "(run async thread) " + this);
- this.pRunThread.start();
- } else {
- this.pRunThread = null;
- JScriptScheduler var10 = new JScriptScheduler(this, var9);
- this.aRP.aTask = var10;
- JScriptScheduler.SuspendExecutionAndStart(var10);
- }
-
- this.AddToTaskList();
- }
-
- public final void AddToTaskList() {
- aThreadList.addElement(this);
- }
-
- public final void RemoveFromTaskList() {
- aThreadList.removeElement(this);
- }
-
- public final JavaScript getDocManager() {
- return this.aJSObj;
- }
-
- public final int GetCallbackID() {
- return this.nCallbackID;
- }
-
- public final boolean isCallbackDone() {
- return this.bCallbackDone;
- }
-
- public final int GetAndResetCallbackID() {
- this.bCallbackDone = true;
- return this.nCallbackID;
- }
-
- public boolean IsLiveConnectCallReady() {
- return this.bLiveConnectReady;
- }
-
- public synchronized void WaitForLiveConnectReady() {
- if (!this.bLiveConnectReady) {
- try {
- while(!this.bLiveConnectReady) {
- this.wait();
- }
-
- this.bLiveConnectReady = false;
- } catch (InterruptedException var1) {
- }
- }
- }
-
- private synchronized void NotifyLiveConnectReady() {
- this.bLiveConnectReady = true;
- this.notifyAll();
- }
-
- public synchronized void WaitForLiveConnectDone() {
- if (!this.bLiveConnectDone) {
- try {
- while(!this.bLiveConnectDone) {
- this.wait();
- }
-
- this.bLiveConnectDone = false;
- } catch (InterruptedException var1) {
- }
- }
- }
-
- public synchronized void NotifyLiveConnectDone() {
- this.bLiveConnectDone = true;
- this.notifyAll();
- }
-
- public void run() {
- SJCallByReference_String var1 = this.aEvalObj == null ? new SJCallByReference_String() : null;
- SJCallByReference_int var2 = new SJCallByReference_int();
- this.aRP.aRetStrg = var1;
- this.aRP.aErrCode = var2;
- this.aRP.bDbgFlag = false;
- this.aRP.aJSObj = this.aJSObj;
- this.aRP.aMethodProp = this.aMethodProp;
- this.aRP.aParamVector = this.aParamVector;
- if (this.bLiveConnectSyncTask) {
- this.NotifyLiveConnectReady();
- this.WaitForLiveConnectDone();
- } else {
- if (this.aRunObj instanceof JSbxObject) {
- JSbxObject var5 = (JSbxObject)this.aRunObj;
- this.aRP.aThisObj = var5;
- if (this.aModule == null) {
- var5.RunCodeWithMyThis(this.aSourceStrg, this.aRP);
- } else {
- int var6 = var5.RunModuleWithMyThis(this.aRP);
- var2.SetValue(var6);
- }
- } else {
- if (!(this.aRunObj instanceof JavaScript)) {
- var2.SetValue(-9);
- return;
- }
-
- JavaScript var3 = (JavaScript)this.aRunObj;
- if (this.aModule == null && this.aModuleName != null) {
- int var4 = var3.CreateAndRunModule(this.aSourceStrg, this.aModuleName, this.aRP);
- var2.SetValue(var4);
- } else {
- var3.DoExecuteSync(this.aSourceStrg, this.aRP);
- }
- }
-
- if (!this.bCallbackDone) {
- this.bCallbackDone = true;
- if (this.nCallbackID != -1) {
- this.aJSObj.DoCallback(var2.GetValue(), var1.GetValue(), this.nCallbackID);
- }
-
- if (this.aEvalObj != null) {
- this.aEvalObj.NotifyCallback(this);
- }
- }
- }
-
- this.RemoveFromTaskList();
- }
- }
-