com.dyuproject.util
Class ClassLoaderUtil

java.lang.Object
  extended by com.dyuproject.util.ClassLoaderUtil

public final class ClassLoaderUtil
extends Object

ClassLoader util for loading classes and finding resources. No checked exceptions.

Author:
David Yu
Date created:
Jan 20, 2009

Constructor Summary
ClassLoaderUtil()
           
 
Method Summary
static URL getResource(String resource, Class<?> context)
          Loads a URL resource from the classloader; If not found, the classloader of the context class specified will be used.
static URL getResource(String resource, Class<?> context, boolean checkParent)
          Loads a URL resource from the classloader; If not found, the classloader of the context class specified will be used.
static Class<?> loadClass(String className, Class<?> context)
          Loads a class from the classloader; If not found, the classloader of the context class specified will be used.
static Class<?> loadClass(String className, Class<?> context, boolean checkParent)
          Loads a class from the classloader; If not found, the classloader of the context class specified will be used.
static
<T> T
newInstance(String className, Class<?> context)
          Instantiates an object using its default constructor if the className is found in the classpath and loaded.
static
<T> T
newInstance(String className, Class<?> context, boolean checkParent)
          Instantiates an object using its default constructor if the className is found in the classpath and loaded.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLoaderUtil

public ClassLoaderUtil()
Method Detail

loadClass

public static Class<?> loadClass(String className,
                                 Class<?> context)
Loads a class from the classloader; If not found, the classloader of the context class specified will be used.


loadClass

public static Class<?> loadClass(String className,
                                 Class<?> context,
                                 boolean checkParent)
Loads a class from the classloader; If not found, the classloader of the context class specified will be used. If the flag checkParent is true, the classloader's parent is included in the lookup.


newInstance

public static <T> T newInstance(String className,
                                Class<?> context)
                     throws Exception
Instantiates an object using its default constructor if the className is found in the classpath and loaded.

Throws:
Exception

newInstance

public static <T> T newInstance(String className,
                                Class<?> context,
                                boolean checkParent)
                     throws Exception
Instantiates an object using its default constructor if the className is found in the classpath and loaded.

Throws:
Exception

getResource

public static URL getResource(String resource,
                              Class<?> context)
Loads a URL resource from the classloader; If not found, the classloader of the context class specified will be used.


getResource

public static URL getResource(String resource,
                              Class<?> context,
                              boolean checkParent)
Loads a URL resource from the classloader; If not found, the classloader of the context class specified will be used. If the flag checkParent is true, the classloader's parent is included in the lookup.



Copyright © 2008-2013. All Rights Reserved.