Jacson

de.spieleck.util
Class FastClassForName

java.lang.Object
  extended byde.spieleck.util.FastClassForName

public class FastClassForName
extends java.lang.Object

This is a replacement for Class.forName(...).newInstance().

It is fast. In my bench it is much faster than the latter construct. Efficient caching and loading mechanism to obtain classes with a default constructor in the current ContextClassLoader.

It treats some classloader intricaties.

Version:
0
Author:
fsn

Field Summary
protected static java.util.HashMap classCache
          Keep track of all classes aquired for faster second access.
 
Method Summary
static java.lang.Class contextClassForName(java.lang.String className, java.lang.Class context)
          Try to load a class from the right contextual classloader.
static java.lang.Class lookupClass(java.lang.String className, java.lang.String defaultPackage, java.lang.Class context)
          Lookup the class, first in cache, then try loading it from context with two trials on the classname.
static java.lang.Object newInstance(java.lang.String className, java.lang.Class require)
           
static java.lang.Object newInstance(java.lang.String className, java.lang.String defaultPackage, java.lang.Class require)
           
static java.lang.Object newInstance(java.lang.String className, java.lang.String defaultPackage, java.lang.Class require, java.lang.Class context)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classCache

protected static java.util.HashMap classCache
Keep track of all classes aquired for faster second access.

Method Detail

newInstance

public static java.lang.Object newInstance(java.lang.String className,
                                           java.lang.Class require)

newInstance

public static java.lang.Object newInstance(java.lang.String className,
                                           java.lang.String defaultPackage,
                                           java.lang.Class require)

newInstance

public static java.lang.Object newInstance(java.lang.String className,
                                           java.lang.String defaultPackage,
                                           java.lang.Class require,
                                           java.lang.Class context)

lookupClass

public static java.lang.Class lookupClass(java.lang.String className,
                                          java.lang.String defaultPackage,
                                          java.lang.Class context)
Lookup the class, first in cache, then try loading it from context with two trials on the classname.


contextClassForName

public static java.lang.Class contextClassForName(java.lang.String className,
                                                  java.lang.Class context)
                                           throws java.lang.ClassNotFoundException
Try to load a class from the right contextual classloader. The right classloader can be somewhat strange in an Ant or Servlet context.

Throws:
java.lang.ClassNotFoundException

Spieleck

Copyleft 2002 spieleck.de.