home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magazyn WWW 2000 June
/
www-06-2000.iso
/
java
/
HashtableClassLoader.java
< prev
next >
Wrap
Text File
|
2000-04-11
|
984b
|
45 lines
import java.util.*;
import java.io.*;
public class HashtableClassLoader extends ClassLoader {
private Hashtable cache = new Hashtable();
private Hashtable data;
public HashtableClassLoader(Hashtable data) {
this.data=data;
}
public synchronized Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
String name0=name.replace('.', '/');
Class c = (Class)cache.get(name);
if (c == null) {
byte[] bytes = (byte[])data.get(name0+".class");
if (bytes==null) {
c=findSystemClass(name);
if (c==null) {
throw new ClassNotFoundException(name);
}
return c;
}
c = defineClass(name, bytes, 0, bytes.length);
cache.put(name, c);
}
if (resolve) {
resolveClass(c);
}
return c;
}
public InputStream getResourceAsStream(String name) {
byte[] bytes=(byte[])data.get(name);
if (bytes!=null) {
return new ByteArrayInputStream(bytes);
}
return null;
}
}