ca.nengo.config
Class ClassRegistry

java.lang.Object
  extended by ca.nengo.config.ClassRegistry

public final class ClassRegistry
extends java.lang.Object

A registry of implementations of selected types of interest (subclasses and interface implementations). TODO: unit tests

Author:
Bryan Tripp

Field Summary
static java.lang.String IMPLS_LOCATION_PROPERTY
           
static java.lang.String TYPES_LOCATION_PROPERTY
           
 
Method Summary
 void addHierarchy(java.lang.Class<?> type)
          As addRegisterableType(Class), but ancestors are added as well.
 void addRegisterableType(java.lang.Class<?> type)
          Adds a class to the list of types whose implementations can be registered (only implementations of certain types can be registered).
 java.util.List<java.lang.Class<?>> getImplementations(java.lang.Class<?> type)
           
static ClassRegistry getInstance()
           
 java.lang.Class<?>[] getRegisterableTypes()
           
 void register(java.lang.Class<?> implementation)
          Registers an implementation against any of the registerable types which it is assignable from.
 void register(java.util.jar.JarFile jar)
          Registers public, non-abstract classes in the given Jar.
 void register(java.lang.String implementationName)
          As register(Class), but by name.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TYPES_LOCATION_PROPERTY

public static final java.lang.String TYPES_LOCATION_PROPERTY
See Also:
Constant Field Values

IMPLS_LOCATION_PROPERTY

public static final java.lang.String IMPLS_LOCATION_PROPERTY
See Also:
Constant Field Values
Method Detail

getInstance

public static ClassRegistry getInstance()
Returns:
Shared instance

addHierarchy

public void addHierarchy(java.lang.Class<?> type)
As addRegisterableType(Class), but ancestors are added as well.

Parameters:
type - Type at bottom of hierarchy

addRegisterableType

public void addRegisterableType(java.lang.Class<?> type)
Adds a class to the list of types whose implementations can be registered (only implementations of certain types can be registered).

Parameters:
type - Type to add to list of registerable types

getRegisterableTypes

public java.lang.Class<?>[] getRegisterableTypes()
Returns:
The list of types whose implementations can be registered

register

public void register(java.lang.Class<?> implementation)
Registers an implementation against any of the registerable types which it is assignable from.

Parameters:
implementation - Class to register as an implementation of matching registerable types

register

public void register(java.lang.String implementationName)
              throws java.lang.ClassNotFoundException
As register(Class), but by name.

Parameters:
implementationName - Name of implementation to register
Throws:
java.lang.ClassNotFoundException

register

public void register(java.util.jar.JarFile jar)
              throws java.lang.ClassNotFoundException
Registers public, non-abstract classes in the given Jar.

Parameters:
jar - Jar from which to draw classes to register
Throws:
java.lang.ClassNotFoundException

getImplementations

public java.util.List<java.lang.Class<?>> getImplementations(java.lang.Class<?> type)
Parameters:
type - A registerable type
Returns:
A list of registered implementations of the given type (empty if type is unknown)