public class ObjectFactory
extends java.lang.Object
Factory
but does
not support singletons and does not synchronize on Object creation
because implementing classes are usually registered only once.Constructor and Description |
---|
ObjectFactory()
Creates a new ObjectFactory.
|
ObjectFactory(int size)
Creates a new ObjectFactory with the given repository size.
|
ObjectFactory(int size,
java.lang.Class objectClass)
Creates a new ObjectFactory with the given repository size
for registration of implementation of the given class.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
create(java.lang.Class implementation)
Creates a new instance of the given class.
|
java.lang.Object |
create(java.lang.Object type)
Creates an instance of a class implementing the given type.
|
void |
register(java.lang.Object type,
java.lang.Class implementation)
Registers a class as implementation of the given type.
|
void |
register(java.lang.Object type,
java.lang.String implementationClassName)
Registers a class by its name as implementation of the given type.
|
public ObjectFactory()
public ObjectFactory(int size)
size
- the size of the repositorypublic ObjectFactory(int size, java.lang.Class objectClass)
registration
.size
- the size of the repositoryobjectClass
- the class all registered implementations
have to implementpublic java.lang.Object create(java.lang.Class implementation) throws java.lang.InstantiationException, java.lang.IllegalAccessException
implementation
- the implementation class to be instantiatedjava.lang.InstantiationException
- if the object cannot be instantiatedjava.lang.IllegalAccessException
- if the given class cannot be accessed because it
is not in the same package and not publicpublic java.lang.Object create(java.lang.Object type) throws java.lang.InstantiationException
type
- the type identifying the class to be instantiatedjava.lang.InstantiationException
- if the instance cannot be createdpublic void register(java.lang.Object type, java.lang.Class implementation)
int hashCode()
from java.lang.Object to be used
it with HashMaps.type
- the type identifying the class to be registeredimplementation
- the implementation class to be registeredpublic void register(java.lang.Object type, java.lang.String implementationClassName)
int hashCode()
from java.lang.Object to be used
it with HashMaps.type
- the type identifying the class to be registeredimplementationClassName
- the full qualified name of the implementation class to be registered