com.waveset.util
Class Reflection

java.lang.Object
  extended bycom.waveset.util.Reflection

public class Reflection
extends java.lang.Object

Reflection utilities.


Field Summary
static java.lang.String code_id
           
protected static Trace trace
           
 
Constructor Summary
Reflection()
           
 
Method Summary
static java.lang.Class[] getArgClasses(java.util.List args)
          Convert a list of argument values, into an array of classes used to locate the appropriate method.
static java.lang.Object getBooleanProperty(java.lang.Object obj, java.lang.String name)
          Get the value of a boolean property using JavaBean setter convention.
static java.lang.Class getClass(java.lang.String name)
          Load a class, but make exceptions prettier.
static java.lang.Class getClassIfExists(java.lang.String cname)
           
static java.lang.reflect.Constructor getConstructor(java.lang.Class c, java.lang.Class[] args)
          Locate a suitable constructor.
static int getIntConstant(java.lang.Class c, java.lang.String constantName, int dflt)
           
static java.lang.reflect.Method getMethod(java.lang.Class c, java.lang.String name, java.lang.Class[] args)
          Locate a suitable method.
static java.lang.reflect.Method getMethod(java.lang.Class c, java.lang.String name, java.lang.Class[] args, boolean raiseError)
          Locate a suitable method.
static java.lang.reflect.Method getMethod(java.lang.Class c, java.lang.String name, java.util.List argValues)
          Locate a suitable method, making certain parameter corecions if necessary.
static java.lang.Object getProperty(java.lang.Object obj, java.lang.String name)
          Get the value of a property using JavaBean setter convention.
static java.lang.Object getProperty(java.lang.Object obj, java.lang.String name, boolean raiseError)
           
static java.lang.String getStringConstant(java.lang.Class c, java.lang.String constantName, java.lang.String dflt)
           
static java.lang.Package[] getWavesetPackages()
           
static boolean hasProperty(java.lang.Object obj, java.lang.String name)
          Test to see if a property is supported.
static java.lang.Object instantiate(java.lang.Class c)
          Create an instance of an object given a class, and assuming a no-arg constructor.
static java.lang.Object instantiate(java.lang.Class c, java.util.List args)
          Create an instance of an object, given a class and a list of constructor arguments.
static java.lang.Object instantiate(java.lang.Class c, java.lang.Object[] args)
          Create an instance of an object, given a class and an array of constructor arguments.
static java.lang.Object instantiate(java.lang.reflect.Constructor con, java.util.List args)
          Create an instance of an object, given a constructor and a list of arguments.
static java.lang.Object instantiate(java.lang.String name)
          Create an instance of a class given a class name, and assuming a no-arg constructor.
static java.lang.Object instantiate(java.lang.String name, java.util.List args)
          Create an instance of an object, given a class name and a list of constructor arguments.
static java.lang.Object invoke(java.lang.reflect.Method m, java.lang.Object target, java.util.List args)
          Invoke a method.
static java.lang.Object invoke(java.lang.reflect.Method m, java.lang.Object target, java.lang.Object[] args)
          Invoke a method.
static void setProperty(java.lang.Object obj, java.lang.String name, java.lang.Object value)
          Assign an object field using JavaBean setter convention.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

code_id

public static final java.lang.String code_id
See Also:
Constant Field Values

trace

protected static final Trace trace
Constructor Detail

Reflection

public Reflection()
Method Detail

getClass

public static java.lang.Class getClass(java.lang.String name)
                                throws WavesetException
Load a class, but make exceptions prettier.

Throws:
WavesetException

getClassIfExists

public static java.lang.Class getClassIfExists(java.lang.String cname)

getArgClasses

public static java.lang.Class[] getArgClasses(java.util.List args)
                                       throws WavesetException
Convert a list of argument values, into an array of classes used to locate the appropriate method.

Note that we'll convert java.lang.Integer values into Class.forName("int") classes under the assumption you normally use primitive integers for method arguments. We could try to be smarter and recognize both types, but that would require that we merge getArgClasses and getMethod.

If we encounter a null argument, we originally left behind the java.lang.Object class, but since we really have to treat this as a wildcard during method searching, just leave it null.

Throws:
WavesetException

getConstructor

public static java.lang.reflect.Constructor getConstructor(java.lang.Class c,
                                                           java.lang.Class[] args)
                                                    throws WavesetException
Locate a suitable constructor.

Throws:
WavesetException

