01: package org.andromda.maven.plugin.configuration;
02:
03: import java.net.URL;
04: import java.net.URLClassLoader;
05:
06: /**
07: * A custom class loader nessary to avoid class loading errors
08: * when running within Maven2.
09: *
10: * @author Chad Brandon
11: */
12: public class ConfigurationClassLoader extends URLClassLoader {
13: public ConfigurationClassLoader(final URL[] urls,
14: final ClassLoader parent) {
15: super (urls, parent);
16: }
17:
18: /**
19: * @see java.lang.ClassLoader#loadClass(java.lang.String)
20: */
21: public Class loadClass(final String name)
22: throws ClassNotFoundException {
23: return this .loadClass(name, false);
24: }
25:
26: /**
27: * @see java.lang.ClassLoader#loadClass(java.lang.String, boolean)
28: */
29: protected Class loadClass(final String name, final boolean resolve)
30: throws ClassNotFoundException {
31: // - first, we check if the class has already been loaded
32: Class loadedClass = this .findLoadedClass(name);
33:
34: // - if we could not find it, try to find it in the parent
35: if (loadedClass == null) {
36: final ClassLoader parent = this .getParent();
37: if (parent != null) {
38: try {
39: loadedClass = parent.loadClass(name);
40: } catch (final ClassNotFoundException exception) {
41: // - ignore
42: }
43: } else {
44: loadedClass = getSystemClassLoader().loadClass(name);
45: }
46: }
47:
48: // - if not loaded from the parent, search this classloader
49: if (loadedClass == null) {
50: loadedClass = findClass(name);
51: }
52:
53: if (resolve) {
54: this.resolveClass(loadedClass);
55: }
56:
57: return loadedClass;
58: }
59: }
|