|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object | +--ix.util.ClassFinder
Converts between class names (Strings) and classes. Note that a single ClassFinder maps in both directions to make it easier to create mappings that are consistent.
Explicit mappings and "imports" may be specified; otherwise fully qualified names must be used.
Primitive types such as byte, boolean,
and int are matched with the corresponding TYPE
classes Byte.TYPE, Boolean.TYPE, etc.
This class does not yet handle array classes.
| Inner Class Summary | |
protected static class |
ClassFinder.Import
Internal class that performs the name-to-class mapping that corresponds to a single import specification. |
| Field Summary | |
protected java.util.Map |
classToName
|
protected java.util.Map |
classToNameCache
|
protected java.util.List |
imports
|
protected java.util.Map |
nameToClass
|
protected java.util.Map |
nameToClassCache
|
| Constructor Summary | |
ClassFinder()
|
|
| Method Summary | |
void |
addImport(java.lang.String name)
Records an import that allows a class name or names to be used without package-qualification. |
protected void |
addInitialImports()
Adds the initial set of imports. |
protected void |
addInitialNames()
Adds the initial set of name mappings. |
void |
addName(java.lang.String name,
java.lang.Class c)
Adds an explicit mapping in both directions between a name and a class. |
java.lang.Class |
classForName(java.lang.String name)
Returns the class that corresponds to the name, as determined by any explicit mappings and imports. |
protected java.lang.Class |
findImportClass(java.lang.String name)
Tries to find a class by asking each import in turn. |
static void |
main(java.lang.String[] argv)
A test loop that asks the user for a name and prints the corresponding class (or else null) as determined by a plain ClassFinder. |
java.lang.String |
nameForClass(java.lang.Class c)
Returns the best name that this ClassFinder would map to the specified class, where a plain class name counts as better than a package-qualified one. |
static java.lang.Class |
tryClassForName(java.lang.String name)
Like Class.forName(String) but returns null
if the class cannot be found. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
protected java.util.List imports
protected java.util.Map nameToClass
protected java.util.Map classToName
protected java.util.Map nameToClassCache
protected java.util.Map classToNameCache
| Constructor Detail |
public ClassFinder()
| Method Detail |
protected void addInitialNames()
protected void addInitialImports()
java.lang.* java.util.*
public void addImport(java.lang.String name)
import statement.
public void addName(java.lang.String name,
java.lang.Class c)
public java.lang.Class classForName(java.lang.String name)
protected java.lang.Class findImportClass(java.lang.String name)
java.lang.RuntimeException - if more than one import can find a class.public static java.lang.Class tryClassForName(java.lang.String name)
Class.forName(String) but returns null
if the class cannot be found.public java.lang.String nameForClass(java.lang.Class c)
public static void main(java.lang.String[] argv)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||