ix.util.reflect
Class ClassSyntax

java.lang.Object
  extended by ix.util.reflect.ClassSyntax

public class ClassSyntax
extends java.lang.Object

Provides a syntax for objects by acting as a factory for class and field descriptions.

For a class with fields, ClassSyntax provides the information needed to process instances field-by-field. It also embodies decisions about which fields should be accessible in this way, how their values are obtained or set, and the order in which they should be visited.

It also specifies how low-level objects are represented as Strings and which XML Schema datatype they should have.

A ClassFinder is used to map both ways between external names and classes and to map between Java and external names for classes and fields.

See Also:
ClassDescr, FieldDescr, ClassFinder

Field Summary
protected  ClassFinder classFinder
           
protected  java.util.Map<java.lang.Class,ClassDescr> classToDescrCache
           
protected  java.util.Map<java.lang.Class,Stringer> classToStringerMap
           
 
Constructor Summary
ClassSyntax()
           
ClassSyntax(ClassFinder finder)
           
 
Method Summary
 java.lang.Class classForExternalName(java.lang.String externalName)
           
protected  FieldMap collectFieldInfo(java.lang.Class objClass)
           
protected  FieldMap collectFields(java.lang.Class c, FieldMap fields)
          Returns an initial List of FieldDescrs.
protected  void collectRelevantClasses(ClassDescr ftype, java.util.List result, java.util.List tail)
           
protected  void collectRelevantClasses(java.lang.Class c, java.util.List result, java.util.List tail)
           
 void describeClass(java.lang.Class c)
          Prints a description of a class on System.out.
 void describeClass(java.lang.Class c, java.io.PrintStream out)
          Prints a description of a class on the designated PrintStream.
 java.util.List<java.lang.Class> expandRelevantClasses(java.util.List<java.lang.Class> topClasses)
          Returns a recursively composed list of classes that are related to the classes in the specified list by being the types of fields, etc.
 java.lang.String externalNameForClass(java.lang.Class c)
           
 java.lang.String externalNameForField(java.lang.String javaName)
           
static java.lang.String fieldNameFromGetName(java.lang.String name)
           
static java.lang.String fieldNameFromSetName(java.lang.String name)
           
 ClassDescr getClassDescr(java.lang.Class c)
           
 ClassFinder getClassFinder()
           
protected  java.lang.reflect.Field[] getDeclaredFields(java.lang.Class c)
          Returns the class's declared fields, or an empty array if there's a security exception (as there might be in an applet).
protected  java.lang.reflect.Method[] getDeclaredMethods(java.lang.Class c)
          Returns the class's declared methods, or an empty array if there's a security exception (as there might be in an applet).
<T> Stringer<T>
getStringer(java.lang.Class<T> c)
           
protected  void initStringConversions()
           
static boolean isGetName(java.lang.String name)
           
static boolean isSetName(java.lang.String name)
           
protected  boolean isWanted(java.lang.reflect.Field f)
           
static void main(java.lang.String[] argv)
          Test loop that repeatedly asks the user for a class name and prints a description.
protected  ClassDescr makeClassDescr(java.lang.Class c)
           
 ClassDescr makeClassDescr(java.lang.Class collectionClass, java.lang.Class eltClass)
           
 ClassDescr makeClassDescr(java.lang.Class mapClass, java.lang.Class keyClass, java.lang.Class valClass)
           
protected  FieldDescr makeFieldDescr(java.lang.reflect.Field f)
           
(package private)  FieldMap makeFieldDescrs(java.lang.Class c)
          Called from a ClassDescr to make descriptions of the class's fields.
protected  ClassDescr makeFieldTypeDescr(FieldDescr fd, java.lang.Class fromClass)
          Constructs a ClassDescr that describes the value of a field.
 java.util.List<java.lang.Class> relevantClasses(java.lang.Class c)
          Returns a recursively composed list of classes that are related to the specified class by being the types of fields, etc.
 java.util.List<java.lang.Class> relevantClasses(java.lang.Class[] topClasses)
          Returns a recursively composed list of classes that are related to the classes in the specified array by being the types of fields, etc.
 java.util.List<java.lang.Class> relevantClasses(java.util.List<java.lang.Class> topClasses)
          Returns a recursively composed list of classes that are related to the classes in the specified list by being the types of fields, etc.
protected
<T> void
setStringer(java.lang.Class<T> c, Stringer<T> s)
           
protected  void tryGetMethod(java.lang.reflect.Method meth, FieldMap fields)
           
protected  void trySetMethod(java.lang.reflect.Method meth, FieldMap fields)
           
 java.lang.String upperNameForClass(java.lang.Class c)
           
 java.lang.String xmlSchemaDatatype(java.lang.Class c)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

classFinder

protected ClassFinder classFinder

classToDescrCache

