1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.geekologue.md4j.util;
18
19 /***
20 * Class Utilities
21 *
22 * @author manos
23 *
24 */
25 public class ClassUtils {
26 /***
27 * Create a new object instance given a class name
28 *
29 * @param name
30 * The class name
31 * @return A new instance
32 * @exception Exception
33 * In case an instantiation error occurs
34 */
35 public static Object newInstance(String name) throws Exception {
36 return ClassUtils.loadClass(name).newInstance();
37 }
38
39 /***
40 * Load a class given a class name its name
41 *
42 * @param name
43 * The class name
44 * @return The class with the given name
45 * @exception ClassNotFoundException
46 * If the class cannot be loaded
47 */
48 public static Class loadClass(String className)
49 throws ClassNotFoundException {
50 return ClassUtils.getClassLoader().loadClass(className);
51 }
52
53 /***
54 * get the context classloader from the current thread
55 *
56 * @return The context classloader for the current thread
57 */
58 public static ClassLoader getClassLoader() {
59 return ClassUtils.class.getClassLoader();
60 }
61 }