Loaderpublic class Loader extends Object This class is a class loader. |
Fields Summary |
---|
private Vector | classPathClass path. | private Hashtable | classesLoaded classes. | private com.sun.satsa.jcrmic.utils.Notifier | notifierErrors/warnings notifier. |
Methods Summary |
---|
public JClass | getClass(java.lang.String className)Returns class definition loaded earlier.
return (JClass) classes.get(className.replace('.", '/"));
| public boolean | loadClass(java.lang.String className)Loads the class.
className = className.replace('.", '/");
// check to avoid duplicate loading
if (classes.containsKey(className))
return true;
InputStream is = null;
for (int i = 0; i < classPath.size(); i++) {
if (classPath.elementAt(i) instanceof String) {
String path = (String) classPath.elementAt(i);
path += File.separator +
className.replace('/", File.separatorChar) +
".class";
File f = new File(path);
if (!f.exists())
continue;
try {
is = new FileInputStream(f);
} catch (FileNotFoundException e) {
continue;
}
} else {
ZipFile z = (ZipFile) classPath.elementAt(i);
ZipEntry ze = z.getEntry(className + ".class");
if (ze == null)
continue;
try {
is = z.getInputStream(ze);
} catch (IOException e) {
notifier.error("rmic.ioerror", z.getName());
return false;
}
}
if (is != null)
break;
}
if (is == null) {
notifier.error("rmic.class.not.found", className);
return false;
}
// class file is found, load it
DataInputStream dis = new DataInputStream(
new BufferedInputStream(is));
JClass cl = new JClass(this);
try {
cl.parse(dis);
} catch (Exception e) {
notifier.error("rmic.parsing.error", className);
return false;
}
// class is loaded
classes.put(className, cl);
// update the class, load all related classes
if (!cl.update())
return false;
return true;
| public boolean | setClassPath(java.lang.String path)Set path for class loading.
classPath.clear();
StringTokenizer parser = new StringTokenizer(path, File.pathSeparator);
while (parser.hasMoreTokens()) {
String s = parser.nextToken();
File f = new File(s);
try {
if (f.isDirectory()) {
// directory - add path to the vector
classPath.addElement(f.getCanonicalPath());
} else {
// file - check that it exists
if (!f.exists()) {
notifier.error("rmic.file.not.found", s);
return false;
}
ZipFile z = new ZipFile(f);
classPath.addElement(z);
}
} catch (IOException e) {
notifier.error("rmic.incorrect.classpath", s);
return false;
}
}
if (classPath.size() == 0) {
return false;
}
return true;
|
|