|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectavrora.util.ClassMap
The ClassMap
is a class that maps short names (i.e. short, lower case strings) to java classes
and can instantiate them. This is useful for dynamic resolution of classes but with a small set of known
defaults that have a short name. If the short name is not in the default set, this class will treat the
short name as a fully qualified Java class name and load it. This class does the requisite checking--that
the class exists, that it can be loaded, that it is of the appropriate type, that it can be instantiated,
etc.
Field Summary | |
protected java.util.HashMap |
classMap
The classMap field is a hash map that maps a string to a Java class. |
protected java.lang.Class |
clazz
The clazz field stores a reference to the Java class of which the objects stored in this
map are instances of. |
protected java.util.HashMap |
objMap
The objMap field is a hash map that maps a string to an instance of a particular class,
i.e. an object. |
protected java.lang.String |
type
The type field stores a string that represents the name of the "type" that this map
contains. |
Constructor Summary | |
ClassMap(java.lang.String t,
java.lang.Class clz)
The constructor for the ClassMap class creates a new class map with the specified type,
which maps strings to instances of the specified class. |
Method Summary | |
void |
addClass(java.lang.String alias,
java.lang.Class clz)
The addClass() method adds a short name (alias) for the specified class to the set of
default class names. |
void |
addInstance(java.lang.String alias,
java.lang.Object o)
The addInstance() method adds a mapping between a short name (alias) and an object that is
the instance of the class represented by that short name. |
java.lang.Class |
getClass(java.lang.String shortName)
The getClass() method gets the Java class representing the class returned for a given
short name. |
java.util.Iterator |
getIterator()
The getIterator() method returns an interator over all of the key values (short
names or aliases) of this class map. |
java.lang.Object |
getObjectOfClass(java.lang.String name)
The getObjectOfClass() method looks up the string name of the class in the alias map
first, and if not found, attempts to load the class using Class.forName() and instantiates
one object. |
java.util.List |
getSortedList()
The getSortedList() method returns a sorted list of the short names (aliases) stored in
this class map. |
java.util.Iterator |
iterator()
The iterator() method returns an interator over the short names (aliases) stored in this
map. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected final java.lang.String type
type
field stores a string that represents the name of the "type" that this map
contains. For example, a class map for actions might be called "Action" and for input formats might be
called "Input Format".
protected final java.lang.Class clazz
clazz
field stores a reference to the Java class of which the objects stored in this
map are instances of.
protected final java.util.HashMap classMap
classMap
field is a hash map that maps a string to a Java class.
protected final java.util.HashMap objMap
objMap
field is a hash map that maps a string to an instance of a particular class,
i.e. an object.
Constructor Detail |
public ClassMap(java.lang.String t, java.lang.Class clz)
ClassMap
class creates a new class map with the specified type,
which maps strings to instances of the specified class.
t
- the name of the type of this class as a stringclz
- the class which objects should be instances ofMethod Detail |
public void addClass(java.lang.String alias, java.lang.Class clz)
addClass()
method adds a short name (alias) for the specified class to the set of
default class names.
alias
- the string representation of the alias of the classclz
- the class to which the alias mapspublic void addInstance(java.lang.String alias, java.lang.Object o)
addInstance()
method adds a mapping between a short name (alias) and an object that is
the instance of the class represented by that short name.
alias
- the alias for the instanceo
- the actual object that will be returned from getObjectOfClass()
when the
parameters is equal to the alias.public java.lang.Class getClass(java.lang.String shortName)
getClass()
method gets the Java class representing the class returned for a given
short name. If there is no short name (alias) for the passed argument, this method will assume that the
parameter is the fully qualified name of a class. It will then load that class and instantiate an
instance of that class. That instance will be returned in subsequent calls to
getObjectOfClass()
.
shortName
- the short name of the class
public java.lang.Object getObjectOfClass(java.lang.String name)
getObjectOfClass()
method looks up the string name of the class in the alias map
first, and if not found, attempts to load the class using Class.forName()
and instantiates
one object.
name
- the name of the class or alias
Avrora.Error
- if there is a problem finding or instantiating the classpublic java.util.List getSortedList()
getSortedList()
method returns a sorted list of the short names (aliases) stored in
this class map.
public java.util.Iterator getIterator()
getIterator()
method returns an interator over all of the key values (short
names or aliases) of this class map.
public java.util.Iterator iterator()
iterator()
method returns an interator over the short names (aliases) stored in this
map.
java.util.Iterator
which can be used to iterate over each alias in
this map.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |