org.eclipse.actf.validation.core
Class Reflector

java.lang.Object
  extended by org.eclipse.actf.validation.core.Reflector

public class Reflector
extends Object

Because the IBM Reflexive GUI Builder appplication is based on the Java Reflection API, we use this class to perform most of the introspection of classes required by the main RGB engine to build and render GUIs. Methods of the Reflector are used to obtain appropriate constructors, methods, and fields of a given class or object.

Author:
Mike Squillace

Nested Class Summary
 class Reflector.Result
          used primarily by the Reflector class to return the results of introspection
 
Constructor Summary
Reflector()
          create a new Reflector for introspecting classes in order to find methods and constructors
 
Method Summary
 Reflector.Result createReflectorResult(Object member, Object[] params)
          convenience method for creating a Reflector.Result object for use outside Reflector class
 Reflector.Result findConstructor(Class objClass, Parameter ctorArg)
          find the constructor of the given class that best fits the given parameters.
 Reflector.Result findConstructor(Class objClass, Parameter[] ctorArgs)
           
 Reflector.Result findMethod(Object methOwner, String name, Parameter arg)
          find a method corresponding to the given name and parameters.
 Reflector.Result findMethod(Object methOwner, String name, Parameter[] args)
           
 List findMethods(Class cls, String name)
          find a list of methods with the given name that can be invoked on an object of the given class.
 List findMethods(Object methodOwner, String name)
          find a list of methods with the given name that can be invoked on the given object
 Object getFieldValue(String name, Class cls)
          retreave a static field value with the given name from the given class
 Object getFieldValue(String name, Object object)
          retreave a field value with the given name from the given object
 boolean setFieldValue(String name, Object object, Parameter val)
          set the value of the field with the given name on the given object to the value specified
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflector

public Reflector()
create a new Reflector for introspecting classes in order to find methods and constructors

Method Detail

createReflectorResult

public Reflector.Result createReflectorResult(Object member,
                                              Object[] params)
convenience method for creating a Reflector.Result object for use outside Reflector class

Parameters:
member - -- class member
params - -- parameters for invokation of member
Returns:
new Reflector.Result instance

findConstructor

public Reflector.Result findConstructor(Class objClass,
                                        Parameter ctorArg)
find the constructor of the given class that best fits the given parameters. notice that the constructor that is desired may not be the one returned as this method makes a best-guess at the types of the given arguments, especially if these are to be evaluated or interpreted as primitives.

Parameters:
objClass - -- class of object to be instantiated
ctorArg - -- either single argument for constructor or code block which, upon evaluation, can be resolved to appropriate arguments
Returns:
Result object containing result of introspection or null if no constructor could be found

findConstructor

public Reflector.Result findConstructor(Class objClass,
                                        Parameter[] ctorArgs)
Parameters:
objClass - -- class of object to be instantiated
ctorArgs - -- either single argument for constructor or code block which, upon evaluation, can be resolved to appropriate arguments
Returns:
Result object containing result of introspection or null if no constructor could be found
See Also:
findConstructor(Class, Parameter)

findMethod

public Reflector.Result findMethod(Object methOwner,
                                   String name,
                                   Parameter arg)
find a method corresponding to the given name and parameters. This method attempts to find a method that can be invoked on the given methodOwner with the given name and that can accept the given parameters. Note that this method makes a "best guess" at the type of the given arguments, especially if these are to be evaluated or interpreted as primitives.

Parameters:
methOwner - -- object upon which method is to be invoked
name - -- method name
arg - -- single argument to method or code which, upon evaluation, can be resolved to appropriate arguments for a method
Returns:
Result object containing result of introspection or null if no method could be found

findMethod

public Reflector.Result findMethod(Object methOwner,
                                   String name,
                                   Parameter[] args)
Parameters:
methOwner - -- object upon which method is to be invoked
name - -- method name
args - -- single argument to method or code which, upon evaluation, can be resolved to appropriate arguments for a method
Returns:
Result object containing result of introspection or null if no method could be found
See Also:
findMethod(Object, String, Parameter)

findMethods

public List findMethods(Object methodOwner,
                        String name)
find a list of methods with the given name that can be invoked on the given object

Parameters:
methodOwner - -- object upon which methods returned could be invoked
name - -- method name
Returns:
list of methods with the given name that could be invoked on the given object

findMethods

public List findMethods(Class cls,
                        String name)
find a list of methods with the given name that can be invoked on an object of the given class.

Parameters:
cls - -- class of object upon which methods returned could be invoked
name - -- method name
Returns:
list of methods with the given name that could be invoked on an object of the given class

getFieldValue

public Object getFieldValue(String name,
                            Class cls)
retreave a static field value with the given name from the given class

Parameters:
name - -- name of field to be queried
cls - -- class of which field is member
Returns:
value of field for that class or null if field does not exist

getFieldValue

public Object getFieldValue(String name,
                            Object object)
retreave a field value with the given name from the given object

Parameters:
name - -- name of field to be queried
object - -- object of which field is member
Returns:
value of field for that object or null if field does not exist

setFieldValue

public boolean setFieldValue(String name,
                             Object object,
                             Parameter val)
set the value of the field with the given name on the given object to the value specified

Parameters:
name - -- name of field
object - -- object whose field is being set
val - -- value of field
Returns:
true if setting of field was successful, false otherwise