1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.myfaces.orchestra.lib;
20
21 /***
22 * <p>
23 * Internal helper class for some class management.
24 * </p>
25 * <p>
26 * <b>Not for use outside of Orchestra</b>
27 * </p>
28 */
29 public final class _ClassUtils
30 {
31 private _ClassUtils()
32 {
33 }
34
35 /***
36 * create a new instance for a class by its name
37 */
38 public static Object newInstance(String className)
39 {
40 try
41 {
42 Class clazz = classForName(className);
43 return clazz.newInstance();
44 }
45 catch(NoClassDefFoundError e)
46 {
47 throw new OrchestraException(e);
48 }
49 catch (InstantiationException e)
50 {
51 throw new OrchestraException(e);
52 }
53 catch (IllegalAccessException e)
54 {
55 throw new OrchestraException(e);
56 }
57 catch (ClassNotFoundException e)
58 {
59 throw new OrchestraException(e);
60 }
61 }
62
63 /***
64 * Lookup class using the webapp classloader first and the the classloader which loaded
65 * this class.
66 */
67 public static Class classForName(String className) throws ClassNotFoundException
68 {
69 if (className == null)
70 {
71 throw new NullPointerException("className");
72 }
73
74 try
75 {
76
77 return Class.forName(className,
78 false,
79 Thread.currentThread().getContextClassLoader());
80 }
81 catch (ClassNotFoundException ignore)
82 {
83
84 return Class.forName(className,
85 false,
86 _ClassUtils.class.getClassLoader());
87 }
88 }
89 }