org.apache.openjpa.persistence.jest
Class PrototypeFactory<K,T>
java.lang.Object
org.apache.openjpa.persistence.jest.PrototypeFactory<K,T>
public class PrototypeFactory<K,T>
- extends Object
A factory for a specific type of objects registered by a key.
The client registers a type indexed by name.
The client can get a new instance of the registered type.
The requested registered type not necessarily have to have a no-arg
constructor. The constructor arguments can be passed during
new instance
request. Based on the
arguments, a matching constructor, if any, is located and invoked.
type of key for this registry
base type of the objects to construct
- Author:
- Pinaki Poddar
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PrototypeFactory
public PrototypeFactory()
register
public void register(K key,
Class<? extends T> prototype)
- Register the given class with the given key.
- Parameters:
key
- a non-null key.prototype
- a type.
newInstance
public T newInstance(K key,
Object... args)
- Create a new instance of the type registered before
with the given key, if any.
The given arguments are used to identify a constructor of the registered type and
passed to the constructor of the registered type.
- Parameters:
key
- a key to identify a registered type.args
- arguments to pass to the constructor of the type.
- Returns:
- null if no type has been registered against the given key.
getRegisteredKeys
public Set<K> getRegisteredKeys()
- Gets the keys registered in this factory.
- Returns:
- immutable set of registered keys.
Copyright © 2006–2015 Apache Software Foundation. All rights reserved.