01: package com.mockrunner.gen.jar;
02:
03: import java.net.URL;
04: import java.net.URLClassLoader;
05:
06: /*
07: * Used by Mockrunner test suite to run the tests against different jars
08: */
09: public class TestConfigurationClassLoader extends URLClassLoader {
10: public TestConfigurationClassLoader(URL[] urls, ClassLoader parent) {
11: super (urls, parent);
12: }
13:
14: protected synchronized Class loadClass(String name, boolean resolve)
15: throws ClassNotFoundException {
16: Class clazz = findLoadedClass(name);
17: if (null != clazz)
18: return clazz;
19: try {
20: clazz = findClass(name);
21: } catch (ClassNotFoundException exc) {
22: /*
23: * Dirty hack to get around CGLib 2.0.2 (and up) issues.
24: * CGLib tries to load some internal enhanced classes
25: * with the classloader before recreating them. The system
26: * classloader returns the enhanced version of the previous
27: * run which causes a ClassCastException. The ClassNotFoundException
28: * forces CGLib to recreate this classes.
29: * This is not necessary for CGGLIB 2.0 and previous.
30: */
31: if (name.indexOf("ByCGLIB$") != -1) {
32: throw exc;
33: }
34: clazz = getParent().loadClass(name);
35: }
36: if (resolve) {
37: resolveClass(clazz);
38: }
39: return clazz;
40: }
41: }
|