iaik.utils
Class Factory

java.lang.Object
  |
  +--iaik.utils.Factory

public abstract class Factory
extends Object

This class can be used to manage classes for dynamic instanziation.

Version:
File Revision 14

Field Summary
protected static Hashtable interfaces
          Repository of known interfaces.
protected static Hashtable singletons
          Repository of Singleton instances.
 
Constructor Summary
protected Factory()
          Restrict instantiation to the class itself and subclasses.
 
Method Summary
protected abstract  Object create(Class implementation)
          Creates a new instance of the given class.
protected  Object create(Class iface, Object type, boolean singleton)
          Create an instance using the given interface and type.
protected  void register(Class iface, Object type, Class implementation)
          Register a class to implement one type of a specific interface.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

interfaces

protected static Hashtable interfaces
Repository of known interfaces.

singletons

protected static Hashtable singletons
Repository of Singleton instances. Some concrete classes desire that only one instance of them is ever created, and that instance is always returned when asked.
Constructor Detail

Factory

protected Factory()
Restrict instantiation to the class itself and subclasses.
Method Detail

create

protected abstract Object create(Class implementation)
                          throws InstantiationException,
                                 IllegalAccessException
Creates a new instance of the given class. This method must be implemented by a subclass in order to behave with Java package protection. In most cases it is a call like implementation.newInstance().
Parameters:
implementation - the implementation class to be instantiated
Throws:
InstantiationException - Thrown when an application tries to create an instance of a class using the newInstance method in class Class, but the specified class object cannot be instantiated because it is an interface or is an abstract class.
IllegalAccessException - if an attempt was made to instantiate a of a foreign package not supporting foreign instantiation

create

protected Object create(Class iface,
                        Object type,
                        boolean singleton)
                 throws InstantiationException
Create an instance using the given interface and type.
Parameters:
iface - the desired interface class the type belongs to
type - an object denoting indirectly which concrete class should be used when instantiating
singleton - boolean denoting weather a shared instance should be used
Returns:
the newly created, uninitialized instance
Throws:
InstantiationException - if new instance couldn't be created

register

protected void register(Class iface,
                        Object type,
                        Class implementation)
Register a class to implement one type of a specific interface. The object which denotes the type has to overwrite method int hashCode() from java.lang.Object to use it with Hashtables.
Parameters:
iface - the desired interface class the type belongs to
type - an Object used to distinguish the different implementations
implementation - The implementation class being registered

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK