ehcache

net.sf.ehcache.util
Class ClassLoaderUtil

java.lang.Object
  extended by net.sf.ehcache.util.ClassLoaderUtil

public final class ClassLoaderUtil
extends Object

Keeps all classloading in ehcache consistent.

Version:
$Id: ClassLoaderUtil.java 5594 2012-05-07 16:04:31Z cdennis $
Author:
Greg Luck

Method Summary
static Object createNewInstance(String className)
          Creates a new class instance.
static Object createNewInstance(String className, Class[] argTypes, Object[] args)
          Creates a new class instance and passes args to the constructor call.
static ClassLoader getFallbackClassLoader()
          Gets a fallback ClassLoader that all classes in ehcache, and extensions, should use for classloading.
static ClassLoader getStandardClassLoader()
          Gets the ClassLoader that all classes in ehcache, and extensions, should use for classloading.
static Class loadClass(String className)
          Load the given class by name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getStandardClassLoader

public static ClassLoader getStandardClassLoader()
Gets the ClassLoader that all classes in ehcache, and extensions, should use for classloading. All ClassLoading in ehcache should use this one. This is the only thing that seems to work for all of the class loading situations found in the wild.

Returns:
the thread context class loader.

getFallbackClassLoader

public static ClassLoader getFallbackClassLoader()
Gets a fallback ClassLoader that all classes in ehcache, and extensions, should use for classloading. This is used if the context class loader does not work.

Returns:
the ClassLoaderUtil.class.getClassLoader();

createNewInstance

public static Object createNewInstance(String className)
                                throws CacheException
Creates a new class instance. Logs errors along the way. Classes are loaded using the ehcache standard classloader.

Parameters:
className - a fully qualified class name
Returns:
the newly created instance
Throws:
CacheException - if instance cannot be created due to a missing class or exception

createNewInstance

public static Object createNewInstance(String className,
                                       Class[] argTypes,
                                       Object[] args)
                                throws CacheException
Creates a new class instance and passes args to the constructor call. Logs errors along the way. Classes are loaded using the ehcache standard classloader.

Parameters:
className - a fully qualified class name
argTypes - Types for constructor argument parameters
args - Values for constructor argument parameters
Returns:
the newly created instance
Throws:
CacheException - if instance cannot be created due to a missing class or exception

loadClass

public static Class loadClass(String className)
                       throws ClassNotFoundException
Load the given class by name

Parameters:
className - a fully qualified class name
Returns:
Class the loaded class
Throws:
ClassNotFoundException - if the class cannot be loaded
Since:
1.7

ehcache

Copyright 2001-2014, Terracotta, Inc.