View Javadoc

1   /*
2    * Copyright Emmanouil Batsis
3    * 
4    * Licensed under the GNU General Public License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.gnu.org/licenses/gpl.txt
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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();// Thread.currentThread().getContextClassLoader();
60      }
61  }