1 22 package org.jboss.mx.loading; 23 24 import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap; 25 26 import org.jboss.classloading.spi.ClassLoadingDomain; 27 import org.jboss.classloading.spi.DomainClassLoader; 28 import org.jboss.classloading.spi.Translator; 29 import org.jboss.logging.Logger; 30 import org.jboss.mx.server.ServerConstants; 31 32 import java.net.URL ; 33 import java.util.HashMap ; 34 import java.util.List ; 35 import java.util.Vector ; 36 37 44 public abstract class LoaderRepositoryDomain 45 implements ServerConstants, ClassLoadingDomain 46 { 47 48 protected static Vector loaders = new Vector (); 50 protected static LoaderRepositoryDomain instance = null; 51 protected Translator translator = null; 52 53 56 private ConcurrentReaderHashMap classes = new ConcurrentReaderHashMap(); 57 58 59 62 private static HashMap nativeClassBySignature; 63 64 private static final Logger log = Logger.getLogger(LoaderRepositoryDomain.class); 66 67 70 static 71 { 72 nativeClassBySignature = new HashMap(); 73 nativeClassBySignature.put("boolean", boolean.class); 74 nativeClassBySignature.put("byte", byte.class); 75 nativeClassBySignature.put("char", char.class); 76 nativeClassBySignature.put("double", double.class); 77 nativeClassBySignature.put("float", float.class); 78 nativeClassBySignature.put("int", int.class); 79 nativeClassBySignature.put("long", long.class); 80 nativeClassBySignature.put("short", short.class); 81 nativeClassBySignature.put("void", void.class); 82 83 nativeClassBySignature.put("boolean[]", boolean[].class); 84 nativeClassBySignature.put("byte[]", byte[].class); 85 nativeClassBySignature.put("char[]", char[].class); 86 nativeClassBySignature.put("double[]", double[].class); 87 nativeClassBySignature.put("float[]", float[].class); 88 nativeClassBySignature.put("int[]", int[].class); 89 nativeClassBySignature.put("long[]", long[].class); 90 nativeClassBySignature.put("short[]", short[].class); 91 } 92 93 public Vector getLoaders() 95 { 96 return loaders; 97 } 98 99 public URL [] getURLs() 100 { 101 return null; 102 } 103 104 public Class getCachedClass(String classname) 105 { 106 return (Class )classes.get(classname); 107 } 108 109 public Translator getTranslator() 110 { 111 return translator; 112 } 113 114 public void setTranslator(Translator t) 115 { 116 translator = t; 117 } 118 119 125 public int compare(LoaderRepositoryDomain lr) 126 { 127 if (lr == this) 128 return 0; 129 else 130 return 1; 131 } 132 133 135 143 public abstract Class loadClass(String className) throws ClassNotFoundException ; 144 153 public abstract Class loadClass(String name, boolean resolve, DomainClassLoader classLoader) throws ClassNotFoundException ; 154 155 157 164 public abstract DomainClassLoader newClassLoader(final URL url, boolean addToRepository) 165 throws Exception ; 166 176 public abstract DomainClassLoader newClassLoader(final URL url, final URL origURL, 177 boolean addToRepository) 178 throws Exception ; 179 180 186 public abstract URL getResource(String name, DomainClassLoader cl); 187 195 public abstract void getResources(String name, DomainClassLoader cl, List urls); 196 197 199 public abstract void addClassLoader(DomainClassLoader cl); 200 206 public abstract boolean addClassLoaderURL(DomainClassLoader cl, URL url); 207 210 public abstract void removeClassLoader(DomainClassLoader cl); 211 212 216 public static final Class getNativeClassForName(String className) 217 { 218 return (Class )nativeClassBySignature.get(className); 220 } 221 222 228 protected int reverseCompare(LoaderRepositoryDomain lr) 229 { 230 return 0; 231 } 232 233 236 void cacheLoadedClass(String name, Class cls, DomainClassLoader cl) 237 { 238 synchronized( classes ) 239 { 240 classes.put(name, cls); 242 if( log.isTraceEnabled() ) 243 { 244 log.trace("cacheLoadedClass, classname: "+name+", class: "+cls 245 +", cl: "+cl); 246 } 247 248 256 } 257 } 258 259 void clear() 260 { 261 classes.clear(); 262 } 263 } 264 | Popular Tags |