1 28 29 package com.caucho.jmx; 30 31 import com.caucho.log.Log; 32 import com.caucho.util.L10N; 33 34 import javax.management.loading.ClassLoaderRepository ; 35 import java.util.ArrayList ; 36 import java.util.logging.Logger ; 37 38 41 public class ClassLoaderRepositoryImpl implements ClassLoaderRepository { 42 private static final L10N L = new L10N(ClassLoaderRepositoryImpl.class); 43 private static final Logger log = Log.open(ClassLoaderRepositoryImpl.class); 44 45 private ArrayList <ClassLoader > _loaders = new ArrayList <ClassLoader >(); 46 47 50 void addClassLoader(ClassLoader loader) 51 { 52 _loaders.add(loader); 53 } 54 55 58 public Class loadClass(String className) 59 throws ClassNotFoundException 60 { 61 for (int i = 0; i < _loaders.size(); i++) { 62 ClassLoader loader = _loaders.get(i); 63 64 try { 65 Class cl = loader.loadClass(className); 66 67 if (cl != null) 68 return cl; 69 } catch (ClassNotFoundException e) { 70 } 71 } 72 73 throw new ClassNotFoundException (L.l("can't load class {0}", 74 className)); 75 } 76 77 80 public Class loadClassBefore(ClassLoader stop, String className) 81 throws ClassNotFoundException 82 { 83 for (int i = 0; i < _loaders.size(); i++) { 84 ClassLoader loader = _loaders.get(i); 85 86 if (loader == stop) 87 break; 88 89 try { 90 Class cl = loader.loadClass(className); 91 92 if (cl != null) 93 return cl; 94 } catch (ClassNotFoundException e) { 95 } 96 } 97 98 throw new ClassNotFoundException (L.l("can't load class {0}", 99 className)); 100 } 101 102 105 public Class loadClassWithout(ClassLoader exclude, String className) 106 throws ClassNotFoundException 107 { 108 for (int i = 0; i < _loaders.size(); i++) { 109 ClassLoader loader = _loaders.get(i); 110 111 if (loader == exclude) 112 continue; 113 114 try { 115 Class cl = loader.loadClass(className); 116 117 if (cl != null) 118 return cl; 119 } catch (ClassNotFoundException e) { 120 } 121 } 122 123 throw new ClassNotFoundException (L.l("can't load class {0}", 124 className)); 125 } 126 } 127 | Popular Tags |