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: /**
11: *
12: * @author <a href="mailto:young_yy@hotmail.com">Young Yang</a>
13: */
14:
15: public class SignatureClassLoader {
16: private PrimitiveClassLoader primitiveLoader = PrimitiveClassLoader
17: .getInstance();
18: private ClassLoader systemLoader = Thread.currentThread()
19: .getContextClassLoader();
20: private static SignatureClassLoader me = new SignatureClassLoader();
21:
22: public static SignatureClassLoader getInstance() {
23: return me;
24: }
25:
26: // only use system class loader and the primitive class loader to load signatures class
27: public Class[] loadClasses(String[] signatures)
28: throws ClassNotFoundException {
29: if (signatures == null || signatures.length == 0)
30: return null;
31: int length = signatures.length;
32: Class[] signatureClasses = new Class[length];
33: for (int i = 0; i < length; i++) {
34: // try for primitive class first
35: Class cla = primitiveLoader.loadClass(signatures[i]);
36: if (cla != null) {
37: signatureClasses[i] = cla;
38: } else { // not primitive class, load it
39: cla = systemLoader.loadClass(signatures[i]);
40: }
41:
42: if (cla == null)
43: throw new ClassNotFoundException(signatures[i]); // class not found
44: signatureClasses[i] = cla;
45: }
46:
47: return signatureClasses;
48: }
49:
50: }
|