1
2
3
4
5
6
7
8 package it.imolinfo.jbi4corba.webservice.generator;
9
10 import java.net.URL;
11 import java.net.URLClassLoader;
12 import java.net.URLStreamHandlerFactory;
13
14
15
16
17
18 public class ChildFirstClassLoader extends URLClassLoader {
19
20
21 public ChildFirstClassLoader() {
22 this(null, null, null);
23 }
24
25
26 public ChildFirstClassLoader(final ClassLoader parent) {
27 this(new URL[0], parent, null);
28 }
29
30 public ChildFirstClassLoader(final URL[] urls) {
31 this(urls, null, null);
32 }
33
34 public ChildFirstClassLoader(final URL[] urls, final ClassLoader parent) {
35 this(urls, parent, null);
36 }
37 public ChildFirstClassLoader(final URL[] urls, final ClassLoader parent, final URLStreamHandlerFactory factory) {
38 super(urls, parent, factory);
39 }
40 public static final URLClassLoader newInstance(final URL[] urls) {
41 return new ChildFirstClassLoader(urls);
42 }
43 public static final URLClassLoader newInstance(final URL[] urls, final ClassLoader parent) {
44 return new ChildFirstClassLoader(urls, parent);
45 }
46
47 public final Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
48
49 Class clazz = findLoadedClass(name);
50
51 if (clazz == null) {
52 try {
53
54 clazz = findClass(name);
55 } catch (ClassNotFoundException cnfe) {
56 ClassLoader parent = getParent();
57
58 if (parent != null) {
59
60 clazz = parent.loadClass(name);
61 } else {
62
63 throw cnfe;
64 }
65 }
66 }
67
68 if (resolve) {
69 resolveClass(clazz);
70 }
71
72 return clazz;
73 }
74
75 }
76