protected java.util.Map<java.lang.Class,ClassDescr> classToDescrCache

classToStringerMap

protected java.util.Map<java.lang.Class,Stringer> classToStringerMap
Constructor Detail

ClassSyntax

public ClassSyntax()

ClassSyntax

public ClassSyntax(ClassFinder finder)
Method Detail

getClassFinder

public ClassFinder getClassFinder()

externalNameForClass

public java.lang.String externalNameForClass(java.lang.Class c)

classForExternalName

public java.lang.Class classForExternalName(java.lang.String externalName)

externalNameForField

public java.lang.String externalNameForField(java.lang.String javaName)

upperNameForClass

public java.lang.String upperNameForClass(java.lang.Class c)

getClassDescr

public ClassDescr getClassDescr(java.lang.Class c)

makeClassDescr

protected ClassDescr makeClassDescr(java.lang.Class c)

makeClassDescr

public ClassDescr makeClassDescr(java.lang.Class collectionClass,
                                 java.lang.Class eltClass)

makeClassDescr

public ClassDescr makeClassDescr(java.lang.Class mapClass,
                                 java.lang.Class keyClass,
                                 java.lang.Class valClass)

xmlSchemaDatatype

public java.lang.String xmlSchemaDatatype(java.lang.Class c)

getStringer

public <T> Stringer<T> getStringer(java.lang.Class<T> c)

setStringer

protected <T> void setStringer(java.lang.Class<T> c,
                               Stringer<T> s)

initStringConversions

protected void initStringConversions()

relevantClasses

public java.util.List<java.lang.Class> relevantClasses(java.lang.Class c)
Returns a recursively composed list of classes that are related to the specified class by being the types of fields, etc.


relevantClasses

public java.util.List<java.lang.Class> relevantClasses(java.lang.Class[] topClasses)
Returns a recursively composed list of classes that are related to the classes in the specified array by being the types of fields, etc.


relevantClasses

public java.util.List<java.lang.Class> relevantClasses(java.util.List<java.lang.Class> topClasses)
Returns a recursively composed list of classes that are related to the classes in the specified list by being the types of fields, etc.


expandRelevantClasses

public java.util.List<java.lang.Class> expandRelevantClasses(java.util.List<java.lang.Class> topClasses)
Returns a recursively composed list of classes that are related to the classes in the specified list by being the types of fields, etc. This method retains the order of the original list, but does preorder expansion of elements to include any relevant classes not already there.


collectRelevantClasses

protected void collectRelevantClasses(java.lang.Class c,
                                      java.util.List result,
                                      java.util.List tail)

collectRelevantClasses

protected void collectRelevantClasses(ClassDescr ftype,
                                      java.util.List result,
                                      java.util.List tail)

makeFieldDescrs

FieldMap makeFieldDescrs(java.lang.Class c)
Called from a ClassDescr to make descriptions of the class's fields. This method should not normally be used for other purposes.


collectFieldInfo

protected FieldMap collectFieldInfo(java.lang.Class objClass)

makeFieldTypeDescr

protected ClassDescr makeFieldTypeDescr(FieldDescr fd,
                                        java.lang.Class fromClass)
Constructs a ClassDescr that describes the value of a field.


getDeclaredMethods

protected java.lang.reflect.Method[] getDeclaredMethods(java.lang.Class c)
Returns the class's declared methods, or an empty array if there's a security exception (as there might be in an applet).


tryGetMethod

protected void tryGetMethod(java.lang.reflect.Method meth,
                            FieldMap fields)

trySetMethod

protected void trySetMethod(java.lang.reflect.Method meth,
                            FieldMap fields)

isGetName

public static final boolean isGetName(java.lang.String name)

isSetName

public static final boolean isSetName(java.lang.String name)

fieldNameFromGetName

public static final java.lang.String fieldNameFromGetName(java.lang.String name)

fieldNameFromSetName

public static final java.lang.String fieldNameFromSetName(java.lang.String name)

collectFields

protected FieldMap collectFields(java.lang.Class c,
                                 FieldMap fields)
Returns an initial List of FieldDescrs.


makeFieldDescr

protected FieldDescr makeFieldDescr(java.lang.reflect.Field f)

getDeclaredFields

protected java.lang.reflect.Field[] getDeclaredFields(java.lang.Class c)
Returns the class's declared fields, or an empty array if there's a security exception (as there might be in an applet).


isWanted

protected boolean isWanted(java.lang.reflect.Field f)

describeClass

public void describeClass(java.lang.Class c)
Prints a description of a class on System.out.


describeClass

public void describeClass(java.lang.Class c,
                          java.io.PrintStream out)
Prints a description of a class on the designated PrintStream.


main

public static void main(java.lang.String[] argv)
Test loop that repeatedly asks the user for a class name and prints a description.