1 22 package org.jboss.mx.loading; 23 24 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 25 import org.jboss.logging.Logger; 26 import org.jboss.mx.server.ServerConstants; 27 import org.jboss.util.loading.Translator; 28 29 import javax.management.loading.ClassLoaderRepository ; 30 import java.net.URL ; 31 import java.util.HashMap ; 32 import java.util.List ; 33 import java.util.Vector ; 34 35 43 public abstract class LoaderRepository 44 implements ServerConstants, ClassLoaderRepository 45 { 46 47 protected static Vector loaders = new Vector (); 49 protected static LoaderRepository instance = null; 50 protected Translator translator = null; 51 52 55 private ConcurrentReaderHashMap classes = new ConcurrentReaderHashMap(); 56 57 58 61 private static HashMap nativeClassBySignature; 62 63 private static final Logger log = Logger.getLogger(LoaderRepository.class); 65 66 69 static 70 { 71 nativeClassBySignature = new HashMap(); 72 nativeClassBySignature.put("boolean", boolean.class); 73 nativeClassBySignature.put("byte", byte.class); 74 nativeClassBySignature.put("char", char.class); 75 nativeClassBySignature.put("double", double.class); 76 nativeClassBySignature.put("float", float.class); 77 nativeClassBySignature.put("int", int.class); 78 nativeClassBySignature.put("long", long.class); 79 nativeClassBySignature.put("short", short.class); 80 nativeClassBySignature.put("void", void.class); 81 82 nativeClassBySignature.put("boolean[]", boolean[].class); 83 nativeClassBySignature.put("byte[]", byte[].class); 84 nativeClassBySignature.put("char[]", char[].class); 85 nativeClassBySignature.put("double[]", double[].class); 86 nativeClassBySignature.put("float[]", float[].class); 87 nativeClassBySignature.put("int[]", int[].class); 88 nativeClassBySignature.put("long[]", long[].class); 89 nativeClassBySignature.put("short[]", short[].class); 90 } 91 92 public Vector getLoaders() 94 { 95 return loaders; 96 } 97 98 public URL [] getURLs() 99 { 100 return null; 101 } 102 103 public Class getCachedClass(String classname) 104 { 105 return (Class )classes.get(classname); 106 } 107 108 public Translator getTranslator() 109 { 110 return translator; 111 } 112 113 public void setTranslator(Translator t) 114 { 115 translator = t; 116 } 117 118 124 public int compare(LoaderRepository lr) 125 { 126 if (lr == this) 127 return 0; 128 else 129 return -lr.reverseCompare(this); 130 } 131 132 134 142 public abstract Class loadClass(String className) throws ClassNotFoundException ; 143 144 153 public abstract Class loadClassWithout(ClassLoader loader, String className) throws ClassNotFoundException ; 154 155 168 public abstract Class loadClassBefore(ClassLoader stop, String className) throws ClassNotFoundException ; 169 170 172 179 public abstract RepositoryClassLoader newClassLoader(final URL url, boolean addToRepository) 180 throws Exception ; 181 191 public abstract RepositoryClassLoader newClassLoader(final URL url, final URL origURL, 192 boolean addToRepository) 193 throws Exception ; 194 195 202 public abstract Class loadClass(String name, boolean resolve, ClassLoader cl) 203 throws ClassNotFoundException ; 204 205 211 public abstract URL getResource(String name, ClassLoader cl); 212 220 public abstract void getResources(String name, ClassLoader cl, List urls); 221 222 224 public abstract void addClassLoader(ClassLoader cl); 225 231 public abstract boolean addClassLoaderURL(ClassLoader cl, URL url); 232 235 public abstract void removeClassLoader(ClassLoader cl); 236 237 241 public static final Class getNativeClassForName(String className) 242 { 243 return (Class )nativeClassBySignature.get(className); 245 } 246 247 253 protected int reverseCompare(LoaderRepository lr) 254 { 255 return 0; 256 } 257 258 261 void cacheLoadedClass(String name, Class cls, ClassLoader cl) 262 { 263 synchronized( classes ) 264 { 265 classes.put(name, cls); 267 if( log.isTraceEnabled() ) 268 { 269 log.trace("cacheLoadedClass, classname: "+name+", class: "+cls 270 +", cl: "+cl); 271 } 272 273 281 } 282 } 283 284 void clear() 285 { 286 classes.clear(); 287 } 288 } 289 | Popular Tags |