uk.ac.soton.ecs.iam.grid.utils
Class ImplementationFactory

java.lang.Object
  extended by uk.ac.soton.ecs.iam.grid.utils.ImplementationFactory

public final class ImplementationFactory
extends Object

Returns the configured class for a given use. The implementationfactory.properties file contains a list of keys (usually interface names) and their corresponding classes. This factory instantiates a new instance of the given class when presented with the given key, or returns an existing instance if one has already been created.


Method Summary
static
<T> T
getSingletonInstance(Class<T> iface)
          Get the singleton instance of the class for this key (interface).
static
<T> T
getSingletonInstance(Class<T> iface, String argument)
          Get the configured class for the given key.
static
<T> T
instantiateObject(Class<T> ifaceClass, Object[] arguments, Class[] types)
          Create a new instance of the configured implementation of 'iface'.
static
<T> void
registerFactory(Class<T> iface, Class factoryClass, String factoryMethod)
          Add an additional interface-to-implementation mappings.
static
<T> void
registerImplementation(Class<T> iface, Class<? extends T> impl)
          Add an additional interface-to-implementation mappings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getSingletonInstance

public static <T> T getSingletonInstance(Class<T> iface)
                              throws CantCreateImplementation
Get the singleton instance of the class for this key (interface). This just calls getSingletonInstance(iface, null)

Throws:
CantCreateImplementation

instantiateObject

public static <T> T instantiateObject(Class<T> ifaceClass,
                                      Object[] arguments,
                                      Class[] types)
                           throws CantCreateImplementation
Create a new instance of the configured implementation of 'iface'. This creates a new copy every time, not a singleton (see getSingletonInstance() for that).

Parameters:
ifaceClass - the class whose name is a key in implementationfactory.properties to be looked up
arguments - arguments to pass to constructor, or null for {}
types - the parameter types to match (may be superclasses of the actual types); pass null to use the types of the parameters
Returns:
a new instance
Throws:
CantCreateImplementation - on error

getSingletonInstance

public static <T> T getSingletonInstance(Class<T> iface,
                                         String argument)
                              throws CantCreateImplementation
Get the configured class for the given key. The key is an interface that the class implements.

Parameters:
iface - the interface which the class implements
argument - a value to be passed to the constructor. If null, no arguments are passed. The factory returns a single instance for each (iface, argument) pair.
Returns:
the new instance.
Throws:
CantCreateImplementation

registerImplementation

public static <T> void registerImplementation(Class<T> iface,
                                              Class<? extends T> impl)
Add an additional interface-to-implementation mappings. This is typically used by plugins.

See Also:
GridClientPluginProvider

registerFactory

public static <T> void registerFactory(Class<T> iface,
                                       Class factoryClass,
                                       String factoryMethod)
Add an additional interface-to-implementation mappings. This is typically used by plugins.

Parameters:
iface - the key which will later be used
factoryClass - a class containing a factory function
factoryMethod - the method in the class that creates the implementations
See Also:
GridClientPluginProvider


Copyright © 2001-2008 University of Southampton IT Innovation Centre. All Rights Reserved.