|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--sam.toolkit.ClassRegistry
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 |
public ClassRegistry()
ClassRegistry
public ClassRegistry(java.lang.Class baseType)
ClassRegistry
baseType
- the base type of all instantiated targetspublic ClassRegistry(java.lang.String description)
ClassRegistry
description
- the human-readable name of all instantiated targetspublic ClassRegistry(java.lang.Class baseType, java.lang.String description)
ClassRegistry
baseType
- the base type of all instantiated targetsdescription
- the human-readable name of all instantiated targetsMethod Detail |
public boolean set(java.lang.String name)
name
as the current target.
true
iff name
is already registeredpublic boolean isSet()
set(java.lang.String)
public java.lang.String name()
""
if no target is currently setset(java.lang.String)
,
isSet()
public boolean register(java.lang.Class target, java.lang.String name) throws java.lang.ClassCastException
name
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
public java.lang.String[] registeredTargets()
protected java.lang.Object build(java.lang.String name)
name
Note that dynamic casting to baseType
is guaranteed to be successfull.
null
if the building failed.public void reset()
get
will thus cause reinstantiation of the target class.
public java.lang.Object get()
Note that instanciation is lazy and occurs only once.
reset
public java.lang.Object get(java.lang.String name)
set
,
get
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |