|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectuk.ac.starlink.util.ObjectFactory
Manages dynamic creation of objects from a known set of classes. An ObjectFactory keeps a list of classes with associated nicknames; the idea is that you can obtain an instance of a given class by supplying the nickname in question. Instead of a nickname you can use the fully qualified classname, whether or not it has previously been registered. Any class registered must be a subclass of the superclass specified when this factory is constructed, and must have a no-arg constructor.
Constructor Summary | |
ObjectFactory(Class clazz)
Constructor. |
Method Summary | |
Object |
createObject(String name)
Constructs and returns an object from one of the classes registered with this factory. |
String[] |
getNickNames()
Returns a list of the nicknames which have been registered. |
boolean |
isRegistered(String name)
Indicates whether this factory knows about a given name. |
void |
register(String nickName,
String className)
Registers a class with its nickname. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public ObjectFactory(Class clazz)
clazz
- type which must be a supertype of any class registered
with this factoryMethod Detail |
public void register(String nickName, String className)
nickName
- nicknameclassName
- fully-qualified class namepublic String[] getNickNames()
public boolean isRegistered(String name)
name
- name
name
can sensibly be passed to
createObject(java.lang.String)
public Object createObject(String name) throws LoadException
name
- classname/nickname of class to instantiate
LoadException
- if the load fails for unsurprising reasons
|
Copyright © 2004 CLRC: Central Laboratory of the Research Councils. All rights reserved. | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |