1 21 22 package org.armedbear.j; 23 24 import java.io.DataInputStream ; 25 26 public final class ExtensionClassLoader extends ClassLoader  27 { 28 public Class loadClass(String s, boolean resolve) throws ClassNotFoundException  29 { 30 try { 31 File file = null; 32 String classname = null; 33 Class c = null; 34 if (s.endsWith(".class")) { 35 file = File.getInstance(Directories.getEditorDirectory(), s); 38 } else { 39 classname = s; 41 } 42 if (classname != null) { 43 c = findLoadedClass(classname); 44 if (c == null) { 45 try { 46 c = findSystemClass(classname); 47 } 48 catch (Exception e) {} 49 } 50 if (c == null) { 51 Debug.assertTrue(file == null); 53 file = File.getInstance(Directories.getEditorDirectory(), 54 classname.concat(".class")); 55 } 56 } 57 if (c == null) { 58 Log.debug("looking for extension class in file " + file.getCanonicalPath()); 59 if (file.isFile()) { 60 long length = file.length(); 61 if (length < Integer.MAX_VALUE) { 62 byte[] classbytes = new byte[(int)length]; 63 DataInputStream in = new DataInputStream (file.getInputStream()); 64 in.readFully(classbytes); 65 in.close(); 66 c = defineClass(classname, classbytes, 0, (int) length); 67 } 68 } else 69 Log.debug("not found " + file.getCanonicalPath()); 70 } 71 if (c != null && resolve) 72 resolveClass(c); 73 return c; 74 } 75 catch (Exception e) { 76 throw new ClassNotFoundException (e.toString()); 77 } 78 } 79 } 80 | Popular Tags |