home *** CD-ROM | disk | FTP | other *** search
/ S283 Planetary Science &n…he Search for Life DVD 2 / DVD-ROM.iso / install / jre1_3 / lib / rt.jar / sun / applet / AppletClassLoader.class (.txt) < prev    next >
Encoding:
Java Class File  |  1979-12-31  |  7.0 KB  |  326 lines

  1. package sun.applet;
  2.  
  3. import java.io.File;
  4. import java.io.FilePermission;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.net.HttpURLConnection;
  8. import java.net.MalformedURLException;
  9. import java.net.SocketPermission;
  10. import java.net.URL;
  11. import java.net.URLClassLoader;
  12. import java.net.URLConnection;
  13. import java.security.AccessControlContext;
  14. import java.security.AccessController;
  15. import java.security.CodeSource;
  16. import java.security.PermissionCollection;
  17. import java.security.PrivilegedActionException;
  18. import java.security.SecureClassLoader;
  19. import java.security.cert.Certificate;
  20. import java.util.Enumeration;
  21. import sun.awt.AppContext;
  22.  
  23. public class AppletClassLoader extends URLClassLoader {
  24.    private URL base;
  25.    private CodeSource codesource;
  26.    private AccessControlContext acc;
  27.    private AppletThreadGroup threadGroup;
  28.    private AppContext appContext;
  29.    int usageCount = 0;
  30.    // $FF: renamed from: mh sun.applet.AppletMessageHandler
  31.    private static AppletMessageHandler field_0 = new AppletMessageHandler("appletclassloader");
  32.  
  33.    protected AppletClassLoader(URL var1) {
  34.       super(new URL[0]);
  35.       this.base = var1;
  36.       this.codesource = new CodeSource(var1, (Certificate[])null);
  37.       this.acc = AccessController.getContext();
  38.    }
  39.  
  40.    URL getBaseURL() {
  41.       return this.base;
  42.    }
  43.  
  44.    public URL[] getURLs() {
  45.       URL[] var1 = super.getURLs();
  46.       URL[] var2 = new URL[var1.length + 1];
  47.       System.arraycopy(var1, 0, var2, 0, var1.length);
  48.       var2[var2.length - 1] = this.base;
  49.       return var2;
  50.    }
  51.  
  52.    void addJar(String var1) {
  53.       URL var2;
  54.       try {
  55.          var2 = new URL(this.base, var1);
  56.       } catch (MalformedURLException var4) {
  57.          throw new IllegalArgumentException("name");
  58.       }
  59.  
  60.       ((URLClassLoader)this).addURL(var2);
  61.    }
  62.  
  63.    public synchronized Class loadClass(String var1, boolean var2) throws ClassNotFoundException {
  64.       int var3 = var1.lastIndexOf(46);
  65.       if (var3 != -1) {
  66.          SecurityManager var4 = System.getSecurityManager();
  67.          if (var4 != null) {
  68.             var4.checkPackageAccess(var1.substring(0, var3));
  69.          }
  70.       }
  71.  
  72.       try {
  73.          return super.loadClass(var1, var2);
  74.       } catch (ClassNotFoundException var7) {
  75.          throw var7;
  76.       } catch (RuntimeException var8) {
  77.          throw var8;
  78.       } catch (Error var9) {
  79.          throw var9;
  80.       }
  81.    }
  82.  
  83.    protected Class findClass(String var1) throws ClassNotFoundException {
  84.       try {
  85.          return super.findClass(var1);
  86.       } catch (ClassNotFoundException var5) {
  87.          String var2 = var1.replace('.', '/').concat(".class");
  88.  
  89.          try {
  90.             byte[] var3 = (byte[])AccessController.doPrivileged(new 1(this, var2), this.acc);
  91.             if (var3 != null) {
  92.                return ((SecureClassLoader)this).defineClass(var1, var3, 0, var3.length, this.codesource);
  93.             } else {
  94.                throw new ClassNotFoundException(var1);
  95.             }
  96.          } catch (PrivilegedActionException var4) {
  97.             throw new ClassNotFoundException(var1, var4.getException());
  98.          }
  99.       }
  100.    }
  101.  
  102.    protected PermissionCollection getPermissions(CodeSource var1) {
  103.       PermissionCollection var2 = super.getPermissions(var1);
  104.       URL var3 = var1.getLocation();
  105.       if (var3.getProtocol().equals("file")) {
  106.          String var4 = var3.getFile().replace('/', File.separatorChar);
  107.          if (!var4.endsWith(File.separator)) {
  108.             int var5 = var4.lastIndexOf(File.separatorChar);
  109.             if (var5 != -1) {
  110.                var4 = var4.substring(0, var5 + 1) + "-";
  111.                var2.add(new FilePermission(var4, "read"));
  112.             }
  113.          }
  114.  
  115.          var2.add(new SocketPermission("localhost", "connect,accept"));
  116.          AccessController.doPrivileged(new 2(this, var2));
  117.          if (this.base.getProtocol().equals("file")) {
  118.             String var7 = this.base.getFile().replace('/', File.separatorChar);
  119.             if (var7.endsWith(File.separator)) {
  120.                var7 = var7 + "-";
  121.             }
  122.  
  123.             var2.add(new FilePermission(var7, "read"));
  124.          }
  125.       }
  126.  
  127.       return var2;
  128.    }
  129.  
  130.    private static byte[] getBytes(URL var0) throws IOException {
  131.       URLConnection var1 = var0.openConnection();
  132.       if (var1 instanceof HttpURLConnection) {
  133.          HttpURLConnection var2 = (HttpURLConnection)var1;
  134.          int var3 = var2.getResponseCode();
  135.          if (var3 >= 400) {
  136.             throw new IOException("open HTTP connection failed.");
  137.          }
  138.       }
  139.  
  140.       int var11 = var1.getContentLength();
  141.       InputStream var13 = var1.getInputStream();
  142.  
  143.       byte[] var4;
  144.       try {
  145.          int var5;
  146.          if (var11 != -1) {
  147.             for(var4 = new byte[var11]; var11 > 0; var11 -= var5) {
  148.                var5 = var13.read(var4, var4.length - var11, var11);
  149.                if (var5 == -1) {
  150.                   throw new IOException("unexpected EOF");
  151.                }
  152.             }
  153.          } else {
  154.             var4 = new byte[1024];
  155.             var5 = 0;
  156.  
  157.             while((var11 = var13.read(var4, var5, var4.length - var5)) != -1) {
  158.                var5 += var11;
  159.                if (var5 >= var4.length) {
  160.                   byte[] var6 = new byte[var5 * 2];
  161.                   System.arraycopy(var4, 0, var6, 0, var5);
  162.                   var4 = var6;
  163.                }
  164.             }
  165.  
  166.             if (var5 != var4.length) {
  167.                byte[] var15 = new byte[var5];
  168.                System.arraycopy(var4, 0, var15, 0, var5);
  169.                var4 = var15;
  170.             }
  171.          }
  172.       } finally {
  173.          var13.close();
  174.       }
  175.  
  176.       return var4;
  177.    }
  178.  
  179.    public URL findResource(String var1) {
  180.       URL var2 = super.findResource(var1);
  181.       if (var2 == null) {
  182.          try {
  183.             var2 = new URL(this.base, var1);
  184.             if (!this.resourceExists(var2)) {
  185.                var2 = null;
  186.             }
  187.          } catch (Exception var4) {
  188.             var2 = null;
  189.          }
  190.       }
  191.  
  192.       return var2;
  193.    }
  194.  
  195.    private boolean resourceExists(URL var1) {
  196.       boolean var2 = true;
  197.  
  198.       try {
  199.          URLConnection var3 = var1.openConnection();
  200.          if (var3 instanceof HttpURLConnection) {
  201.             HttpURLConnection var4 = (HttpURLConnection)var3;
  202.             int var5 = var4.getResponseCode();
  203.             if (var5 == 200) {
  204.                return true;
  205.             }
  206.  
  207.             if (var5 >= 400) {
  208.                return false;
  209.             }
  210.          } else {
  211.             InputStream var7 = var1.openStream();
  212.             var7.close();
  213.          }
  214.       } catch (Exception var6) {
  215.          var2 = false;
  216.       }
  217.  
  218.       return var2;
  219.    }
  220.  
  221.    public Enumeration findResources(String var1) throws IOException {
  222.       URL var2 = new URL(this.base, var1);
  223.       if (!this.resourceExists(var2)) {
  224.          var2 = null;
  225.       }
  226.  
  227.       Enumeration var3 = super.findResources(var1);
  228.       return new 3(this, var3, var2);
  229.    }
  230.  
  231.    Class loadCode(String var1) throws ClassNotFoundException {
  232.       var1 = var1.replace('/', '.');
  233.       var1 = var1.replace(File.separatorChar, '.');
  234.       String var2 = var1;
  235.       if (var1.endsWith(".class") || var1.endsWith(".java")) {
  236.          var1 = var1.substring(0, var1.lastIndexOf(46));
  237.       }
  238.  
  239.       try {
  240.          return ((ClassLoader)this).loadClass(var1);
  241.       } catch (ClassNotFoundException var4) {
  242.          return ((ClassLoader)this).loadClass(var2);
  243.       }
  244.    }
  245.  
  246.    synchronized ThreadGroup getThreadGroup() {
  247.       if (this.threadGroup == null || this.threadGroup.isDestroyed()) {
  248.          AccessController.doPrivileged(new 4(this));
  249.       }
  250.  
  251.       return this.threadGroup;
  252.    }
  253.  
  254.    AppContext getAppContext() {
  255.       return this.appContext;
  256.    }
  257.  
  258.    synchronized void grab() {
  259.       ++this.usageCount;
  260.       this.getThreadGroup();
  261.    }
  262.  
  263.    synchronized void release() {
  264.       if (this.usageCount > 1) {
  265.          --this.usageCount;
  266.       } else {
  267.          if (this.appContext != null) {
  268.             try {
  269.                this.appContext.dispose();
  270.             } catch (IllegalThreadStateException var2) {
  271.             }
  272.          }
  273.  
  274.          this.usageCount = 0;
  275.          this.appContext = null;
  276.          this.threadGroup = null;
  277.       }
  278.  
  279.    }
  280.  
  281.    private static void printError(String var0, Throwable var1) {
  282.       String var2 = null;
  283.       if (var1 == null) {
  284.          var2 = field_0.getMessage("filenotfound", var0);
  285.       } else if (var1 instanceof IOException) {
  286.          var2 = field_0.getMessage("fileioexception", var0);
  287.       } else if (var1 instanceof ClassFormatError) {
  288.          var2 = field_0.getMessage("fileformat", var0);
  289.       } else if (var1 instanceof ThreadDeath) {
  290.          var2 = field_0.getMessage("filedeath", var0);
  291.       } else if (var1 instanceof Error) {
  292.          var2 = field_0.getMessage("fileerror", var1.toString(), var0);
  293.       }
  294.  
  295.       if (var2 != null) {
  296.          System.err.println(var2);
  297.       }
  298.  
  299.    }
  300.  
  301.    // $FF: synthetic method
  302.    static URL access$000(AppletClassLoader var0) {
  303.       return var0.base;
  304.    }
  305.  
  306.    // $FF: synthetic method
  307.    static byte[] access$100(URL var0) throws IOException {
  308.       return getBytes(var0);
  309.    }
  310.  
  311.    // $FF: synthetic method
  312.    static AppletThreadGroup access$202(AppletClassLoader var0, AppletThreadGroup var1) {
  313.       return var0.threadGroup = var1;
  314.    }
  315.  
  316.    // $FF: synthetic method
  317.    static AppletThreadGroup access$200(AppletClassLoader var0) {
  318.       return var0.threadGroup;
  319.    }
  320.  
  321.    // $FF: synthetic method
  322.    static AppContext access$302(AppletClassLoader var0, AppContext var1) {
  323.       return var0.appContext = var1;
  324.    }
  325. }
  326.