| Method from sun.applet.AppletClassLoader Detail: |
protected void addJar(String name) throws IOException {
URL url;
try {
url = new URL(base, name);
} catch (MalformedURLException e) {
throw new IllegalArgumentException("name");
}
addURL(url);
// DEBUG
//URL[] urls = getURLs();
//for (int i = 0; i < urls.length; i++) {
// System.out.println("url[" + i + "] = " + urls[i]);
//}
}
|
protected Class findClass(String name) throws ClassNotFoundException {
int index = name.indexOf(";");
String cookie = "";
if(index != -1) {
cookie = name.substring(index, name.length());
name = name.substring(0, index);
}
// check loaded JAR files
try {
return super.findClass(name);
} catch (ClassNotFoundException e) {
}
// Otherwise, try loading the class from the code base URL
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == false)
throw new ClassNotFoundException(name);
// final String path = name.replace('.', '/').concat(".class").concat(cookie);
String encodedName = ParseUtil.encodePath(name.replace('.", '/"), false);
final String path = (new StringBuffer(encodedName)).append(".class").append(cookie).toString();
try {
byte[] b = (byte[]) AccessController.doPrivileged(
new PrivilegedExceptionAction() {
public Object run() throws IOException {
return getBytes(new URL(base, path));
}
}, acc);
if (b != null) {
return defineClass(name, b, 0, b.length, codesource);
} else {
throw new ClassNotFoundException(name);
}
} catch (PrivilegedActionException e) {
throw new ClassNotFoundException(name, e.getException());
}
}
|
public URL findResource(String name) {
// check loaded JAR files
URL url = super.findResource(name);
// 6215746: Disable META-INF/* lookup from codebase in
// applet/plugin classloader. [stanley.ho]
if (name.startsWith("META-INF/"))
return url;
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == false)
return url;
if (url == null)
{
//#4805170, if it is a call from Applet.getImage()
//we should check for the image only in the archives
boolean insideGetResourceAsStreamFromJar = false;
synchronized(syncResourceAsStreamFromJar) {
insideGetResourceAsStreamFromJar = resourceAsStreamFromJarInCall;
}
if (insideGetResourceAsStreamFromJar) {
return null;
}
// Fixed #4507227: Slow performance to load
// class and resources. [stanleyh]
//
// Check if getResourceAsStream is called.
//
boolean insideGetResourceAsStream = false;
synchronized(syncResourceAsStream)
{
insideGetResourceAsStream = resourceAsStreamInCall;
}
// If getResourceAsStream is called, don't
// trigger the following code. Otherwise,
// unnecessary connection will be made.
//
if (insideGetResourceAsStream == false)
{
// otherwise, try the code base
try {
url = new URL(base, ParseUtil.encodePath(name, false));
// check if resource exists
if(!resourceExists(url))
url = null;
} catch (Exception e) {
// all exceptions, including security exceptions, are caught
url = null;
}
}
}
return url;
}
|
public Enumeration findResources(String name) throws IOException {
final Enumeration e = super.findResources(name);
// 6215746: Disable META-INF/* lookup from codebase in
// applet/plugin classloader. [stanley.ho]
if (name.startsWith("META-INF/"))
return e;
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == false)
return e;
URL u = new URL(base, ParseUtil.encodePath(name, false));
if (!resourceExists(u)) {
u = null;
}
final URL url = u;
return new Enumeration() {
private boolean done;
public Object nextElement() {
if (!done) {
if (e.hasMoreElements()) {
return e.nextElement();
}
done = true;
if (url != null) {
return url;
}
}
throw new NoSuchElementException();
}
public boolean hasMoreElements() {
return !done && (e.hasMoreElements() || url != null);
}
};
}
|
public AppContext getAppContext() {
return appContext;
}
|
URL getBaseURL() {
return base;
}
|
public boolean getExceptionStatus() {
return exceptionStatus;
}
|
protected PermissionCollection getPermissions(CodeSource codesource) {
final PermissionCollection perms = super.getPermissions(codesource);
URL url = codesource.getLocation();
String path = null;
Permission p;
try {
p = url.openConnection().getPermission();
} catch (java.io.IOException ioe) {
p = null;
}
if (p instanceof FilePermission) {
path = p.getName();
} else if ((p == null) && (url.getProtocol().equals("file"))) {
path = url.getFile().replace('/", File.separatorChar);
path = ParseUtil.decode(path);
}
if (path != null) {
if (!path.endsWith(File.separator)) {
int endIndex = path.lastIndexOf(File.separatorChar);
if (endIndex != -1) {
path = path.substring(0, endIndex+1) + "-";
perms.add(new FilePermission(path,
SecurityConstants.FILE_READ_ACTION));
}
}
perms.add(new SocketPermission("localhost",
SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION));
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
try {
String host = InetAddress.getLocalHost().getHostName();
perms.add(new SocketPermission(host,
SecurityConstants.SOCKET_CONNECT_ACCEPT_ACTION));
} catch (UnknownHostException uhe) {
}
return null;
}
});
Permission bperm;
try {
bperm = base.openConnection().getPermission();
} catch (java.io.IOException ioe) {
bperm = null;
}
if (bperm instanceof FilePermission) {
String bpath = bperm.getName();
if (bpath.endsWith(File.separator)) {
bpath += "-";
}
perms.add(new FilePermission(bpath,
SecurityConstants.FILE_READ_ACTION));
} else if ((bperm == null) && (base.getProtocol().equals("file"))) {
String bpath = base.getFile().replace('/", File.separatorChar);
bpath = ParseUtil.decode(bpath);
if (bpath.endsWith(File.separator)) {
bpath += "-";
}
perms.add(new FilePermission(bpath, SecurityConstants.FILE_READ_ACTION));
}
}
return perms;
}
Returns the permissions for the given codesource object.
The implementation of this method first calls super.getPermissions,
to get the permissions
granted by the super class, and then adds additional permissions
based on the URL of the codesource.
If the protocol is "file"
and the path specifies a file, permission is granted to read all files
and (recursively) all files and subdirectories contained in
that directory. This is so applets with a codebase of
file:/blah/some.jar can read in file:/blah/, which is needed to
be backward compatible. We also add permission to connect back to
the "localhost". |
public InputStream getResourceAsStream(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try
{
InputStream is = null;
// Fixed #4507227: Slow performance to load
// class and resources. [stanleyh]
//
// The following is used to avoid calling
// AppletClassLoader.findResource() in
// super.getResourceAsStream(). Otherwise,
// unnecessary connection will be made.
//
synchronized(syncResourceAsStream)
{
resourceAsStreamInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamInCall = false;
}
// 4668479: Option to turn off codebase lookup in AppletClassLoader
// during resource requests. [stanley.ho]
if (codebaseLookup == true && is == null)
{
// If resource cannot be obtained,
// try to download it from codebase
URL url = new URL(base, ParseUtil.encodePath(name, false));
is = url.openStream();
}
return is;
}
catch (Exception e)
{
return null;
}
}
Returns an input stream for reading the specified resource.
The search order is described in the documentation for #getResource(String) . |
public InputStream getResourceAsStreamFromJar(String name) {
if (name == null) {
throw new NullPointerException("name");
}
try {
InputStream is = null;
synchronized(syncResourceAsStreamFromJar) {
resourceAsStreamFromJarInCall = true;
// Call super class
is = super.getResourceAsStream(name);
resourceAsStreamFromJarInCall = false;
}
return is;
} catch (Exception e) {
return null;
}
}
Returns an input stream for reading the specified resource from the
the loaded jar files.
The search order is described in the documentation for #getResource(String) . |
public ThreadGroup getThreadGroup() {
synchronized (threadGroupSynchronizer) {
if (threadGroup == null || threadGroup.isDestroyed()) {
AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
threadGroup = new AppletThreadGroup(base + "-threadGroup");
// threadGroup.setDaemon(true);
// threadGroup is now destroyed by AppContext.dispose()
// Create the new AppContext from within a Thread belonging
// to the newly created ThreadGroup, and wait for the
// creation to complete before returning from this method.
AppContextCreator creatorThread = new AppContextCreator(threadGroup);
// Since this thread will later be used to launch the
// applet's AWT-event dispatch thread and we want the applet
// code executing the AWT callbacks to use their own class
// loader rather than the system class loader, explicitly
// set the context class loader to the AppletClassLoader.
creatorThread.setContextClassLoader(AppletClassLoader.this);
synchronized(creatorThread.syncObject) {
creatorThread.start();
try {
creatorThread.syncObject.wait();
} catch (InterruptedException e) { }
appContext = creatorThread.appContext;
}
return null;
}
});
}
return threadGroup;
}
}
|
public URL[] getURLs() {
URL[] jars = super.getURLs();
URL[] urls = new URL[jars.length + 1];
System.arraycopy(jars, 0, urls, 0, jars.length);
urls[urls.length - 1] = base;
return urls;
}
|
void grab() {
synchronized(grabReleaseSynchronizer) {
usageCount++;
}
getThreadGroup(); // Make sure ThreadGroup/AppContext exist
}
Grab this AppletClassLoader and its ThreadGroup/AppContext, so they
won't be destroyed. |
Boolean isJDK11Target(Class clazz) {
return (Boolean) jdk11AppletInfo.get(clazz.toString());
}
Determine if applet is targeted for JDK 1.1. |
Boolean isJDK12Target(Class clazz) {
return (Boolean) jdk12AppletInfo.get(clazz.toString());
}
Determine if applet is targeted for JDK 1.2. |
public synchronized Class loadClass(String name,
boolean resolve) throws ClassNotFoundException {
// First check if we have permission to access the package. This
// should go away once we've added support for exported packages.
int i = name.lastIndexOf('.");
if (i != -1) {
SecurityManager sm = System.getSecurityManager();
if (sm != null)
sm.checkPackageAccess(name.substring(0, i));
}
try {
return super.loadClass(name, resolve);
} catch (ClassNotFoundException e) {
//printError(name, e.getException());
throw e;
} catch (RuntimeException e) {
//printError(name, e);
throw e;
} catch (Error e) {
//printError(name, e);
throw e;
}
}
|
Class loadCode(String name) throws ClassNotFoundException {
// first convert any '/' or native file separator to .
name = name.replace('/", '.");
name = name.replace(File.separatorChar, '.");
// deal with URL rewriting
String cookie = null;
int index = name.indexOf(";");
if(index != -1) {
cookie = name.substring(index, name.length());
name = name.substring(0, index);
}
// save that name for later
String fullName = name;
// then strip off any suffixes
if (name.endsWith(".class") || name.endsWith(".java")) {
name = name.substring(0, name.lastIndexOf('."));
}
try {
if(cookie != null)
name = (new StringBuffer(name)).append(cookie).toString();
return loadClass(name);
} catch (ClassNotFoundException e) {
}
// then if it didn't end with .java or .class, or in the
// really pathological case of a class named class or java
if(cookie != null)
fullName = (new StringBuffer(fullName)).append(cookie).toString();
return loadClass(fullName);
}
|
protected void release() {
AppContext tempAppContext = null;
synchronized(grabReleaseSynchronizer) {
if (usageCount > 1) {
--usageCount;
} else {
synchronized(threadGroupSynchronizer) {
// Store app context in temp variable
tempAppContext = appContext;
usageCount = 0;
appContext = null;
threadGroup = null;
}
}
}
// Dispose appContext outside any sync block to
// prevent potential deadlock.
if (tempAppContext != null) {
try {
tempAppContext.dispose(); // nuke the world!
} catch (IllegalThreadStateException e) { }
}
}
Release this AppletClassLoader and its ThreadGroup/AppContext.
If nothing else has grabbed this AppletClassLoader, its ThreadGroup
and AppContext will be destroyed.
Because this method may destroy the AppletClassLoader's ThreadGroup,
this method should NOT be called from within the AppletClassLoader's
ThreadGroup.
Changed modifier to protected in order to be able to overwrite this
function in PluginClassLoader.java |
void setCodebaseLookup(boolean codebaseLookup) {
this.codebaseLookup = codebaseLookup;
}
Set the codebase lookup flag. |
protected void setExceptionStatus() {
exceptionStatus = true;
}
|
void setJDK11Target(Class clazz,
boolean bool) {
jdk11AppletInfo.put(clazz.toString(), Boolean.valueOf(bool));
}
Set applet target level as JDK 1.1. |
void setJDK12Target(Class clazz,
boolean bool) {
jdk12AppletInfo.put(clazz.toString(), Boolean.valueOf(bool));
}
Set applet target level as JDK 1.2. |