1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.hivemind.impl; |
16 |
| |
17 |
| import java.net.URL; |
18 |
| |
19 |
| import org.apache.hivemind.ApplicationRuntimeException; |
20 |
| import org.apache.hivemind.ClassResolver; |
21 |
| |
22 |
| |
23 |
| |
24 |
| |
25 |
| |
26 |
| |
27 |
| |
28 |
| public class DefaultClassResolver implements ClassResolver |
29 |
| { |
30 |
| private ClassLoader _loader; |
31 |
| |
32 |
| |
33 |
| |
34 |
| |
35 |
| |
36 |
456
| public DefaultClassResolver()
|
37 |
| { |
38 |
456
| this(Thread.currentThread().getContextClassLoader());
|
39 |
| } |
40 |
| |
41 |
457
| public DefaultClassResolver(ClassLoader loader)
|
42 |
| { |
43 |
457
| _loader = loader;
|
44 |
| } |
45 |
| |
46 |
21
| public URL getResource(String name)
|
47 |
| { |
48 |
21
| String stripped = removeLeadingSlash(name);
|
49 |
| |
50 |
21
| URL result = _loader.getResource(stripped);
|
51 |
| |
52 |
21
| return result;
|
53 |
| } |
54 |
| |
55 |
21
| private String removeLeadingSlash(String name)
|
56 |
| { |
57 |
21
| if (name.startsWith("/"))
|
58 |
15
| return name.substring(1);
|
59 |
| |
60 |
6
| return name;
|
61 |
| } |
62 |
| |
63 |
| |
64 |
| |
65 |
| |
66 |
| |
67 |
| |
68 |
| |
69 |
| |
70 |
| |
71 |
| |
72 |
| |
73 |
| |
74 |
| |
75 |
| |
76 |
15
| public Class findClass(String type)
|
77 |
| { |
78 |
15
| try
|
79 |
| { |
80 |
15
| return lookupClass(type);
|
81 |
| } |
82 |
| catch (Throwable t) |
83 |
| { |
84 |
4
| throw new ApplicationRuntimeException(ImplMessages.unableToLoadClass(type, _loader, t),
|
85 |
| t); |
86 |
| } |
87 |
| } |
88 |
| |
89 |
8704
| private Class lookupClass(String type) throws ClassNotFoundException
|
90 |
| { |
91 |
8704
| Class result = JavaTypeUtils.getPrimtiveClass(type);
|
92 |
| |
93 |
8704
| if (result != null)
|
94 |
1
| return result;
|
95 |
| |
96 |
| |
97 |
| |
98 |
| |
99 |
8703
| String jvmName = JavaTypeUtils.getJVMClassName(type);
|
100 |
| |
101 |
8703
| return Class.forName(jvmName, true, _loader);
|
102 |
| } |
103 |
| |
104 |
8689
| public Class checkForClass(String type)
|
105 |
| { |
106 |
8689
| try
|
107 |
| { |
108 |
8689
| return lookupClass(type);
|
109 |
| } |
110 |
| catch (ClassNotFoundException ex) |
111 |
| { |
112 |
3908
| return null;
|
113 |
| } |
114 |
| catch (Throwable t) |
115 |
| { |
116 |
0
| throw new ApplicationRuntimeException(ImplMessages.unableToLoadClass(type, _loader, t),
|
117 |
| t); |
118 |
| } |
119 |
| |
120 |
| } |
121 |
| |
122 |
127
| public ClassLoader getClassLoader()
|
123 |
| { |
124 |
127
| return _loader;
|
125 |
| } |
126 |
| |
127 |
| } |