|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sourceforge.groboutils.util.classes.v1.ClassUtil
Utility class for loading classes and creating instances. It decides
which JDK version to use as the loader. Class instances are put
into a Hashtable, based on URL and classname. When the Java-Doc defines
a jarName, as in getClass( String, String )
, the
jarName may be a filename loadable from the File
class, or a proper URL loadable from the URL
class.
If the jarName does not have a protocol, then it is assumed to
be a file, otherwise, it is used as a URL.
Note that this class is not thread safe. It is assumed that applications will use the ClassUtil only during initialization times, since dynamic class loading can be very expensive. If you need thread safety, then you will need to ensure that either all class loading is done in a single thread, or that your application properly synchronizes the method calls.
Update v0.9.1: the constructor will now check for jdk2 first like before, but now if it is not found, it will try to use jdk0 compatibility - before, it would just fail out. This allows the libraries to be repackaged to contain only the jdk0 classes if so desired.
Field Summary | |
protected static ClassUtil |
s_instance
Subclasses must instantiate themselves in this variable in their static initialization block, and overload the getInstance()
static method. |
Constructor Summary | |
protected |
ClassUtil()
Default constructor - made protected so users won't instantiate the utility |
Method Summary | |
java.lang.Object |
createObject(java.lang.Class c)
Creates an Object from the given Class, using its default constructor. |
java.lang.Object |
createObject(java.lang.String className)
Creates a new instance of the class with the given className using the default constructor. |
java.lang.Object |
createObject(java.lang.String className,
java.lang.String jarName)
Creates a new instance of the class with the given className using the default constructor, from the given URL. |
void |
flush()
Call this to flush out the cache. |
java.lang.Class |
getClass(java.lang.String name)
Either finds or loads from cache the given class, using the default class loader. |
java.lang.Class |
getClass(java.lang.String name,
java.lang.String jarName)
Either finds or loads from cache the given class. |
protected java.lang.String |
getClassHashName(java.lang.String name,
java.lang.String jarName)
Creates the name of the class for the hashtable lookup, which is a junction of the jar name and the class name. |
java.lang.String |
getClassPackage(java.lang.Class c)
Discovers the package name for the given class. |
static ClassUtil |
getInstance()
Retrieve the shared instance of the utility class. |
boolean |
isJdk2Compatible()
Checks if the current JVM version is 1.2 compatible. |
protected java.lang.Class |
loadClass(java.lang.String className,
java.lang.String baseJar)
Attempts to load the class from the current classpath if baseJar is null, or from the appropriate class loader if it is not null. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static ClassUtil s_instance
getInstance()
static method.
Constructor Detail |
protected ClassUtil()
Method Detail |
public static ClassUtil getInstance()
public void flush()
public java.lang.Class getClass(java.lang.String name)
name
- the name of the class to load.
getClass( String, String )
public java.lang.Class getClass(java.lang.String name, java.lang.String jarName)
name
- the name of the class to load.jarName
- the URL to load the class from - it may be null.
getClass( String )
public java.lang.Object createObject(java.lang.String className)
className
- the name of the class to create an instance.
getClass( String )
,
createObject( String, String )
public java.lang.Object createObject(java.lang.String className, java.lang.String jarName)
className
- the name of the class to create an instance.jarName
- the URL to load the class from - it may be null.
getClass( String, String )
,
createObject( String )
public java.lang.Object createObject(java.lang.Class c)
c
- the Class object from which a new instance will be created
using its default constructor.
public boolean isJdk2Compatible()
URLClassLoader
exists
in the classpath, or false otherwise.public java.lang.String getClassPackage(java.lang.Class c)
c
- the class to find the package name.
protected java.lang.String getClassHashName(java.lang.String name, java.lang.String jarName)
name
- the class namejarName
- the jar name - may be null.
protected java.lang.Class loadClass(java.lang.String className, java.lang.String baseJar)
className
- name of the class to loadbaseJar
- the URL file to load the class from - may be
null.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |