home *** CD-ROM | disk | FTP | other *** search
- package netscape.netcast;
-
- import java.awt.Event;
- import java.io.File;
- import java.net.MalformedURLException;
- import java.net.URL;
- import java.util.StringTokenizer;
- import java.util.Vector;
- import marimba.castanet.client.CastanetChannel;
- import marimba.castanet.client.CastanetConstants;
- import marimba.castanet.client.CastanetEnvironment;
- import marimba.castanet.client.CastanetException;
- import marimba.castanet.client.CastanetFile;
- import marimba.castanet.client.CastanetObject;
- import marimba.castanet.client.CastanetObserver;
- import marimba.castanet.client.CastanetWorkspace;
- import marimba.channel.Application;
- import netscape.applet.CastanetChannelInfo;
- import netscape.security.ForbiddenTargetException;
- import netscape.security.PrivilegeManager;
- import netscape.security.Target;
-
- public final class ApplicationThread implements CastanetObserver, CastanetConstants, Runnable {
- CastanetEnvironment env;
- CastanetChannel channel;
- Application application;
- CastanetChannelInfo loader;
- ApplicationThreadGroup group;
- ApplicationContext context;
- CastanetChannelInfo info;
- Thread thread;
- Event queue;
- // $FF: renamed from: tm long
- long field_0 = System.currentTimeMillis();
-
- public ApplicationThread(CastanetChannel channel, int msg, Object arg) {
- this.env = ((CastanetObject)channel).getEnvironment();
- this.channel = channel;
- this.context = new ApplicationContext(channel);
- switch (msg) {
- case 404:
- case 405:
- this.sendEvent(channel, msg, arg);
- ((CastanetObject)channel).addObserver(this);
- String readPath = channel.getTransmitter().getDirectory().getPath();
- String writePath = channel.getDataDirectory().getPath();
- String workspacePath = ((CastanetObject)channel).getWorkspace().getDirectory().getAbsolutePath();
- URL[] urls = null;
- String[] zips = null;
- this.group = new ApplicationThreadGroup(((CastanetObject)channel).getName() + "-Group");
- this.group.setMaxPriority(8);
- Vector v = new Vector();
- String codebase = channel.getChannelProperty("codebase");
- if (codebase != null && codebase.indexOf(58) < 0) {
- v.addElement(codebase);
- }
-
- String classpath = channel.getChannelProperty("classpath");
- if (classpath != null) {
- StringTokenizer t = new StringTokenizer(classpath, ":");
-
- while(t.hasMoreElements()) {
- String cp = t.nextToken();
- if (cp.indexOf(58) < 0) {
- v.addElement(cp);
- }
- }
- }
-
- int pathlen = v.size();
- if (pathlen > 0) {
- urls = new URL[pathlen];
- zips = new String[pathlen];
-
- for(int i = 0; i < pathlen; ++i) {
- String path = ((String)v.elementAt(i)).trim();
- if (path.equals(".")) {
- urls[i] = channel.getBase();
- } else if (path.endsWith(".zip")) {
- CastanetFile file = channel.getFile(path);
- if (file == null) {
- ((CastanetObject)channel).notifyException(602, 860, file);
- } else if (file instanceof File) {
- zips[i] = ((File)file).getAbsolutePath();
- } else {
- ((CastanetObject)channel).notifyException(607, 861, file);
- }
- } else {
- try {
- if (!path.endsWith("/")) {
- path = path + "/";
- }
-
- urls[i] = new URL(channel.getBase(), path);
- } catch (MalformedURLException var16) {
- ((CastanetObject)channel).notifyException(602, 860, path);
- }
- }
- }
- }
-
- PrivilegeManager privMgr = PrivilegeManager.getPrivilegeManager();
- if (privMgr != null) {
- Target target = Target.findTarget("MarimbaInternalTarget");
- if (target != null) {
- privMgr.enablePrivilege(target);
- }
- }
-
- this.info = new CastanetChannelInfo(pathlen, readPath, writePath, workspacePath, urls, zips, this.group, channel.getBase());
- this.group.loader = this.info;
- this.loader = this.info;
- this.thread = new Thread(this.group, this, ((CastanetObject)channel).getName() + "-Thread");
- this.thread.start();
- return;
- default:
- ((CastanetObject)channel).notify(106, new CastanetException(605, 846, new Integer(msg)));
- }
- }
-
- synchronized void sendEvent(Object target, int msg, Object arg) {
- Event evt = new Event(target, msg, arg);
- if (this.queue == null) {
- this.queue = evt;
- this.notify();
- } else {
- Event q;
- for(q = this.queue; q.evt != null; q = q.evt) {
- }
-
- q.target = evt;
- }
- }
-
- synchronized Event getNextEvent() throws InterruptedException {
- while(this.queue == null) {
- this.wait();
- }
-
- Event evt = this.queue;
- this.queue = evt.evt;
- evt.evt = null;
- return evt;
- }
-
- void kill() {
- try {
- PrivilegeManager privMgr = PrivilegeManager.getPrivilegeManager();
- Target target = null;
- if (privMgr != null) {
- target = Target.findTarget("MarimbaInternalTarget");
- if (target != null) {
- privMgr.enablePrivilege(target);
- }
- }
-
- Thread thread = this.thread;
- if (thread != null) {
- try {
- thread.stop();
- } catch (IllegalThreadStateException var6) {
- }
- }
-
- CastanetChannelInfo loader = this.loader;
- if (loader != null) {
- loader.close();
- }
-
- CastanetChannel channel = this.channel;
- if (channel != null) {
- channel.stopped();
- }
- } catch (Throwable var7) {
- }
-
- this.application = null;
- this.loader = null;
- this.thread = null;
- this.queue = null;
- this.context = null;
- CastanetChannel ch = this.channel;
- ApplicationThreadGroup grp = this.group;
- if (ch != null && grp != null) {
- new ThreadGroupStopper(((CastanetObject)ch).getWorkspace(), grp);
- this.channel = null;
- this.group = null;
- }
-
- }
-
- public void notify(CastanetObject target, int msg, Object arg) {
- switch (msg) {
- case 407:
- case 3285287:
- case 3285288:
- case 3285289:
- case 3285291:
- case 3285292:
- this.sendEvent(target, msg, arg);
- return;
- case 408:
- this.kill();
- return;
- default:
- }
- }
-
- public void callChannelStarted(CastanetChannel channel) {
- PrivilegeManager privMgr = PrivilegeManager.getPrivilegeManager();
- Target target = null;
- if (privMgr != null) {
- target = Target.findTarget("MarimbaAppContextTarget");
- if (target != null) {
- privMgr.enablePrivilege(target);
- }
- }
-
- channel.started();
- }
-
- private void callChannelStopped(CastanetChannel ch) {
- PrivilegeManager privMgr = PrivilegeManager.getPrivilegeManager();
- Target target = null;
- if (privMgr != null) {
- target = Target.findTarget("MarimbaAppContextTarget");
- if (target != null) {
- privMgr.enablePrivilege(target);
-
- try {
- privMgr.checkPrivilegeEnabled(target);
- } catch (ForbiddenTargetException var4) {
- }
- }
- }
-
- ch.stopped();
- }
-
- private void callNotifiedUpdate(CastanetChannel channel) {
- PrivilegeManager privMgr = PrivilegeManager.getPrivilegeManager();
- Target target = null;
- if (privMgr != null) {
- target = Target.findTarget("MarimbaInternalTarget");
- if (target != null) {
- privMgr.enablePrivilege(target);
- }
- }
-
- channel.notifiedUpdate();
- }
-
- Class loadChannelMainClass(CastanetChannel channel) throws ClassNotFoundException {
- PrivilegeManager privMgr = PrivilegeManager.getPrivilegeManager();
- Target target = null;
- if (privMgr != null) {
- target = Target.findTarget("MarimbaAppContextTarget");
- if (target != null) {
- privMgr.enablePrivilege(target);
- }
- }
-
- String main = channel.getChannelProperty("main");
- if (main == null) {
- ((CastanetObject)channel).notifyException(602, 862, (Object)null);
- return null;
- } else {
- main = main.trim();
- Class c = this.loader.loadClass(main);
- return c;
- }
- }
-
- public void run() {
- try {
- try {
- for(Event evt = this.getNextEvent(); evt != null; evt = this.getNextEvent()) {
- switch (evt.id) {
- case 404:
- case 405:
- try {
- Class c = this.loadChannelMainClass(this.channel);
- if (c == null) {
- return;
- }
-
- this.application = (Application)c.newInstance();
- } catch (NoSuchMethodError e) {
- ((Throwable)e).printStackTrace();
- this.channel.notifyException(602, 863, e);
- return;
- } catch (NoClassDefFoundError e) {
- ((Throwable)e).printStackTrace();
- this.channel.notifyException(602, 864, e);
- return;
- } catch (ClassNotFoundException e) {
- ((Throwable)e).printStackTrace();
- this.channel.notifyException(602, 864, e);
- return;
- } catch (InstantiationException e) {
- ((Throwable)e).printStackTrace();
- this.channel.notifyException(602, 865, e);
- return;
- } catch (IllegalAccessException e) {
- ((Throwable)e).printStackTrace();
- this.channel.notifyException(602, 866, e);
- return;
- } catch (ClassCastException e) {
- ((Throwable)e).printStackTrace();
- this.channel.notifyException(602, 867, e);
- return;
- } catch (ThreadDeath e) {
- throw e;
- } catch (Throwable e) {
- e.printStackTrace();
- this.channel.notifyException(602, 845, e);
- return;
- }
-
- try {
- this.application.setContext(this.context);
- } catch (ThreadDeath e) {
- throw e;
- } catch (Throwable e) {
- e.printStackTrace();
- this.channel.notifyException(602, 868, e);
- return;
- }
-
- switch (evt.id) {
- case 404:
- try {
- evt.target = this.application;
- evt.id = 3285290;
- if (!this.application.handleEvent(evt)) {
- return;
- }
- } catch (ThreadDeath e) {
- throw e;
- } catch (Throwable e) {
- e.printStackTrace();
- this.channel.notifyException(602, 869, e);
- return;
- }
- case 405:
- try {
- this.application.start();
- } catch (ThreadDeath e) {
- throw e;
- } catch (Throwable e) {
- e.printStackTrace();
- this.channel.notifyException(602, 870, e);
- return;
- }
-
- this.callChannelStarted(this.channel);
- default:
- continue;
- }
- case 407:
- if (this.application != null) {
- try {
- this.application.stop();
- } catch (ThreadDeath e) {
- throw e;
- } catch (Throwable e) {
- e.printStackTrace();
- this.channel.notifyException(602, 872, e);
- }
- }
-
- return;
- case 3285287:
- if (this.application != null) {
- try {
- evt.target = this.application;
- this.application.handleEvent(evt);
- this.callNotifiedUpdate(this.channel);
- } catch (ThreadDeath e) {
- throw e;
- } catch (Throwable e) {
- e.printStackTrace();
- this.channel.notifyException(602, 871, e);
- }
- }
- break;
- case 3285289:
- this.context.param = null;
- case 3285288:
- case 3285291:
- case 3285292:
- if (this.application != null) {
- try {
- evt.target = this.application;
- this.application.handleEvent(evt);
- } catch (ThreadDeath e) {
- throw e;
- } catch (Throwable e) {
- e.printStackTrace();
- this.channel.notifyException(602, 871, e);
- }
- }
- }
- }
-
- return;
- } catch (InterruptedException e) {
- ((Throwable)e).printStackTrace();
- } catch (Throwable e) {
- e.printStackTrace();
- }
-
- } finally {
- CastanetChannel e = this.channel;
- if (e != null) {
- this.env.flush(e.getBase());
- this.callChannelStopped(e);
- ((CastanetObject)e).removeObserver(this);
- }
-
- CastanetChannelInfo ldr = this.loader;
- if (ldr != null) {
- ldr.close();
- }
-
- ApplicationThreadGroup grp = this.group;
- CastanetWorkspace ws = this.channel.getWorkspace();
- this.application = null;
- this.loader = null;
- this.channel = null;
- this.thread = null;
- this.group = null;
- this.queue = null;
- this.context = null;
- if (grp != null) {
- new ThreadGroupStopper(ws, grp);
- }
-
- }
- }
- }
-