01: /* JFox, the OpenSource J2EE Application Server
02: *
03: * Copyright (C) 2002 huihoo.com
04: * Distributable under GNU LGPL license
05: * See the GNU Lesser General Public License for more details.
06: */
07:
08: package org.huihoo.jfox.jmx.loading;
09:
10: import java.util.List;
11: import java.util.ArrayList;
12: import java.util.Iterator;
13:
14: /**
15: *
16: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
17: */
18:
19: public class ClassLoaderRepositorySupport implements
20: ExtendedClassLoaderRepository {
21:
22: private volatile List loaders = new ArrayList();
23:
24: public ClassLoaderRepositorySupport() {
25: // add the default class loader
26: this .addClassLoader(Thread.currentThread()
27: .getContextClassLoader());
28: }
29:
30: public void addClassLoader(ClassLoader loader) {
31: if (!(loaders.contains(loader)))
32: loaders.add(loader);
33: }
34:
35: public void removeClassLoader(ClassLoader classloader) {
36: loaders.remove(classloader);
37: }
38:
39: public Class loadClass(String className)
40: throws ClassNotFoundException {
41: return loadClassWithout(null, className);
42: }
43:
44: /**
45: * load a class without the specify classloader
46: * @param loader
47: * @param className
48: * @return Class object
49: * @throws ClassNotFoundException
50: */
51: public Class loadClassWithout(ClassLoader loader, String className)
52: throws ClassNotFoundException {
53: Iterator it = loaders.iterator();
54: Class cls = null;
55: while (it.hasNext()) {
56: ClassLoader cl = (ClassLoader) it.next();
57: if (cl.equals(loader))
58: continue;
59: // if it's MLetRI , the loadClass(String className) will not use LoaderRepository
60: try {
61: cls = cl.loadClass(className);
62: } catch (ClassNotFoundException e) {
63: // ignore the exception
64: }
65: }
66: if (cls == null)
67: throw new ClassNotFoundException(className); // class not found
68: return cls;
69: }
70:
71: }
|