home *** CD-ROM | disk | FTP | other *** search
- package sun.applet;
-
- import java.applet.Applet;
- import java.applet.AppletContext;
- import java.applet.AppletStub;
- import java.awt.BorderLayout;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Panel;
- import java.awt.Window;
- import java.io.File;
- import java.io.FilePermission;
- import java.io.IOException;
- import java.io.InputStream;
- import java.io.ObjectInputStream;
- import java.net.SocketPermission;
- import java.net.URL;
- import java.security.AccessControlContext;
- import java.security.AccessController;
- import java.security.CodeSource;
- import java.security.Permission;
- import java.security.PermissionCollection;
- import java.security.Permissions;
- import java.security.ProtectionDomain;
- import java.security.cert.Certificate;
- import java.util.Hashtable;
- import java.util.StringTokenizer;
- import sun.misc.MessageUtils;
- import sun.misc.Queue;
-
- public abstract class AppletPanel extends Panel implements AppletStub, Runnable {
- Applet applet;
- protected boolean doInit = true;
- AppletClassLoader loader;
- public static final int APPLET_DISPOSE = 0;
- public static final int APPLET_LOAD = 1;
- public static final int APPLET_INIT = 2;
- public static final int APPLET_START = 3;
- public static final int APPLET_STOP = 4;
- public static final int APPLET_DESTROY = 5;
- public static final int APPLET_QUIT = 6;
- public static final int APPLET_ERROR = 7;
- public static final int APPLET_RESIZE = 51234;
- public static final int APPLET_LOADING = 51235;
- public static final int APPLET_LOADING_COMPLETED = 51236;
- protected int status;
- Thread handler;
- Dimension defaultAppletSize = new Dimension(10, 10);
- Dimension currentAppletSize = new Dimension(10, 10);
- // $FF: renamed from: mu sun.misc.MessageUtils
- MessageUtils field_0 = new MessageUtils();
- Thread loaderThread = null;
- boolean loadAbortRequest = false;
- private static int threadGroupNumber = 0;
- private AppletListener listeners;
- private Queue queue = null;
- private static Hashtable classloaders = new Hashtable();
- private static AppletMessageHandler amh = new AppletMessageHandler("appletpanel");
-
- protected abstract String getCode();
-
- protected abstract String getJarFiles();
-
- protected abstract String getSerializedObject();
-
- public abstract int getWidth();
-
- public abstract int getHeight();
-
- synchronized void createAppletThread() {
- String var1 = "applet-" + this.getCode();
- this.loader = this.getClassLoader(this.getCodeBase());
- this.loader.grab();
- ThreadGroup var2 = this.loader.getThreadGroup();
- this.handler = new Thread(var2, this, "thread " + var1);
- AccessController.doPrivileged(new 1(this));
- this.handler.start();
- }
-
- void joinAppletThread() throws InterruptedException {
- if (this.handler != null) {
- this.handler.join();
- this.handler = null;
- }
-
- }
-
- void release() {
- if (this.loader != null) {
- this.loader.release();
- this.loader = null;
- }
-
- }
-
- public void init() {
- try {
- this.defaultAppletSize.width = this.getWidth();
- this.currentAppletSize.width = this.defaultAppletSize.width;
- this.defaultAppletSize.height = this.getHeight();
- this.currentAppletSize.height = this.defaultAppletSize.height;
- } catch (NumberFormatException var2) {
- this.status = 7;
- this.showAppletStatus("badattribute.exception");
- this.showAppletLog("badattribute.exception");
- this.showAppletException(var2);
- }
-
- ((Container)this).setLayout(new BorderLayout());
- this.createAppletThread();
- }
-
- public Dimension minimumSize() {
- return new Dimension(this.defaultAppletSize.width, this.defaultAppletSize.height);
- }
-
- public Dimension preferredSize() {
- return new Dimension(this.currentAppletSize.width, this.currentAppletSize.height);
- }
-
- public synchronized void addAppletListener(AppletListener var1) {
- this.listeners = AppletEventMulticaster.add(this.listeners, var1);
- }
-
- public synchronized void removeAppletListener(AppletListener var1) {
- this.listeners = AppletEventMulticaster.remove(this.listeners, var1);
- }
-
- public void dispatchAppletEvent(int var1, Object var2) {
- if (this.listeners != null) {
- AppletEvent var3 = new AppletEvent(this, var1, var2);
- this.listeners.appletStateChanged(var3);
- }
-
- }
-
- public void sendEvent(int var1) {
- synchronized(this) {
- if (this.queue == null) {
- this.queue = new Queue();
- }
-
- Integer var3 = new Integer(var1);
- this.queue.enqueue(var3);
- this.notifyAll();
- }
-
- if (var1 == 6) {
- try {
- this.joinAppletThread();
- } catch (InterruptedException var5) {
- }
-
- if (this.loader == null) {
- this.loader = this.getClassLoader(this.getCodeBase());
- }
-
- this.release();
- }
-
- }
-
- synchronized AppletEvent getNextEvent() throws InterruptedException {
- while(this.queue == null || this.queue.isEmpty()) {
- this.wait();
- }
-
- Integer var1 = (Integer)this.queue.dequeue();
- return new AppletEvent(this, var1, (Object)null);
- }
-
- boolean emptyEventQueue() {
- return this.queue == null || this.queue.isEmpty();
- }
-
- public void run() {
- Thread var1 = Thread.currentThread();
- if (var1 == this.loaderThread) {
- this.runLoader();
- } else {
- for(boolean var2 = false; !var2 && !var1.isInterrupted(); this.clearLoadAbortRequest()) {
- AppletEvent var3;
- try {
- var3 = this.getNextEvent();
- } catch (InterruptedException var7) {
- this.showAppletStatus("bail");
- return;
- }
-
- try {
- switch (var3.getID()) {
- case 0:
- if (this.status != 1) {
- this.showAppletStatus("notdestroyed");
- } else {
- this.status = 0;
- ((Container)this).remove(this.applet);
- this.applet = null;
- this.showAppletStatus("disposed");
- var2 = true;
- }
- break;
- case 1:
- if (this.okToLoad() && this.loaderThread == null) {
- this.setLoaderThread(new Thread(this));
- this.loaderThread.start();
- this.loaderThread.join();
- this.setLoaderThread((Thread)null);
- }
- break;
- case 2:
- if (this.status != 1) {
- this.showAppletStatus("notloaded");
- } else {
- this.applet.resize(this.defaultAppletSize);
- if (this.doInit) {
- this.applet.init();
- }
-
- this.doInit = true;
- ((Container)this).validate();
- this.status = 2;
- this.showAppletStatus("inited");
- }
- break;
- case 3:
- if (this.status != 2) {
- this.showAppletStatus("notinited");
- } else {
- this.applet.resize(this.currentAppletSize);
- this.applet.start();
- ((Container)this).validate();
- this.applet.show();
- this.setDefaultFocus();
- this.status = 3;
- this.showAppletStatus("started");
- }
- break;
- case 4:
- if (this.status != 3) {
- this.showAppletStatus("notstarted");
- } else {
- this.status = 2;
- this.applet.hide();
- this.applet.stop();
- this.showAppletStatus("stopped");
- }
- break;
- case 5:
- if (this.status != 2) {
- this.showAppletStatus("notstopped");
- } else {
- this.status = 1;
- this.applet.destroy();
- this.showAppletStatus("destroyed");
- }
- break;
- case 6:
- return;
- }
- } catch (Exception var8) {
- if (((Throwable)var8).getMessage() != null) {
- this.showAppletStatus("exception2", var8.getClass().getName(), ((Throwable)var8).getMessage());
- } else {
- this.showAppletStatus("exception", var8.getClass().getName());
- }
-
- this.showAppletException(var8);
- } catch (ThreadDeath var9) {
- this.showAppletStatus("death");
- return;
- } catch (Error var10) {
- if (((Throwable)var10).getMessage() != null) {
- this.showAppletStatus("error2", var10.getClass().getName(), ((Throwable)var10).getMessage());
- } else {
- this.showAppletStatus("error", var10.getClass().getName());
- }
-
- this.showAppletException(var10);
- }
- }
-
- }
- }
-
- private void setDefaultFocus() {
- if (((Component)this).getParent() instanceof Window) {
- Window var1 = (Window)((Component)this).getParent();
- if (var1.getFocusOwner() != null) {
- this.doSetDefaultFocus();
- }
- }
-
- }
-
- private void doSetDefaultFocus() {
- if (this.applet != null) {
- if (!this.activateFocus(this.applet)) {
- Object var1;
- Component var2;
- for(var1 = this.applet; var1 instanceof Container && ((Container)var1).getComponentCount() > 0; var1 = var2) {
- var2 = ((Container)var1).getComponent(0);
- if (!var2.isVisible() || !var2.isEnabled()) {
- break;
- }
- }
-
- ((Component)var1).requestFocus();
- }
- }
- }
-
- private boolean activateFocus(Container var1) {
- int var2 = var1.getComponentCount();
-
- for(int var3 = 0; var3 < var2; ++var3) {
- Component var4 = var1.getComponent(var3);
- if (var4.isVisible() && var4.isEnabled() && var4.isFocusTraversable()) {
- var4.requestFocus();
- return true;
- }
-
- if (var4 instanceof Container && var4.isVisible() && var4.isEnabled() && this.activateFocus((Container)var4)) {
- return true;
- }
- }
-
- return false;
- }
-
- private void runLoader() {
- if (this.status != 0) {
- this.showAppletStatus("notdisposed");
- } else {
- this.dispatchAppletEvent(51235, (Object)null);
- this.status = 1;
- this.loader = this.getClassLoader(this.getCodeBase());
- String var1 = this.getCode();
-
- label118: {
- try {
- this.loadJarFiles(this.loader);
- this.applet = this.createApplet(this.loader);
- break label118;
- } catch (ClassNotFoundException var17) {
- this.status = 7;
- this.showAppletStatus("notfound", var1);
- this.showAppletLog("notfound", var1);
- this.showAppletException(var17);
- } catch (InstantiationException var18) {
- this.status = 7;
- this.showAppletStatus("nocreate", var1);
- this.showAppletLog("nocreate", var1);
- this.showAppletException(var18);
- return;
- } catch (IllegalAccessException var19) {
- this.status = 7;
- this.showAppletStatus("noconstruct", var1);
- this.showAppletLog("noconstruct", var1);
- this.showAppletException(var19);
- return;
- } catch (Exception var20) {
- this.status = 7;
- this.showAppletStatus("exception", ((Throwable)var20).getMessage());
- this.showAppletException(var20);
- return;
- } catch (ThreadDeath var21) {
- this.status = 7;
- this.showAppletStatus("death");
- return;
- } catch (Error var22) {
- this.status = 7;
- this.showAppletStatus("error", ((Throwable)var22).getMessage());
- this.showAppletException(var22);
- return;
- } finally {
- this.dispatchAppletEvent(51236, (Object)null);
- }
-
- return;
- }
-
- this.applet.setStub(this);
- this.applet.hide();
- ((Container)this).add("Center", this.applet);
- this.showAppletStatus("loaded");
- ((Container)this).validate();
- }
- }
-
- protected Applet createApplet(AppletClassLoader var1) throws ClassNotFoundException, IllegalAccessException, IOException, InstantiationException, InterruptedException {
- String var2 = this.getSerializedObject();
- String var3 = this.getCode();
- if (var3 != null && var2 != null) {
- System.err.println(amh.getMessage("runloader.err"));
- return null;
- } else {
- if (var3 == null && var2 == null) {
- String var4 = "nocode";
- this.status = 7;
- this.showAppletStatus(var4);
- this.showAppletLog(var4);
- ((Component)this).repaint();
- }
-
- if (var3 != null) {
- this.applet = (Applet)var1.loadCode(var3).newInstance();
- this.doInit = true;
- } else {
- InputStream var11 = (InputStream)AccessController.doPrivileged(new 2(this, var1, var2));
- AppletObjectInputStream var5 = new AppletObjectInputStream(var11, var1);
- Object var6 = ((ObjectInputStream)var5).readObject();
- this.applet = (Applet)var6;
- this.doInit = false;
- }
-
- if (Thread.interrupted()) {
- label58:
- try {
- this.status = 0;
- this.applet = null;
- this.showAppletStatus("death");
- } finally {
- break label58;
- }
-
- Thread.currentThread().interrupt();
- return null;
- } else {
- return this.applet;
- }
- }
- }
-
- protected void loadJarFiles(AppletClassLoader var1) throws IOException, InterruptedException {
- String var2 = this.getJarFiles();
- if (var2 != null) {
- StringTokenizer var3 = new StringTokenizer(var2, ",", false);
-
- while(var3.hasMoreTokens()) {
- String var4 = var3.nextToken().trim();
-
- try {
- var1.addJar(var4);
- } catch (IllegalArgumentException var6) {
- }
- }
- }
-
- }
-
- protected synchronized void stopLoading() {
- if (this.loaderThread != null) {
- this.loaderThread.interrupt();
- } else {
- this.setLoadAbortRequest();
- }
-
- }
-
- protected synchronized boolean okToLoad() {
- return !this.loadAbortRequest;
- }
-
- protected synchronized void clearLoadAbortRequest() {
- this.loadAbortRequest = false;
- }
-
- protected synchronized void setLoadAbortRequest() {
- this.loadAbortRequest = true;
- }
-
- private synchronized void setLoaderThread(Thread var1) {
- this.loaderThread = var1;
- }
-
- public boolean isActive() {
- return this.status == 3;
- }
-
- public void appletResize(int var1, int var2) {
- this.currentAppletSize.width = var1;
- this.currentAppletSize.height = var2;
- Dimension var3 = new Dimension(this.currentAppletSize.width, this.currentAppletSize.height);
- this.dispatchAppletEvent(51234, var3);
- }
-
- public void setBounds(int var1, int var2, int var3, int var4) {
- super.setBounds(var1, var2, var3, var4);
- this.currentAppletSize.width = var3;
- this.currentAppletSize.height = var4;
- }
-
- public Applet getApplet() {
- return this.applet;
- }
-
- protected void showAppletStatus(String var1) {
- this.getAppletContext().showStatus(amh.getMessage(var1));
- }
-
- protected void showAppletStatus(String var1, Object var2) {
- this.getAppletContext().showStatus(amh.getMessage(var1, var2));
- }
-
- protected void showAppletStatus(String var1, Object var2, Object var3) {
- this.getAppletContext().showStatus(amh.getMessage(var1, var2, var3));
- }
-
- protected void showAppletLog(String var1) {
- System.out.println(amh.getMessage(var1));
- }
-
- protected void showAppletLog(String var1, Object var2) {
- System.out.println(amh.getMessage(var1, var2));
- }
-
- protected void showAppletException(Throwable var1) {
- var1.printStackTrace();
- ((Component)this).repaint();
- }
-
- public static synchronized void flushClassLoader(URL var0) {
- classloaders.remove(var0);
- }
-
- public static synchronized void flushClassLoaders() {
- classloaders = new Hashtable();
- }
-
- protected AppletClassLoader createClassLoader(URL var1) {
- return new AppletClassLoader(var1);
- }
-
- synchronized AppletClassLoader getClassLoader(URL var1) {
- AppletClassLoader var2 = (AppletClassLoader)classloaders.get(var1);
- if (var2 == null) {
- AccessControlContext var3 = this.getAccessControlContext(var1);
- var2 = (AppletClassLoader)AccessController.doPrivileged(new 3(this, var1), var3);
- }
-
- return var2;
- }
-
- private AccessControlContext getAccessControlContext(URL var1) {
- Object var2 = (PermissionCollection)AccessController.doPrivileged(new 4(this));
- if (var2 == null) {
- var2 = new Permissions();
- }
-
- ((PermissionCollection)var2).add(new RuntimePermission("createClassLoader"));
-
- Permission var3;
- try {
- var3 = var1.openConnection().getPermission();
- } catch (IOException var6) {
- var3 = null;
- }
-
- if (var3 instanceof FilePermission) {
- String var4 = var3.getName();
- int var5 = var4.lastIndexOf(File.separatorChar);
- ((PermissionCollection)var2).add(var3);
- if (var5 != -1) {
- var4 = var4.substring(0, var5 + 1);
- if (var4.endsWith(File.separator)) {
- var4 = var4 + "-";
- }
-
- ((PermissionCollection)var2).add(new FilePermission(var4, "read"));
- }
- } else {
- String var8 = var1.getHost();
- if (var8 == null) {
- var8 = "localhost";
- }
-
- ((PermissionCollection)var2).add(new SocketPermission(var8, "connect, accept"));
- if (var3 != null) {
- ((PermissionCollection)var2).add(var3);
- }
- }
-
- ProtectionDomain var9 = new ProtectionDomain(new CodeSource(var1, (Certificate[])null), (PermissionCollection)var2);
- AccessControlContext var10 = new AccessControlContext(new ProtectionDomain[]{var9});
- return var10;
- }
-
- public Thread getAppletHandlerThread() {
- return this.handler;
- }
-
- public int getAppletWidth() {
- return this.currentAppletSize.width;
- }
-
- public int getAppletHeight() {
- return this.currentAppletSize.height;
- }
-
- public abstract AppletContext getAppletContext();
-
- public abstract String getParameter(String var1);
-
- public abstract URL getCodeBase();
-
- public abstract URL getDocumentBase();
-
- // $FF: synthetic method
- static Hashtable access$000() {
- return classloaders;
- }
- }
-