Package edu.wisc.game.reflect
Class Reflect
- java.lang.Object
-
- edu.wisc.game.reflect.Reflect
-
public class Reflect extends Object
A bunch of methods to figure what fields a class has, and how to print them out in a more or less sensible way.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classReflect.EntryAn entry describes one field of the class, complete with its access methods (getter and setter) and the display hints
-
Field Summary
Fields Modifier and Type Field Description Reflect.Entry[]entriesMethodextraFieldsMethodIf this method exists in the class, it can be executed to get a Mapfor extra fields to be put into the JSON structure. static StringextraFieldsMethodNamestatic DateFormatsqlDf
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Vector<String>asStringVector(Object o, String quote)static Vector<String>asStringVector(Object o, String quote, boolean dolinks)static StringcompactFormat(Object val)Compact human readable format, with no extra quotes, for various HTML tablesstatic StringcsvHeader(Class c)Saves the class description as the header line of a comma-separated filestatic StringcsvRow(Object o)static StringcsvRow(Object o, String end)Saves the object as a row of comma-separated filestatic StringcustomizedReflect(Object o, edu.wisc.game.reflect.PairFormatter f)More pretty version ofreflectToString(Object o)static StringformatAsString(Object val, String quote)Formats a single field of an object.Reflect.EntrygetEntry(String name)static String[]getNames(Class c)Returns the array of field namesReflect.EntrygetOwningEntry(Enum e)Finds the entry that describes the field whose type is the the enumerated class for which e is one of the values.static ReflectgetReflect(Class c)Looks up or creates a Reflect instance for a specified class.static StringhtmlHeaderRow(Class c, boolean TR)static StringhtmlRow(Object o, boolean TR)static StringhtmlRow(Object o, boolean TR, boolean dolinks)Returns a complete TR element, or just a bunch of TD cells.static StringmakeGetMethodName(String name)static StringmakeGetMethodName2(String name)static StringmakeSetMethodName(String name)static StringreflectToString(Object o)Prints all appropriate fields of the specified object in the default (toString) formatstatic StringreflectToString(Object o, boolean skipNulls)static StringsaveAsInsert(Object o)Saves the object as a MySQL "INSERT" statementStringtoString()
-
-
-
Field Detail
-
sqlDf
public static final DateFormat sqlDf
-
entries
public Reflect.Entry[] entries
-
extraFieldsMethod
public Method extraFieldsMethod
If this method exists in the class, it can be executed to get a Mapfor extra fields to be put into the JSON structure. We use this to transmit arbitrary object properties in the Captive Game Server.
-
extraFieldsMethodName
public static final String extraFieldsMethodName
- See Also:
- Constant Field Values
-
-
Method Detail
-
getEntry
public Reflect.Entry getEntry(String name)
-
getOwningEntry
public Reflect.Entry getOwningEntry(Enum e) throws IllegalArgumentException
Finds the entry that describes the field whose type is the the enumerated class for which e is one of the values. This method only makes sense to use if the class has only field with that enum type; otherwise, an error will be thrown- Returns:
- A matching Entry object, or null
- Throws:
IllegalArgumentException
-
getReflect
public static Reflect getReflect(Class c)
Looks up or creates a Reflect instance for a specified class.- Parameters:
c- Class to analyze. We reduce it to an existing basic class, if possible (in case it is of an automatically derived type, such as org.apache.openjpa.enhance.edu.wisc.game.rest$Respondent$pcsubclass )
-
reflectToString
public static String reflectToString(Object o)
Prints all appropriate fields of the specified object in the default (toString) format
-
compactFormat
public static String compactFormat(Object val)
Compact human readable format, with no extra quotes, for various HTML tables
-
customizedReflect
public static String customizedReflect(Object o, edu.wisc.game.reflect.PairFormatter f)
More pretty version ofreflectToString(Object o)
-
csvRow
public static String csvRow(Object o, String end)
Saves the object as a row of comma-separated file- Parameters:
end- The text to append to the end (CR, or "")
-
htmlRow
public static String htmlRow(Object o, boolean TR, boolean dolinks)
Returns a complete TR element, or just a bunch of TD cells.- Parameters:
TR- Include the TR elementdolinks- Include hyperlinks to other pages on fields that have the "link" value set in their "Display" attribute. This is useful in research pages, but (usually) not in user-facing pages.
-
asStringVector
public static Vector<String> asStringVector(Object o, String quote, boolean dolinks)
- Parameters:
quote- The string to use for quotes (may be an empty string, if no quotes are needed)dolinks- If true, attention is paid to the link() attribute, converting some fields into hyperlinks
-
formatAsString
public static String formatAsString(Object val, String quote)
Formats a single field of an object. Note the somewhat peculiar treatment of boolean values in OpenJPA. If the object has been retreived with a query obtained with createQuery() (i.e., a JPQL query), then a boolean value will be retrieved as Boolean object. But if createNativeQuery() (over MySQL, at any rate) has been used - i.e., we have a SQL query - then boolean values will appear as strings, one character long, containing char(0) or char(1)! This is because in MySQL booleans are "synonyms for TINYINT(1)". http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.htmlArrays and other collections are printed elementwise if it can be done consicely enough; otherwise, just element count
-
csvHeader
public static String csvHeader(Class c)
Saves the class description as the header line of a comma-separated file
-
-