iaik.utils
Class Factory
java.lang.Object
|
+--iaik.utils.Factory
- public abstract class Factory
- extends java.lang.Object
This class can be used to manage classes for dynamic instanziation.
|
Field Summary |
protected static java.util.Hashtable |
interfaces
Repository of known interfaces. |
protected static java.util.Hashtable |
singletons
Repository of Singleton instances. |
|
Constructor Summary |
protected |
Factory()
Restrict instantiation to the class itself and subclasses. |
|
Method Summary |
protected abstract java.lang.Object |
create(java.lang.Class implementation)
Creates a new instance of the given class. |
protected java.lang.Object |
create(java.lang.Class iface,
java.lang.Object type,
boolean singleton)
Create an instance using the given interface and type. |
protected void |
register(java.lang.Class iface,
java.lang.Object type,
java.lang.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 |
interfaces
protected static java.util.Hashtable interfaces
- Repository of known interfaces.
singletons
protected static java.util.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.
Factory
protected Factory()
- Restrict instantiation to the class itself and subclasses.
create
protected abstract java.lang.Object create(java.lang.Class implementation)
throws java.lang.InstantiationException,
java.lang.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:
- java.lang.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.
- java.lang.IllegalAccessException - if an attempt was made to instantiate a of a foreign
package not supporting foreign instantiation
create
protected java.lang.Object create(java.lang.Class iface,
java.lang.Object type,
boolean singleton)
throws java.lang.InstantiationException
- Create an instance using the given interface and type.
- Parameters:
iface - the desired interface class the type belongs totype - an object denoting indirectly which concrete
class should be used when instantiatingsingleton - boolean denoting weather a shared instance
should be used- Returns:
- the newly created, uninitialized instance
- Throws:
- java.lang.InstantiationException - if new instance couldn't be created
register
protected void register(java.lang.Class iface,
java.lang.Object type,
java.lang.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 totype - an Object used to distinguish the different implementationsimplementation - The implementation class being registered