sam.toolkit
Class ClassRegistry

java.lang.Object
  |
  +--sam.toolkit.ClassRegistry
Direct Known Subclasses:
NamedClassRegistry

public class ClassRegistry
extends java.lang.Object

General-purpose Class registry This serves as both a registry and a factory. This class allows a user to a specific sub-class of a certain base type under a given name, and later instantiate it based on that name.


Constructor Summary
ClassRegistry()
          Builds a new ClassRegistry
ClassRegistry(java.lang.Class baseType)
          Builds a new ClassRegistry
ClassRegistry(java.lang.Class baseType, java.lang.String description)
          Builds a new ClassRegistry
ClassRegistry(java.lang.String description)
          Builds a new ClassRegistry
 
Method Summary
protected  java.lang.Object build(java.lang.String name)
          Instantiates a new target registered as name Note that dynamic casting to baseType is guaranteed to be successfull.
 java.lang.Object get()
          Gets the current user interface.
 java.lang.Object get(java.lang.String name)
          Sets and gets specified user interface.
 boolean isSet()
          Wether any target has ever been set.
 java.lang.String name()
          Gets the name of the gurrent target
 boolean register(java.lang.Class target, java.lang.String name)
          Registers a new target as name
 java.lang.String[] registeredTargets()
          Gets the list of all registered objects
 void reset()
          Resets the current target.
 boolean set(java.lang.String name)
          Sets name as the current target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassRegistry

public ClassRegistry()
Builds a new ClassRegistry


ClassRegistry

public ClassRegistry(java.lang.Class baseType)
Builds a new ClassRegistry

Parameters:
baseType - the base type of all instantiated targets

ClassRegistry

public ClassRegistry(java.lang.String description)
Builds a new ClassRegistry

Parameters:
description - the human-readable name of all instantiated targets

ClassRegistry

public ClassRegistry(java.lang.Class baseType,
                     java.lang.String description)
Builds a new ClassRegistry

Parameters:
baseType - the base type of all instantiated targets
description - the human-readable name of all instantiated targets
Method Detail

set

public boolean set(java.lang.String name)
Sets name as the current target.

Returns:
true iff name is already registered

isSet

public boolean isSet()
Wether any target has ever been set.

See Also:
set(java.lang.String)

name

public java.lang.String name()
Gets the name of the gurrent target

Returns:
"" if no target is currently set
See Also:
set(java.lang.String), isSet()

register

public boolean register(java.lang.Class target,
                        java.lang.String name)
                 throws java.lang.ClassCastException
Registers a new target as name

Returns:
true iff the registration was successfull. This is the case iff target is a subtype of baseType, its ClassLoader allows introspection and it defines a public no-argument constructor.
java.lang.ClassCastException

registeredTargets

public java.lang.String[] registeredTargets()
Gets the list of all registered objects


build

protected java.lang.Object build(java.lang.String name)
Instantiates a new target registered as name Note that dynamic casting to baseType is guaranteed to be successfull.

Returns:
null if the building failed.

reset

public void reset()
Resets the current target. Subsequent calls to get will thus cause reinstantiation of the target class.


get

public java.lang.Object get()
Gets the current user interface.

Note that instanciation is lazy and occurs only once.

Returns:
the current user interface
See Also:
reset

get

public java.lang.Object get(java.lang.String name)
Sets and gets specified user interface.

Returns:
the specified user interface
See Also:
set, get