01: /*
02: * DynamicLibraryLoader.java
03: *
04: * Copyright (C) 2002, 2003, 2004, 2005, 2006 Takis Diakoumis
05: *
06: * This program is free software; you can redistribute it and/or
07: * modify it under the terms of the GNU General Public License
08: * as published by the Free Software Foundation; either version 2
09: * of the License, or any later version.
10: *
11: * This program is distributed in the hope that it will be useful,
12: * but WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14: * GNU General Public License for more details.
15: *
16: * You should have received a copy of the GNU General Public License
17: * along with this program; if not, write to the Free Software
18: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19: *
20: */
21:
22: package org.underworldlabs.util;
23:
24: import java.io.IOException;
25: import java.net.URLClassLoader;
26: import java.net.URL;
27: import java.util.Enumeration;
28:
29: /* ----------------------------------------------------------
30: * CVS NOTE: Changes to the CVS repository prior to the
31: * release of version 3.0.0beta1 has meant a
32: * resetting of CVS revision numbers.
33: * ----------------------------------------------------------
34: */
35:
36: /**
37: *
38: * @author Takis Diakoumis
39: * @version $Revision: 1.4 $
40: * @date $Date: 2006/05/14 06:56:07 $
41: */
42: public class DynamicLibraryLoader extends URLClassLoader {
43:
44: private ClassLoader parent = null;
45:
46: public DynamicLibraryLoader(URL[] urls) {
47: super (urls, ClassLoader.getSystemClassLoader());
48: parent = ClassLoader.getSystemClassLoader();
49: }
50:
51: public Class loadLibrary(String clazz)
52: throws ClassNotFoundException {
53: return loadClass(clazz, true);
54: }
55:
56: public Class loadLibrary(String clazz, boolean resolve)
57: throws ClassNotFoundException {
58: return loadClass(clazz, resolve);
59: }
60:
61: protected synchronized Class loadClass(String classname,
62: boolean resolve) throws ClassNotFoundException {
63:
64: Class theClass = findLoadedClass(classname);
65:
66: if (theClass != null) {
67: return theClass;
68: }
69:
70: try {
71: theClass = findBaseClass(classname);
72: } catch (ClassNotFoundException cnfe) {
73: theClass = findClass(classname);
74: }
75:
76: if (resolve) {
77: resolveClass(theClass);
78: }
79:
80: return theClass;
81:
82: }
83:
84: private Class findBaseClass(String name)
85: throws ClassNotFoundException {
86:
87: if (parent == null) {
88: return findSystemClass(name);
89: } else {
90: return parent.loadClass(name);
91: }
92:
93: }
94:
95: }
|