home *** CD-ROM | disk | FTP | other *** search
- package sun.applet;
-
- import java.io.BufferedInputStream;
- import java.io.File;
- import java.io.FilePermission;
- import java.io.IOException;
- import java.io.InputStream;
- import java.net.HttpURLConnection;
- import java.net.MalformedURLException;
- import java.net.SocketPermission;
- import java.net.URL;
- import java.net.URLClassLoader;
- import java.net.URLConnection;
- import java.security.AccessControlContext;
- import java.security.AccessController;
- import java.security.CodeSource;
- import java.security.Permission;
- import java.security.PermissionCollection;
- import java.security.PrivilegedActionException;
- import java.security.cert.Certificate;
- import java.util.Enumeration;
- import java.util.HashMap;
- import sun.awt.AppContext;
- import sun.net.www.ParseUtil;
-
- public class AppletClassLoader extends URLClassLoader {
- private URL base;
- private CodeSource codesource;
- private AccessControlContext acc;
- private boolean exceptionStatus = false;
- private final Object threadGroupSynchronizer = new Object();
- private final Object grabReleaseSynchronizer = new Object();
- private boolean codebaseLookup = true;
- private Object syncResourceAsStream = new Object();
- private Object syncResourceAsStreamFromJar = new Object();
- private boolean resourceAsStreamInCall = false;
- private boolean resourceAsStreamFromJarInCall = false;
- private AppletThreadGroup threadGroup;
- private AppContext appContext;
- int usageCount = 0;
- private HashMap jdk11AppletInfo = new HashMap();
- private HashMap jdk12AppletInfo = new HashMap();
- // $FF: renamed from: mh sun.applet.AppletMessageHandler
- private static AppletMessageHandler field_0 = new AppletMessageHandler("appletclassloader");
-
- protected AppletClassLoader(URL var1) {
- super(new URL[0]);
- this.base = var1;
- this.codesource = new CodeSource(var1, (Certificate[])null);
- this.acc = AccessController.getContext();
- }
-
- void setCodebaseLookup(boolean var1) {
- this.codebaseLookup = var1;
- }
-
- URL getBaseURL() {
- return this.base;
- }
-
- public URL[] getURLs() {
- URL[] var1 = super.getURLs();
- URL[] var2 = new URL[var1.length + 1];
- System.arraycopy(var1, 0, var2, 0, var1.length);
- var2[var2.length - 1] = this.base;
- return var2;
- }
-
- protected void addJar(String var1) throws IOException {
- URL var2;
- try {
- var2 = new URL(this.base, var1);
- } catch (MalformedURLException var4) {
- throw new IllegalArgumentException("name");
- }
-
- this.addURL(var2);
- }
-
- public synchronized Class loadClass(String var1, boolean var2) throws ClassNotFoundException {
- int var3 = var1.lastIndexOf(46);
- if (var3 != -1) {
- SecurityManager var4 = System.getSecurityManager();
- if (var4 != null) {
- var4.checkPackageAccess(var1.substring(0, var3));
- }
- }
-
- try {
- return super.loadClass(var1, var2);
- } catch (ClassNotFoundException var5) {
- throw var5;
- } catch (RuntimeException var6) {
- throw var6;
- } catch (Error var7) {
- throw var7;
- }
- }
-
- protected Class findClass(String var1) throws ClassNotFoundException {
- int var2 = var1.indexOf(";");
- String var3 = "";
- if (var2 != -1) {
- var3 = var1.substring(var2, var1.length());
- var1 = var1.substring(0, var2);
- }
-
- try {
- return super.findClass(var1);
- } catch (ClassNotFoundException var8) {
- if (!this.codebaseLookup) {
- throw new ClassNotFoundException(var1);
- } else {
- String var4 = ParseUtil.encodePath(var1.replace('.', '/'), false);
- String var5 = var4 + ".class" + var3;
-
- try {
- byte[] var6 = (byte[])AccessController.doPrivileged(new 1(this, var5), this.acc);
- if (var6 != null) {
- return this.defineClass(var1, var6, 0, var6.length, this.codesource);
- } else {
- throw new ClassNotFoundException(var1);
- }
- } catch (PrivilegedActionException var7) {
- throw new ClassNotFoundException(var1, var7.getException());
- }
- }
- }
- }
-
- protected PermissionCollection getPermissions(CodeSource var1) {
- PermissionCollection var2 = super.getPermissions(var1);
- URL var3 = var1.getLocation();
- String var4 = null;
-
- Permission var5;
- try {
- var5 = var3.openConnection().getPermission();
- } catch (IOException var9) {
- var5 = null;
- }
-
- if (var5 instanceof FilePermission) {
- var4 = var5.getName();
- } else if (var5 == null && var3.getProtocol().equals("file")) {
- var4 = var3.getFile().replace('/', File.separatorChar);
- var4 = ParseUtil.decode(var4);
- }
-
- if (var4 != null) {
- if (!var4.endsWith(File.separator)) {
- int var6 = var4.lastIndexOf(File.separatorChar);
- if (var6 != -1) {
- var4 = var4.substring(0, var6 + 1) + "-";
- var2.add(new FilePermission(var4, "read"));
- }
- }
-
- var2.add(new SocketPermission("localhost", "connect,accept"));
- AccessController.doPrivileged(new 2(this, var2));
-
- Permission var12;
- try {
- var12 = this.base.openConnection().getPermission();
- } catch (IOException var8) {
- var12 = null;
- }
-
- if (var12 instanceof FilePermission) {
- String var7 = var12.getName();
- if (var7.endsWith(File.separator)) {
- var7 = var7 + "-";
- }
-
- var2.add(new FilePermission(var7, "read"));
- } else if (var12 == null && this.base.getProtocol().equals("file")) {
- String var13 = this.base.getFile().replace('/', File.separatorChar);
- var13 = ParseUtil.decode(var13);
- if (var13.endsWith(File.separator)) {
- var13 = var13 + "-";
- }
-
- var2.add(new FilePermission(var13, "read"));
- }
- }
-
- return var2;
- }
-
- private static byte[] getBytes(URL var0) throws IOException {
- URLConnection var1 = var0.openConnection();
- if (var1 instanceof HttpURLConnection) {
- HttpURLConnection var2 = (HttpURLConnection)var1;
- int var3 = var2.getResponseCode();
- if (var3 >= 400) {
- throw new IOException("open HTTP connection failed.");
- }
- }
-
- int var10 = var1.getContentLength();
- BufferedInputStream var12 = new BufferedInputStream(var1.getInputStream());
-
- byte[] var4;
- try {
- int var5;
- if (var10 != -1) {
- for(var4 = new byte[var10]; var10 > 0; var10 -= var5) {
- var5 = ((InputStream)var12).read(var4, var4.length - var10, var10);
- if (var5 == -1) {
- throw new IOException("unexpected EOF");
- }
- }
- } else {
- var4 = new byte[8192];
- var5 = 0;
-
- while((var10 = ((InputStream)var12).read(var4, var5, var4.length - var5)) != -1) {
- var5 += var10;
- if (var5 >= var4.length) {
- byte[] var6 = new byte[var5 * 2];
- System.arraycopy(var4, 0, var6, 0, var5);
- var4 = var6;
- }
- }
-
- if (var5 != var4.length) {
- byte[] var14 = new byte[var5];
- System.arraycopy(var4, 0, var14, 0, var5);
- var4 = var14;
- }
- }
- } finally {
- ((InputStream)var12).close();
- }
-
- return var4;
- }
-
- public InputStream getResourceAsStream(String var1) {
- if (var1 == null) {
- throw new NullPointerException("name");
- } else {
- try {
- Object var2 = null;
- InputStream var7;
- synchronized(this.syncResourceAsStream) {
- this.resourceAsStreamInCall = true;
- var7 = super.getResourceAsStream(var1);
- this.resourceAsStreamInCall = false;
- }
-
- if (this.codebaseLookup && var7 == null) {
- URL var3 = new URL(this.base, ParseUtil.encodePath(var1, false));
- var7 = var3.openStream();
- }
-
- return var7;
- } catch (Exception var6) {
- return null;
- }
- }
- }
-
- public InputStream getResourceAsStreamFromJar(String var1) {
- if (var1 == null) {
- throw new NullPointerException("name");
- } else {
- try {
- Object var2 = null;
- InputStream var7;
- synchronized(this.syncResourceAsStreamFromJar) {
- this.resourceAsStreamFromJarInCall = true;
- var7 = super.getResourceAsStream(var1);
- this.resourceAsStreamFromJarInCall = false;
- }
-
- return var7;
- } catch (Exception var6) {
- return null;
- }
- }
- }
-
- public URL findResource(String var1) {
- URL var2 = super.findResource(var1);
- if (var1.startsWith("META-INF/")) {
- return var2;
- } else if (!this.codebaseLookup) {
- return var2;
- } else {
- if (var2 == null) {
- boolean var3 = false;
- synchronized(this.syncResourceAsStreamFromJar) {
- var3 = this.resourceAsStreamFromJarInCall;
- }
-
- if (var3) {
- return null;
- }
-
- boolean var4 = false;
- synchronized(this.syncResourceAsStream) {
- var4 = this.resourceAsStreamInCall;
- }
-
- if (!var4) {
- try {
- var2 = new URL(this.base, ParseUtil.encodePath(var1, false));
- if (!this.resourceExists(var2)) {
- var2 = null;
- }
- } catch (Exception var7) {
- var2 = null;
- }
- }
- }
-
- return var2;
- }
- }
-
- private boolean resourceExists(URL var1) {
- boolean var2 = true;
-
- try {
- URLConnection var3 = var1.openConnection();
- if (var3 instanceof HttpURLConnection) {
- HttpURLConnection var4 = (HttpURLConnection)var3;
- var4.setRequestMethod("HEAD");
- int var5 = var4.getResponseCode();
- if (var5 == 200) {
- return true;
- }
-
- if (var5 >= 400) {
- return false;
- }
- } else {
- InputStream var7 = var3.getInputStream();
- var7.close();
- }
- } catch (Exception var6) {
- var2 = false;
- }
-
- return var2;
- }
-
- public Enumeration findResources(String var1) throws IOException {
- Enumeration var2 = super.findResources(var1);
- if (var1.startsWith("META-INF/")) {
- return var2;
- } else if (!this.codebaseLookup) {
- return var2;
- } else {
- URL var3 = new URL(this.base, ParseUtil.encodePath(var1, false));
- if (!this.resourceExists(var3)) {
- var3 = null;
- }
-
- return new 3(this, var2, var3);
- }
- }
-
- Class loadCode(String var1) throws ClassNotFoundException {
- var1 = var1.replace('/', '.');
- var1 = var1.replace(File.separatorChar, '.');
- String var2 = null;
- int var3 = var1.indexOf(";");
- if (var3 != -1) {
- var2 = var1.substring(var3, var1.length());
- var1 = var1.substring(0, var3);
- }
-
- String var4 = var1;
- if (var1.endsWith(".class") || var1.endsWith(".java")) {
- var1 = var1.substring(0, var1.lastIndexOf(46));
- }
-
- try {
- if (var2 != null) {
- var1 = var1 + var2;
- }
-
- return this.loadClass(var1);
- } catch (ClassNotFoundException var6) {
- if (var2 != null) {
- var4 = var4 + var2;
- }
-
- return this.loadClass(var4);
- }
- }
-
- ThreadGroup getThreadGroup() {
- synchronized(this.threadGroupSynchronizer) {
- if (this.threadGroup == null || this.threadGroup.isDestroyed()) {
- AccessController.doPrivileged(new 4(this));
- }
-
- return this.threadGroup;
- }
- }
-
- AppContext getAppContext() {
- return this.appContext;
- }
-
- void grab() {
- synchronized(this.grabReleaseSynchronizer) {
- ++this.usageCount;
- }
-
- this.getThreadGroup();
- }
-
- protected void setExceptionStatus() {
- this.exceptionStatus = true;
- }
-
- public boolean getExceptionStatus() {
- return this.exceptionStatus;
- }
-
- protected void release() {
- AppContext var1 = null;
- synchronized(this.grabReleaseSynchronizer) {
- if (this.usageCount > 1) {
- --this.usageCount;
- } else {
- synchronized(this.threadGroupSynchronizer) {
- var1 = this.appContext;
- this.usageCount = 0;
- this.appContext = null;
- this.threadGroup = null;
- }
- }
- }
-
- if (var1 != null) {
- try {
- var1.dispose();
- } catch (IllegalThreadStateException var6) {
- }
- }
-
- }
-
- void setJDK11Target(Class var1, boolean var2) {
- this.jdk11AppletInfo.put(var1.toString(), var2);
- }
-
- void setJDK12Target(Class var1, boolean var2) {
- this.jdk12AppletInfo.put(var1.toString(), var2);
- }
-
- Boolean isJDK11Target(Class var1) {
- return (Boolean)this.jdk11AppletInfo.get(var1.toString());
- }
-
- Boolean isJDK12Target(Class var1) {
- return (Boolean)this.jdk12AppletInfo.get(var1.toString());
- }
-
- private static void printError(String var0, Throwable var1) {
- String var2 = null;
- if (var1 == null) {
- var2 = field_0.getMessage("filenotfound", var0);
- } else if (var1 instanceof IOException) {
- var2 = field_0.getMessage("fileioexception", var0);
- } else if (var1 instanceof ClassFormatError) {
- var2 = field_0.getMessage("fileformat", var0);
- } else if (var1 instanceof ThreadDeath) {
- var2 = field_0.getMessage("filedeath", var0);
- } else if (var1 instanceof Error) {
- var2 = field_0.getMessage("fileerror", var1.toString(), var0);
- }
-
- if (var2 != null) {
- System.err.println(var2);
- }
-
- }
-
- // $FF: synthetic method
- static URL access$000(AppletClassLoader var0) {
- return var0.base;
- }
-
- // $FF: synthetic method
- static byte[] access$100(URL var0) throws IOException {
- return getBytes(var0);
- }
-
- // $FF: synthetic method
- static AppletThreadGroup access$202(AppletClassLoader var0, AppletThreadGroup var1) {
- return var0.threadGroup = var1;
- }
-
- // $FF: synthetic method
- static AppletThreadGroup access$200(AppletClassLoader var0) {
- return var0.threadGroup;
- }
-
- // $FF: synthetic method
- static AppContext access$302(AppletClassLoader var0, AppContext var1) {
- return var0.appContext = var1;
- }
- }
-