fdda.utils
Class ObjectCache

java.lang.Object
  |
  +--fdda.utils.ObjectCache

public class ObjectCache
extends Object

The instance of this class (Singleton) caches instances of the classes that have to be loaded dynamically (via Class.forName()). The loaded class itself is also cached, in case of the need for several new instances. The cache is not thread-safe.

Author:
Jörg Rüdenauer
See Also:
Class

Constructor Summary
protected ObjectCache()
          The default constructor.
 
Method Summary
static ObjectCache getInstance()
          Returns the instance of ObjectCache (Singleton-Pattern).
 Object getObject(String className)
          Returns an instance of a dynamically loaded class.
 Class loadClass(String className)
          Loads a class dynamically, if it isn't cached.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ObjectCache

protected ObjectCache()
The default constructor.

Method Detail

getInstance

public static ObjectCache getInstance()
Returns the instance of ObjectCache (Singleton-Pattern).

Returns:
the single instance of the class.

loadClass

public final Class loadClass(String className)
                      throws ClassNotFoundException
Loads a class dynamically, if it isn't cached. If it is cached (i.e., was already loaded once), the cached class is returned.

Parameters:
className - the name of the class
Returns:
the loaded class
Throws:
ClassNotFoundException - if the class doesn't exist in the CLASSPATH

getObject

public final Object getObject(String className)
                       throws ClassNotFoundException,
                              InstantiationException,
                              IllegalAccessException
Returns an instance of a dynamically loaded class. If an instance of the class is cached, the cached instance is returned; otherwise, a new instance is created and cached. That means that this method should only be used for classes that are used Singleton-like in the application. The class must have a public constructor without parameters.

Parameters:
className - the name of the class
Returns:
an instance of the class - may already be used!
Throws:
ClassNotFoundException - if the class doesn't exist in the CLASSPATH
InstantiationException - if no instance of the class can be created
IllegalAccessException - if no default constructor is available


API documentation for FDDA version 0.9. Generated on 17/02/2004 14:12.