home *** CD-ROM | disk | FTP | other *** search
/ Sky at Night 2007 June / SAN CD 6-2007 CD-ROM 25.iso / pc / Software / AstroGrav_Win / Java / jre1.6.0 / lib / rt.jar / sun / applet / AppletClassLoader.class (.txt) < prev    next >
Encoding:
Java Class File  |  2006-11-29  |  9.8 KB  |  510 lines

  1. package sun.applet;
  2.  
  3. import java.io.BufferedInputStream;
  4. import java.io.File;
  5. import java.io.FilePermission;
  6. import java.io.IOException;
  7. import java.io.InputStream;
  8. import java.net.HttpURLConnection;
  9. import java.net.MalformedURLException;
  10. import java.net.SocketPermission;
  11. import java.net.URL;
  12. import java.net.URLClassLoader;
  13. import java.net.URLConnection;
  14. import java.security.AccessControlContext;
  15. import java.security.AccessController;
  16. import java.security.CodeSource;
  17. import java.security.Permission;
  18. import java.security.PermissionCollection;
  19. import java.security.PrivilegedActionException;
  20. import java.security.cert.Certificate;
  21. import java.util.Enumeration;
  22. import java.util.HashMap;
  23. import sun.awt.AppContext;
  24. import sun.net.www.ParseUtil;
  25.  
  26. public class AppletClassLoader extends URLClassLoader {
  27.    private URL base;
  28.    private CodeSource codesource;
  29.    private AccessControlContext acc;
  30.    private boolean exceptionStatus = false;
  31.    private final Object threadGroupSynchronizer = new Object();
  32.    private final Object grabReleaseSynchronizer = new Object();
  33.    private boolean codebaseLookup = true;
  34.    private Object syncResourceAsStream = new Object();
  35.    private Object syncResourceAsStreamFromJar = new Object();
  36.    private boolean resourceAsStreamInCall = false;
  37.    private boolean resourceAsStreamFromJarInCall = false;
  38.    private AppletThreadGroup threadGroup;
  39.    private AppContext appContext;
  40.    int usageCount = 0;
  41.    private HashMap jdk11AppletInfo = new HashMap();
  42.    private HashMap jdk12AppletInfo = new HashMap();
  43.    // $FF: renamed from: mh sun.applet.AppletMessageHandler
  44.    private static AppletMessageHandler field_0 = new AppletMessageHandler("appletclassloader");
  45.  
  46.    protected AppletClassLoader(URL var1) {
  47.       super(new URL[0]);
  48.       this.base = var1;
  49.       this.codesource = new CodeSource(var1, (Certificate[])null);
  50.       this.acc = AccessController.getContext();
  51.    }
  52.  
  53.    void setCodebaseLookup(boolean var1) {
  54.       this.codebaseLookup = var1;
  55.    }
  56.  
  57.    URL getBaseURL() {
  58.       return this.base;
  59.    }
  60.  
  61.    public URL[] getURLs() {
  62.       URL[] var1 = super.getURLs();
  63.       URL[] var2 = new URL[var1.length + 1];
  64.       System.arraycopy(var1, 0, var2, 0, var1.length);
  65.       var2[var2.length - 1] = this.base;
  66.       return var2;
  67.    }
  68.  
  69.    protected void addJar(String var1) throws IOException {
  70.       URL var2;
  71.       try {
  72.          var2 = new URL(this.base, var1);
  73.       } catch (MalformedURLException var4) {
  74.          throw new IllegalArgumentException("name");
  75.       }
  76.  
  77.       this.addURL(var2);
  78.    }
  79.  
  80.    public synchronized Class loadClass(String var1, boolean var2) throws ClassNotFoundException {
  81.       int var3 = var1.lastIndexOf(46);
  82.       if (var3 != -1) {
  83.          SecurityManager var4 = System.getSecurityManager();
  84.          if (var4 != null) {
  85.             var4.checkPackageAccess(var1.substring(0, var3));
  86.          }
  87.       }
  88.  
  89.       try {
  90.          return super.loadClass(var1, var2);
  91.       } catch (ClassNotFoundException var5) {
  92.          throw var5;
  93.       } catch (RuntimeException var6) {
  94.          throw var6;
  95.       } catch (Error var7) {
  96.          throw var7;
  97.       }
  98.    }
  99.  
  100.    protected Class findClass(String var1) throws ClassNotFoundException {
  101.       int var2 = var1.indexOf(";");
  102.       String var3 = "";
  103.       if (var2 != -1) {
  104.          var3 = var1.substring(var2, var1.length());
  105.          var1 = var1.substring(0, var2);
  106.       }
  107.  
  108.       try {
  109.          return super.findClass(var1);
  110.       } catch (ClassNotFoundException var8) {
  111.          if (!this.codebaseLookup) {
  112.             throw new ClassNotFoundException(var1);
  113.          } else {
  114.             String var4 = ParseUtil.encodePath(var1.replace('.', '/'), false);
  115.             String var5 = var4 + ".class" + var3;
  116.  
  117.             try {
  118.                byte[] var6 = (byte[])AccessController.doPrivileged(new 1(this, var5), this.acc);
  119.                if (var6 != null) {
  120.                   return this.defineClass(var1, var6, 0, var6.length, this.codesource);
  121.                } else {
  122.                   throw new ClassNotFoundException(var1);
  123.                }
  124.             } catch (PrivilegedActionException var7) {
  125.                throw new ClassNotFoundException(var1, var7.getException());
  126.             }
  127.          }
  128.       }
  129.    }
  130.  
  131.    protected PermissionCollection getPermissions(CodeSource var1) {
  132.       PermissionCollection var2 = super.getPermissions(var1);
  133.       URL var3 = var1.getLocation();
  134.       String var4 = null;
  135.  
  136.       Permission var5;
  137.       try {
  138.          var5 = var3.openConnection().getPermission();
  139.       } catch (IOException var9) {
  140.          var5 = null;
  141.       }
  142.  
  143.       if (var5 instanceof FilePermission) {
  144.          var4 = var5.getName();
  145.       } else if (var5 == null && var3.getProtocol().equals("file")) {
  146.          var4 = var3.getFile().replace('/', File.separatorChar);
  147.          var4 = ParseUtil.decode(var4);
  148.       }
  149.  
  150.       if (var4 != null) {
  151.          if (!var4.endsWith(File.separator)) {
  152.             int var6 = var4.lastIndexOf(File.separatorChar);
  153.             if (var6 != -1) {
  154.                var4 = var4.substring(0, var6 + 1) + "-";
  155.                var2.add(new FilePermission(var4, "read"));
  156.             }
  157.          }
  158.  
  159.          var2.add(new SocketPermission("localhost", "connect,accept"));
  160.          AccessController.doPrivileged(new 2(this, var2));
  161.  
  162.          Permission var12;
  163.          try {
  164.             var12 = this.base.openConnection().getPermission();
  165.          } catch (IOException var8) {
  166.             var12 = null;
  167.          }
  168.  
  169.          if (var12 instanceof FilePermission) {
  170.             String var7 = var12.getName();
  171.             if (var7.endsWith(File.separator)) {
  172.                var7 = var7 + "-";
  173.             }
  174.  
  175.             var2.add(new FilePermission(var7, "read"));
  176.          } else if (var12 == null && this.base.getProtocol().equals("file")) {
  177.             String var13 = this.base.getFile().replace('/', File.separatorChar);
  178.             var13 = ParseUtil.decode(var13);
  179.             if (var13.endsWith(File.separator)) {
  180.                var13 = var13 + "-";
  181.             }
  182.  
  183.             var2.add(new FilePermission(var13, "read"));
  184.          }
  185.       }
  186.  
  187.       return var2;
  188.    }
  189.  
  190.    private static byte[] getBytes(URL var0) throws IOException {
  191.       URLConnection var1 = var0.openConnection();
  192.       if (var1 instanceof HttpURLConnection) {
  193.          HttpURLConnection var2 = (HttpURLConnection)var1;
  194.          int var3 = var2.getResponseCode();
  195.          if (var3 >= 400) {
  196.             throw new IOException("open HTTP connection failed.");
  197.          }
  198.       }
  199.  
  200.       int var10 = var1.getContentLength();
  201.       BufferedInputStream var12 = new BufferedInputStream(var1.getInputStream());
  202.  
  203.       byte[] var4;
  204.       try {
  205.          int var5;
  206.          if (var10 != -1) {
  207.             for(var4 = new byte[var10]; var10 > 0; var10 -= var5) {
  208.                var5 = ((InputStream)var12).read(var4, var4.length - var10, var10);
  209.                if (var5 == -1) {
  210.                   throw new IOException("unexpected EOF");
  211.                }
  212.             }
  213.          } else {
  214.             var4 = new byte[8192];
  215.             var5 = 0;
  216.  
  217.             while((var10 = ((InputStream)var12).read(var4, var5, var4.length - var5)) != -1) {
  218.                var5 += var10;
  219.                if (var5 >= var4.length) {
  220.                   byte[] var6 = new byte[var5 * 2];
  221.                   System.arraycopy(var4, 0, var6, 0, var5);
  222.                   var4 = var6;
  223.                }
  224.             }
  225.  
  226.             if (var5 != var4.length) {
  227.                byte[] var14 = new byte[var5];
  228.                System.arraycopy(var4, 0, var14, 0, var5);
  229.                var4 = var14;
  230.             }
  231.          }
  232.       } finally {
  233.          ((InputStream)var12).close();
  234.       }
  235.  
  236.       return var4;
  237.    }
  238.  
  239.    public InputStream getResourceAsStream(String var1) {
  240.       if (var1 == null) {
  241.          throw new NullPointerException("name");
  242.       } else {
  243.          try {
  244.             Object var2 = null;
  245.             InputStream var7;
  246.             synchronized(this.syncResourceAsStream) {
  247.                this.resourceAsStreamInCall = true;
  248.                var7 = super.getResourceAsStream(var1);
  249.                this.resourceAsStreamInCall = false;
  250.             }
  251.  
  252.             if (this.codebaseLookup && var7 == null) {
  253.                URL var3 = new URL(this.base, ParseUtil.encodePath(var1, false));
  254.                var7 = var3.openStream();
  255.             }
  256.  
  257.             return var7;
  258.          } catch (Exception var6) {
  259.             return null;
  260.          }
  261.       }
  262.    }
  263.  
  264.    public InputStream getResourceAsStreamFromJar(String var1) {
  265.       if (var1 == null) {
  266.          throw new NullPointerException("name");
  267.       } else {
  268.          try {
  269.             Object var2 = null;
  270.             InputStream var7;
  271.             synchronized(this.syncResourceAsStreamFromJar) {
  272.                this.resourceAsStreamFromJarInCall = true;
  273.                var7 = super.getResourceAsStream(var1);
  274.                this.resourceAsStreamFromJarInCall = false;
  275.             }
  276.  
  277.             return var7;
  278.          } catch (Exception var6) {
  279.             return null;
  280.          }
  281.       }
  282.    }
  283.  
  284.    public URL findResource(String var1) {
  285.       URL var2 = super.findResource(var1);
  286.       if (var1.startsWith("META-INF/")) {
  287.          return var2;
  288.       } else if (!this.codebaseLookup) {
  289.          return var2;
  290.       } else {
  291.          if (var2 == null) {
  292.             boolean var3 = false;
  293.             synchronized(this.syncResourceAsStreamFromJar) {
  294.                var3 = this.resourceAsStreamFromJarInCall;
  295.             }
  296.  
  297.             if (var3) {
  298.                return null;
  299.             }
  300.  
  301.             boolean var4 = false;
  302.             synchronized(this.syncResourceAsStream) {
  303.                var4 = this.resourceAsStreamInCall;
  304.             }
  305.  
  306.             if (!var4) {
  307.                try {
  308.                   var2 = new URL(this.base, ParseUtil.encodePath(var1, false));
  309.                   if (!this.resourceExists(var2)) {
  310.                      var2 = null;
  311.                   }
  312.                } catch (Exception var7) {
  313.                   var2 = null;
  314.                }
  315.             }
  316.          }
  317.  
  318.          return var2;
  319.       }
  320.    }
  321.  
  322.    private boolean resourceExists(URL var1) {
  323.       boolean var2 = true;
  324.  
  325.       try {
  326.          URLConnection var3 = var1.openConnection();
  327.          if (var3 instanceof HttpURLConnection) {
  328.             HttpURLConnection var4 = (HttpURLConnection)var3;
  329.             var4.setRequestMethod("HEAD");
  330.             int var5 = var4.getResponseCode();
  331.             if (var5 == 200) {
  332.                return true;
  333.             }
  334.  
  335.             if (var5 >= 400) {
  336.                return false;
  337.             }
  338.          } else {
  339.             InputStream var7 = var3.getInputStream();
  340.             var7.close();
  341.          }
  342.       } catch (Exception var6) {
  343.          var2 = false;
  344.       }
  345.  
  346.       return var2;
  347.    }
  348.  
  349.    public Enumeration findResources(String var1) throws IOException {
  350.       Enumeration var2 = super.findResources(var1);
  351.       if (var1.startsWith("META-INF/")) {
  352.          return var2;
  353.       } else if (!this.codebaseLookup) {
  354.          return var2;
  355.       } else {
  356.          URL var3 = new URL(this.base, ParseUtil.encodePath(var1, false));
  357.          if (!this.resourceExists(var3)) {
  358.             var3 = null;
  359.          }
  360.  
  361.          return new 3(this, var2, var3);
  362.       }
  363.    }
  364.  
  365.    Class loadCode(String var1) throws ClassNotFoundException {
  366.       var1 = var1.replace('/', '.');
  367.       var1 = var1.replace(File.separatorChar, '.');
  368.       String var2 = null;
  369.       int var3 = var1.indexOf(";");
  370.       if (var3 != -1) {
  371.          var2 = var1.substring(var3, var1.length());
  372.          var1 = var1.substring(0, var3);
  373.       }
  374.  
  375.       String var4 = var1;
  376.       if (var1.endsWith(".class") || var1.endsWith(".java")) {
  377.          var1 = var1.substring(0, var1.lastIndexOf(46));
  378.       }
  379.  
  380.       try {
  381.          if (var2 != null) {
  382.             var1 = var1 + var2;
  383.          }
  384.  
  385.          return this.loadClass(var1);
  386.       } catch (ClassNotFoundException var6) {
  387.          if (var2 != null) {
  388.             var4 = var4 + var2;
  389.          }
  390.  
  391.          return this.loadClass(var4);
  392.       }
  393.    }
  394.  
  395.    ThreadGroup getThreadGroup() {
  396.       synchronized(this.threadGroupSynchronizer) {
  397.          if (this.threadGroup == null || this.threadGroup.isDestroyed()) {
  398.             AccessController.doPrivileged(new 4(this));
  399.          }
  400.  
  401.          return this.threadGroup;
  402.       }
  403.    }
  404.  
  405.    AppContext getAppContext() {
  406.       return this.appContext;
  407.    }
  408.  
  409.    void grab() {
  410.       synchronized(this.grabReleaseSynchronizer) {
  411.          ++this.usageCount;
  412.       }
  413.  
  414.       this.getThreadGroup();
  415.    }
  416.  
  417.    protected void setExceptionStatus() {
  418.       this.exceptionStatus = true;
  419.    }
  420.  
  421.    public boolean getExceptionStatus() {
  422.       return this.exceptionStatus;
  423.    }
  424.  
  425.    protected void release() {
  426.       AppContext var1 = null;
  427.       synchronized(this.grabReleaseSynchronizer) {
  428.          if (this.usageCount > 1) {
  429.             --this.usageCount;
  430.          } else {
  431.             synchronized(this.threadGroupSynchronizer) {
  432.                var1 = this.appContext;
  433.                this.usageCount = 0;
  434.                this.appContext = null;
  435.                this.threadGroup = null;
  436.             }
  437.          }
  438.       }
  439.  
  440.       if (var1 != null) {
  441.          try {
  442.             var1.dispose();
  443.          } catch (IllegalThreadStateException var6) {
  444.          }
  445.       }
  446.  
  447.    }
  448.  
  449.    void setJDK11Target(Class var1, boolean var2) {
  450.       this.jdk11AppletInfo.put(var1.toString(), var2);
  451.    }
  452.  
  453.    void setJDK12Target(Class var1, boolean var2) {
  454.       this.jdk12AppletInfo.put(var1.toString(), var2);
  455.    }
  456.  
  457.    Boolean isJDK11Target(Class var1) {
  458.       return (Boolean)this.jdk11AppletInfo.get(var1.toString());
  459.    }
  460.  
  461.    Boolean isJDK12Target(Class var1) {
  462.       return (Boolean)this.jdk12AppletInfo.get(var1.toString());
  463.    }
  464.  
  465.    private static void printError(String var0, Throwable var1) {
  466.       String var2 = null;
  467.       if (var1 == null) {
  468.          var2 = field_0.getMessage("filenotfound", var0);
  469.       } else if (var1 instanceof IOException) {
  470.          var2 = field_0.getMessage("fileioexception", var0);
  471.       } else if (var1 instanceof ClassFormatError) {
  472.          var2 = field_0.getMessage("fileformat", var0);
  473.       } else if (var1 instanceof ThreadDeath) {
  474.          var2 = field_0.getMessage("filedeath", var0);
  475.       } else if (var1 instanceof Error) {
  476.          var2 = field_0.getMessage("fileerror", var1.toString(), var0);
  477.       }
  478.  
  479.       if (var2 != null) {
  480.          System.err.println(var2);
  481.       }
  482.  
  483.    }
  484.  
  485.    // $FF: synthetic method
  486.    static URL access$000(AppletClassLoader var0) {
  487.       return var0.base;
  488.    }
  489.  
  490.    // $FF: synthetic method
  491.    static byte[] access$100(URL var0) throws IOException {
  492.       return getBytes(var0);
  493.    }
  494.  
  495.    // $FF: synthetic method
  496.    static AppletThreadGroup access$202(AppletClassLoader var0, AppletThreadGroup var1) {
  497.       return var0.threadGroup = var1;
  498.    }
  499.  
  500.    // $FF: synthetic method
  501.    static AppletThreadGroup access$200(AppletClassLoader var0) {
  502.       return var0.threadGroup;
  503.    }
  504.  
  505.    // $FF: synthetic method
  506.    static AppContext access$302(AppletClassLoader var0, AppContext var1) {
  507.       return var0.appContext = var1;
  508.    }
  509. }
  510.