|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object ix.util.reflect.ClassFinder
public class 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.
A ClassFinder may use a different naming convention than Java provided that there are String-to-String mappings in both directions between any special "external" names and ordinary Java names.
This class does not yet handle array classes.
Nested 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()
|
|
ClassFinder(ClassFinder base)
|
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. |
protected void |
cacheBothWays(java.lang.String name,
java.lang.Class c)
Caches the mapping from name to class and from class to name. |
java.lang.Class |
classForName(java.lang.String name)
Returns the class that corresponds to the name, as determined by any imports or explicit mappings. |
protected boolean |
classHasShortName(java.lang.Class c,
java.lang.String shortExternal)
|
protected static void |
do_main(ClassFinder cf)
A test loop that asks the user for a name and prints the corresponding class (or else null) as determined by the ClassFinder. |
java.lang.String |
externalFieldName(java.lang.String javaName)
Returns the external name that corresponds to a Java field name. |
java.lang.String |
externalName(java.lang.String javaName)
Returns the external name that corresponds to a Java class name. |
protected java.lang.Class |
findImportClass(java.lang.String name)
Tries to find a class by asking each import in turn. |
java.lang.String |
javaFieldName(java.lang.String externalName)
Returns the Java name that corresponds to an external field name. |
java.lang.String |
javaName(java.lang.String externalName)
Returns the Java name that corresponds to an external class name. |
static void |
main(java.lang.String[] argv)
Simple main program for testing. |
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. |
void |
preLoad(java.util.List expectedClasses)
|
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 |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
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()
public ClassFinder(ClassFinder base)
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)
name
- an external name for a class.c
- a classprotected void cacheBothWays(java.lang.String name, java.lang.Class c)
public void preLoad(java.util.List expectedClasses)
public java.lang.String javaName(java.lang.String externalName)
public java.lang.String javaFieldName(java.lang.String externalName)
javaName(String)
, but it may be overridden in subclasses
in which the conversion for class names cannot be used for fields.
public java.lang.String externalName(java.lang.String javaName)
public java.lang.String externalFieldName(java.lang.String javaName)
externalName(String)
,
but it may be overridden in subclasses in which the conversion
for class names cannot be used for fields.
public java.lang.Class classForName(java.lang.String name)
cacheBothWays(String, Class)
for an explanation.)
name
- an external name for a class.
protected java.lang.Class findImportClass(java.lang.String name)
name
- a Java name for a class.
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.
name
- a Java name for a class.
public java.lang.String nameForClass(java.lang.Class c)
cacheBothWays(String, Class)
protected boolean classHasShortName(java.lang.Class c, java.lang.String shortExternal)
public static void main(java.lang.String[] argv)
do_main(ClassFinder)
with an instance of
this class as the finder.
protected static void do_main(ClassFinder cf)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |