1 29 30 package com.caucho.bytecode; 31 32 import com.caucho.loader.EnvironmentLocal; 33 34 import java.util.logging.Level ; 35 36 39 public class JClassLoaderWrapper extends JClassLoader { 40 private static final 41 EnvironmentLocal<JClassLoaderWrapper> _localClassLoader = 42 new EnvironmentLocal<JClassLoaderWrapper>(); 43 44 private ClassLoader _loader; 45 46 49 private JClassLoaderWrapper(ClassLoader loader) 50 { 51 _loader = loader; 52 } 53 54 57 public static JClassLoaderWrapper create() 58 { 59 return create(Thread.currentThread().getContextClassLoader()); 60 } 61 62 65 public static JClassLoaderWrapper create(ClassLoader loader) 66 { 67 JClassLoaderWrapper jLoader = _localClassLoader.getLevel(loader); 68 69 if (jLoader == null) { 70 jLoader = new JClassLoaderWrapper(loader); 71 _localClassLoader.set(jLoader, loader); 72 } 73 74 return jLoader; 75 } 76 77 80 protected JClass loadClass(String name) 81 { 82 try { 83 Class cl; 84 85 if (_loader != null) 86 cl = Class.forName(name, false, _loader); 87 else 88 cl = Class.forName(name); 89 90 return new JClassWrapper(cl, this); 91 } catch (ClassNotFoundException e) { 92 log.log(Level.FINE, e.toString(), e); 93 94 return null; 95 } 96 } 97 98 public String toString() 99 { 100 return "JClassLoaderWrapper[" + _loader + "]"; 101 } 102 } 103 | Popular Tags |