1 15 16 package javassist; 17 18 import java.io.InputStream ; 19 import java.net.URL ; 20 import java.lang.ref.WeakReference ; 21 22 41 public class LoaderClassPath implements ClassPath { 42 private WeakReference clref; 43 44 47 public LoaderClassPath(ClassLoader cl) { 48 clref = new WeakReference (cl); 49 } 50 51 public String toString() { 52 Object cl = null; 53 if (clref != null) 54 cl = clref.get(); 55 56 return cl == null ? "<null>" : cl.toString(); 57 } 58 59 64 public InputStream openClassfile(String classname) { 65 String cname = classname.replace('.', '/') + ".class"; 66 ClassLoader cl = (ClassLoader )clref.get(); 67 if (cl == null) 68 return null; else 70 return cl.getResourceAsStream(cname); 71 } 72 73 80 public URL find(String classname) { 81 String cname = classname.replace('.', '/') + ".class"; 82 ClassLoader cl = (ClassLoader )clref.get(); 83 if (cl == null) 84 return null; else 86 return cl.getResource(cname); 87 } 88 89 92 public void close() { 93 clref = null; 94 } 95 } 96 | Popular Tags |