Java Reference
In-Depth Information
L ISTING 6.3 Continued
6
* see superclasss
*/
public Class loadClass(String className, byte[] b){
return defineClass(className, b, 0, b.length );
}
/**
* This method returns a cached class
* @return a cached class as a byte array
*/
protected byte[] getClass(String className){
// flatten up package information
String fileName = helper.getCacheClassFileName(className);
byte[] b = null;
int size = 0;
try {
File f = helper.getCachedFile(fileName+”.class”);
size = (int)f.length();
b = new byte[size];
DataInputStream dis =
new DataInputStream(f.toURL().openConnection().getInputStream());
dis.readFully(b);
} catch (Exception e){
System.out.println(“BankClientLoader- getClass(“+className+”): “+e);
}
return b;
}
}
The most important thing to note in Listing 6.3 is the class loading mechanism implemented in
the loadClass method (lines 73-129). The class loading procedure is the following:
1. Look for the requested class in the local cache.
2. Ask for the class to the super classloader.
3. Request the class directly to the server.
This mechanism allows for replacing already installed classes with newer versions that need
only to have the same class name and be saved in the client cache. The third step is important,
too, because it allows for direct server download of classes that are neither in cache nor in the
classpath. In this way, completely new applications can be installed in the local cache just by
specifying the main class only. Thus, once the new main class is executed, all the other classes
Search WWH ::




Custom Search