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[]entriesstatic DateFormatsqlDf -
Method Summary
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" statement
-
Field Details
-
Method Details
-
makeGetMethodName
-
makeGetMethodName2
-
makeSetMethodName
-
getEntry
-
getOwningEntry
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
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
Prints all appropriate fields of the specified object in the default (toString) format -
compactFormat
Compact human readable format, with no extra quotes, for various HTML tables -
reflectToString
-
customizedReflect
More pretty version ofreflectToString(Object o) -
csvRow
-
csvRow
Saves the object as a row of comma-separated file- Parameters:
end- The text to append to the end (CR, or "")
-
htmlRow
-
htmlRow
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.
-
htmlHeaderRow
-
asStringVector
-
asStringVector
- 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
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
Saves the class description as the header line of a comma-separated file -
getNames
Returns the array of field names -
saveAsInsert
Saves the object as a MySQL "INSERT" statement
-