org.formulacompiler.runtime
Class ImplementationLocator

java.lang.Object
  extended by org.formulacompiler.runtime.ImplementationLocator

public final class ImplementationLocator
extends java.lang.Object

Very simple service locator for AFC. Uses the same mechanism as Java 6's java.util.ServiceLoader to locate implementation classes, that is, files of the desired class's name in "META-INF/services/" containing lines which specify the implementor class names.

It currently does not use java.util.ServiceLoader internally because I do not yet want to assume Java 6.

Author:
peo

Nested Class Summary
static class ImplementationLocator.ConfigurationException
          Exception thrown when configuration errors occur.
static class ImplementationLocator.ConfigurationMissingException
          Exception thrown when a configuration is missing for a single instance request.
 
Constructor Summary
ImplementationLocator()
           
 
Method Summary
static
<T> T
getInstance(java.lang.Class<T> _class)
          Returns a newly constructed instance of the implementor class of the given abstract class or interface.
static
<T> java.util.Collection<T>
getInstances(java.lang.Class<T> _class)
          Like getInstance(Class), but returns a collection of all matching implementations.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImplementationLocator

public ImplementationLocator()
Method Detail

getInstance

public static <T> T getInstance(java.lang.Class<T> _class)
                     throws ImplementationLocator.ConfigurationException,
                            ImplementationLocator.ConfigurationMissingException
Returns a newly constructed instance of the implementor class of the given abstract class or interface. The implementor is looked up in a file with the name "META-INF/services/[class-name]". All non-comment lines should specify fully qualified class names. Comments start with "#".

Type Parameters:
T - is the desired return type.
Parameters:
_class - is the class of the desired return type.
Returns:
an instance of T.
Throws:
ImplementationLocator.ConfigurationException - for all internal declared exceptions, with the cause set to the internal exception.
ImplementationLocator.ConfigurationMissingException - when the configuration file is missing.

getInstances

public static <T> java.util.Collection<T> getInstances(java.lang.Class<T> _class)
                                            throws ImplementationLocator.ConfigurationException
Like getInstance(Class), but returns a collection of all matching implementations.

Type Parameters:
T - is the desired return type.
Parameters:
_class - is the class of the desired return type.
Returns:
a collection of instances of T. Never null, never shared, mutable.
Throws:
ImplementationLocator.ConfigurationException - for all internal declared exceptions, with the cause set to the internal exception.