|
1
|
|
/* Generated by AspectJ version 1.0.5 */
|
|
2
|
|
package org.apache.cactus.util;
|
|
3
|
|
import java.util.ResourceBundle;
|
|
4
|
|
import java.util.PropertyResourceBundle;
|
|
5
|
|
import java.util.MissingResourceException;
|
|
6
|
|
import java.util.Locale;
|
|
7
|
|
|
|
8
|
|
/**
|
|
9
|
|
* Utiliy methods related to class loading in a webapp environment.
|
|
10
|
|
*
|
|
11
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
|
12
|
|
*
|
|
13
|
|
* @version $Id: ClassLoaderUtils.java,v 1.2.6.1 2002/08/31 14:43:40 vmassol Exp $
|
|
14
|
|
*/
|
|
15
|
|
public class ClassLoaderUtils {
|
|
16
|
|
/**
|
|
17
|
|
* Try loading a class first by using the context class loader or by using
|
|
18
|
|
* the classloader of the referrer class if the context classloader failed
|
|
19
|
|
* to load the class.
|
|
20
|
|
*
|
|
21
|
|
* @param theClassName the name of the test class
|
|
22
|
|
* @param theReferrer the class will be loaded using the classloader which
|
|
23
|
|
* has loaded this referrer class
|
|
24
|
|
* @return the class object the test class to call
|
|
25
|
|
* @exception ClassNotFoundException if the class cannot be loaded through
|
|
26
|
|
* either classloader
|
|
27
|
|
*/
|
|
28
|
427
|
public static Class loadClass(String theClassName,
|
|
29
|
|
Class theReferrer) throws ClassNotFoundException {
|
|
30
|
427
|
Class clazz = null;
|
|
31
|
427
|
try {
|
|
32
|
427
|
clazz = ClassLoaderUtils.loadClassFromWebappClassLoader(theClassName, theReferrer);
|
|
33
|
|
} catch (Exception internalException) {
|
|
34
|
0
|
clazz = ClassLoaderUtils.loadClassFromContextClassLoader(theClassName);
|
|
35
|
|
}
|
|
36
|
427
|
return clazz;
|
|
37
|
|
}
|
|
38
|
|
|
|
39
|
|
/**
|
|
40
|
|
* Try loading class using the Context class loader.
|
|
41
|
|
*
|
|
42
|
|
* @param theClassName the class to load
|
|
43
|
|
* @return the <code>Class</code> object for the class to load
|
|
44
|
|
* @exception ClassNotFoundException if the class cannot be loaded through
|
|
45
|
|
* this class loader
|
|
46
|
|
*/
|
|
47
|
0
|
public static Class loadClassFromContextClassLoader(String theClassName) throws
|
|
48
|
|
ClassNotFoundException {
|
|
49
|
0
|
return Class.forName(theClassName, true, Thread.currentThread().getContextClassLoader());
|
|
50
|
|
}
|
|
51
|
|
|
|
52
|
|
/**
|
|
53
|
|
* Try loading class using the Webapp class loader.
|
|
54
|
|
*
|
|
55
|
|
* @param theClassName the class to load
|
|
56
|
|
* @param theReferrer the class will be loaded using the classloader which
|
|
57
|
|
* has loaded this referrer class
|
|
58
|
|
* @return the <code>Class</code> object for the class to load
|
|
59
|
|
* @exception ClassNotFoundException if the class cannot be loaded through
|
|
60
|
|
* this class loader
|
|
61
|
|
*/
|
|
62
|
427
|
public static Class loadClassFromWebappClassLoader(String theClassName,
|
|
63
|
|
Class theReferrer) throws ClassNotFoundException {
|
|
64
|
427
|
return Class.forName(theClassName, true, theReferrer.getClassLoader());
|
|
65
|
|
}
|
|
66
|
|
|
|
67
|
|
/**
|
|
68
|
|
* Try loading a resource bundle from either the context class loader or
|
|
69
|
|
* the
|
|
70
|
|
*
|
|
71
|
|
* @param theName the resource bundle name
|
|
72
|
|
* @param theReferrer the resource bundle will be loaded using the
|
|
73
|
|
* classloader which has loaded this referrer class
|
|
74
|
|
* @return the loaded resource bundle
|
|
75
|
|
*/
|
|
76
|
14
|
public static ResourceBundle loadPropertyResourceBundle(String theName, Class theReferrer) {
|
|
77
|
14
|
ResourceBundle bundle;
|
|
78
|
14
|
try {
|
|
79
|
14
|
if (theReferrer.getClassLoader() == null) {
|
|
80
|
0
|
bundle = PropertyResourceBundle.getBundle(theName, Locale.getDefault());
|
|
81
|
|
} else {
|
|
82
|
14
|
bundle = PropertyResourceBundle.getBundle(theName, Locale.getDefault(),
|
|
83
|
|
theReferrer.getClassLoader());
|
|
84
|
|
}
|
|
85
|
|
} catch (MissingResourceException e) {
|
|
86
|
0
|
bundle = PropertyResourceBundle.getBundle(theName, Locale.getDefault(),
|
|
87
|
|
Thread.currentThread().getContextClassLoader());
|
|
88
|
|
}
|
|
89
|
14
|
return bundle;
|
|
90
|
|
}
|
|
91
|
|
|
|
92
|
|
/**
|
|
93
|
|
* Utiliy methods related to class loading in a webapp environment.
|
|
94
|
|
*
|
|
95
|
|
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
|
|
96
|
|
*
|
|
97
|
|
* @version $Id: ClassLoaderUtils.java,v 1.2.6.1 2002/08/31 14:43:40 vmassol Exp $
|
|
98
|
|
*/
|
|
99
|
0
|
public ClassLoaderUtils() {
|
|
100
|
0
|
super();
|
|
101
|
|
}
|
|
102
|
|
}
|