instantiate

public static java.lang.Object instantiate(java.lang.String name)
                                    throws WavesetException
Create an instance of a class given a class name, and assuming a no-arg constructor.

Throws:
WavesetException

instantiate

public static java.lang.Object instantiate(java.lang.Class c)
                                    throws WavesetException
Create an instance of an object given a class, and assuming a no-arg constructor.

Throws:
WavesetException

instantiate

public static java.lang.Object instantiate(java.lang.reflect.Constructor con,
                                           java.util.List args)
                                    throws WavesetException
Create an instance of an object, given a constructor and a list of arguments.

Throws:
WavesetException

instantiate

public static java.lang.Object instantiate(java.lang.Class c,
                                           java.util.List args)
                                    throws WavesetException
Create an instance of an object, given a class and a list of constructor arguments.

Throws:
WavesetException

instantiate

public static java.lang.Object instantiate(java.lang.Class c,
                                           java.lang.Object[] args)
                                    throws WavesetException
Create an instance of an object, given a class and an array of constructor arguments.

Throws:
WavesetException

instantiate

public static java.lang.Object instantiate(java.lang.String name,
                                           java.util.List args)
                                    throws WavesetException
Create an instance of an object, given a class name and a list of constructor arguments.

Throws:
WavesetException

getMethod

public static java.lang.reflect.Method getMethod(java.lang.Class c,
                                                 java.lang.String name,
                                                 java.lang.Class[] args)
                                          throws WavesetException
Locate a suitable method.

Throws:
WavesetException

getMethod

public static java.lang.reflect.Method getMethod(java.lang.Class c,
                                                 java.lang.String name,
                                                 java.lang.Class[] args,
                                                 boolean raiseError)
                                          throws WavesetException
Locate a suitable method.

Throws:
WavesetException

getMethod

public static java.lang.reflect.Method getMethod(java.lang.Class c,
                                                 java.lang.String name,
                                                 java.util.List argValues)
                                          throws WavesetException
Locate a suitable method, making certain parameter corecions if necessary.

This is handy for cases like setting properties from Forms or XPRESS where the value may be a string, but the function is defined to take an "int". Handle a few of the common cases and coerce the value. We assume we're allowed to modify the values in the params list.

This isn't nearly comprehensive enough, adding coercion makes the difficulty of selecting the "best fit" method within the class hierarchy even harder and potentially ambiguous.

Parameters:
c - The class the method is in
name - The name of the method
argValues - The values of the arguments
Throws:
WavesetException

invoke

public static java.lang.Object invoke(java.lang.reflect.Method m,
                                      java.lang.Object target,
                                      java.util.List args)
                               throws WavesetException
Invoke a method.

Throws:
WavesetException

invoke

public static java.lang.Object invoke(java.lang.reflect.Method m,
                                      java.lang.Object target,
                                      java.lang.Object[] args)
                               throws WavesetException
Invoke a method.

Throws:
WavesetException

setProperty

public static void setProperty(java.lang.Object obj,
                               java.lang.String name,
                               java.lang.Object value)
                        throws WavesetException
Assign an object field using JavaBean setter convention. Hmm, isn't there something in the JavaBean runtime to do this?

Throws:
WavesetException

getProperty

public static java.lang.Object getProperty(java.lang.Object obj,
                                           java.lang.String name)
                                    throws WavesetException
Get the value of a property using JavaBean setter convention. Hmm, isn't there something in the JavaBean runtime to do this?

Throws:
WavesetException

getProperty

public static java.lang.Object getProperty(java.lang.Object obj,
                                           java.lang.String name,
                                           boolean raiseError)
                                    throws WavesetException
Throws:
WavesetException

getBooleanProperty

public static java.lang.Object getBooleanProperty(java.lang.Object obj,
                                                  java.lang.String name)
                                           throws WavesetException
Get the value of a boolean property using JavaBean setter convention.

Throws:
WavesetException

hasProperty

public static boolean hasProperty(java.lang.Object obj,
                                  java.lang.String name)
Test to see if a property is supported. Assume the existance of a getter is enough.


getStringConstant

public static java.lang.String getStringConstant(java.lang.Class c,
                                                 java.lang.String constantName,
                                                 java.lang.String dflt)

getIntConstant

public static int getIntConstant(java.lang.Class c,
                                 java.lang.String constantName,
                                 int dflt)

getWavesetPackages

public static java.lang.Package[] getWavesetPackages()