Define and use a ClassLoader in an applet

LucLaf@aol.com
Sun, 11 May 1997 04:36:11 -0400 (EDT)

From: LucLaf@aol.com
Date: Sun, 11 May 1997 04:36:11 -0400 (EDT)
To: java-security@web2.javasoft.com
Subject: Define and use a ClassLoader in an applet

I have made a class loader named SpecialClassLoader derivated from
ClassLoader.
It is used by an other class named SuperClassLoader derivated from Thread.

These classes works very well while I work on my development bench (MSDEV /
VisualJ++).
(downloaded classes installed on HTTP server).

But when I use them with a browser (netscape 2.01 / IE3.0) via HTTP server, a
security exception is thrown.
This exception appear when the SpecialClassLoader constructor is invoked.

Then, before invoke this constructor, I test if I can do that with the
checkCreateClassLoader()
method of default SecurityManager.
This don't throw exception, then I conclued I can define a new class loader.
But in fact I can't!

Is there any people who explain this phenomenon ?
And, last but not least, what can I do to used a class loader in an applet ?

Luc laforets - LucLaf@aol.com

/*
******************************************************************************
*******
Class : SuperClassLoader
Inherit : None.
Using : SpecialClassloader.
Files : SuperClassLoader.java
Use : This class manage a class download.
Remarks : None.
Usage : By the LoadManager object.
Author : L.Laforets.
Date : 05 mar 97
Update : By : None.
Date : None.
Subject : None.
******************************************************************************
****** */

package node;

import java.net.URL;

public class SuperClassLoader extends Thread {
//Data members
exerciseShell motherApplet; //The exerciseShell applet
String name; //The class name to download
URL base; //The http server URL
Class theLoadedClass; //The downloaded class

//Constructor
public SuperClassLoader (exerciseShell aplt, String nm, URL urlBase) {
super();
motherApplet = aplt;
name = nm;
base = urlBase;
}

//Method members
public void run() {
try {
SecurityManager security = System.getSecurityManager();
if (security != null) {
security.checkCreateClassLoader();
//WHEN USE IN REAL BROWSER THE FOLLOWING LINE THROW A SECURITY EXCEPTION
SpecialClassLoader scl = new SpecialClassLoader(motherApplet, base);
theLoadedClass = scl.loadClass(name, true);
}
catch (Exception e) {
theLoadedClass = null;
}
}

public Class getLoadedClass() {
return theLoadedClass;
}
}

/*
******************************************************************************
*******
Class : SpecialClassLoader
Inherit : ClassLoader.
Using : Hashtable, URL.
Files : SpecialClassLoader.java
Use : Implement a networked class loader.
Remarks : Inspired by Sun class sun.applet.AppletClassLoader.
Usage : Download node classes.
Author : L.Laforets.
Date : 04 mar 97
Update : By : None.
Date : None.
Subject : None.
******************************************************************************
****** */

package node;

import java.util.Hashtable;
import java.io.InputStream;
import java.io.IOException;
import java.io.FileNotFoundException;
import java.net.URL;
import java.net.URLConnection;
import java.net.MalformedURLException;

class SpecialClassLoader extends ClassLoader {
//Data members
URL base; //The base URL
final String PACKAGE = "node"; //The classes package
exerciseShell motherApplet; //The mothet applet

SpecialClassLoader(exerciseShell mother, URL baseUrl) {
motherApplet = mother;
base = baseUrl;
}
CONTINUE ......