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
  • Constructor Details

    • PrototypeFactory

      public PrototypeFactory()
  • Method Details

    • 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.