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.
  • Field Details

  • Method Details

    • makeGetMethodName

      public static String makeGetMethodName​(String name)
    • makeGetMethodName2

      public static String makeGetMethodName2​(String name)
    • makeSetMethodName

      public static String makeSetMethodName​(String name)
    • 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
    • reflectToString

      public static String reflectToString​(Object o, boolean skipNulls)
    • customizedReflect

      public static String customizedReflect​(Object o, edu.wisc.game.reflect.PairFormatter f)
      More pretty version of reflectToString(Object o)
    • csvRow

      public static String csvRow​(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)
    • 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 element
      dolinks - 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

      public static String htmlHeaderRow​(Class c, boolean TR)
    • asStringVector

      public static Vector<String> asStringVector​(Object o, String quote)
    • 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.html

      Arrays 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
    • getNames

      public static String[] getNames​(Class c)
      Returns the array of field names
    • saveAsInsert

      public static String saveAsInsert​(Object o)
      Saves the object as a MySQL "INSERT" statement