igpp.util
Class Reflection

java.lang.Object
  extended by igpp.util.Reflection

public class Reflection
extends Object

A utility class that provides methods for self-aware actions. Methods support the calling set*() methods using keyword/value arguments which includes using "keyword=value" syntax. Additional methods support dumping the value of all fields of an object.

Version:
1.00 2007
Author:
Todd King

Constructor Summary
Reflection()
           
 
Method Summary
static void dump(Object obj)
          Print the value of all member variables to System.out.
static void dumpMethods(Object obj)
          Print the value of all member variables to System.out.
static String getMemberValue(Object obj, String name)
          Call the get() method with a given name suffix and return the value as String.
static Method getMethod(Object obj, String name)
          Returns the first Method with a given name regardless of the full signature (arguments) of the method.
static Method getMethod(Object obj, String name, Class[] argSig)
          Returns the first Method with a given name which matches the the full signature (arguments) of the method.
static void main(String[] args)
           
static boolean setMember(Object obj, String statement)
          Set a member variable using the syntax "name=value".
static boolean setMember(Object obj, String name, String value)
          Call the set() method with a given name suffix passing one argument.
static boolean setMember(Object obj, String name, String[] value)
          Call the set() method with a given name suffix and a String array as an argument.
static boolean setMemberString(Object obj, String name, String value)
          Call the set() method with a given name suffix and a String as an argument.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflection

public Reflection()
Method Detail

main

public static void main(String[] args)

setMember

public static boolean setMember(Object obj,
                                String statement)
Set a member variable using the syntax "name=value". The passed Object is searched for a "setName" method to call to set the member varaible.

Parameters:
obj - the Object to inspect for the setName method.
statement - the string containing "name=value".
Returns:
true if the statement was parsed correctly, otherwise false

setMember

public static boolean setMember(Object obj,
                                String name,
                                String[] value)
Call the set() method with a given name suffix and a String array as an argument. Calls the appropriate set method for each value.

Parameters:
obj - the Object to inspect for the setName method.
name - the name of the item to set.
value - the String array of values to set.
Returns:
true
Since:
1.0

setMemberString

public static boolean setMemberString(Object obj,
                                      String name,
                                      String value)
Call the set() method with a given name suffix and a String as an argument.

Parameters:
obj - the Object to inspect for the setName method.
name - the name of the item to set.
value - the String value to set.
Returns:
true if the set method was called, otherwise false
Since:
1.0

setMember

public static boolean setMember(Object obj,
                                String name,
                                String value)
Call the set() method with a given name suffix passing one argument. Type conversion is attempted for the passed argument based on the signature of the set method.

Parameters:
obj - the Object to inspect for the setName method.
name - the name of the item to set.
value - the String value to set.
Returns:
true if the set method was called, otherwise false
Since:
1.0

getMemberValue

public static String getMemberValue(Object obj,
                                    String name)
Call the get() method with a given name suffix and return the value as String.

Parameters:
obj - the Object to inspect for the setName method.
name - the name of the item to set.
Returns:
the returned String value from the get method.
Since:
1.0

getMethod

public static Method getMethod(Object obj,
                               String name)
Returns the first Method with a given name regardless of the full signature (arguments) of the method. The name of the method is case-insensitve. Most useful for retrieving methods with no arguments. Returns null if no method is found.

Parameters:
obj - the Object to inspect for the get method.
name - the name of the item to set.
Returns:
the Method is a match is found, otherwise null
Since:
1.0

getMethod

public static Method getMethod(Object obj,
                               String name,
                               Class[] argSig)
Returns the first Method with a given name which matches the the full signature (arguments) of the method. The name of the method is case-insensitve. Returns null if no method is found.

Parameters:
obj - the Object to inspect for the get method.
name - the name of the item to set.
argSig - an array of Class instances which specify the argument types for the method.
Returns:
the Method is a match is found, otherwise null
Since:
1.0

dump

public static void dump(Object obj)
Print the value of all member variables to System.out.

Parameters:
obj - the Object to inspect for the member varaibles.
Since:
1.0

dumpMethods

public static void dumpMethods(Object obj)
Print the value of all member variables to System.out.

Parameters:
obj - the Object to inspect for the member varaibles.
Since:
1.0


Copyright © 2008-2009 Regents University of California. All Rights Reserved.