classUtils.reflection
Class ReflectUtil

java.lang.Object
  extended by classUtils.reflection.ReflectUtil

public class ReflectUtil
extends java.lang.Object

ReflectUtil shows several examples of using reflection.


Constructor Summary
ReflectUtil(java.lang.Object _o)
          Instance the ReflectUtil with an Object.
 
Method Summary
static void addImmediateInterfaces(java.lang.Class c, java.util.Vector v)
           
static java.lang.Class[] getAllInterfaces(java.lang.Class c)
           
 java.lang.reflect.Method[] getAllMethods()
          Obtain a list of all the methods.
static java.lang.reflect.Method[] getAllMethods(java.lang.Object o)
           
 java.lang.reflect.Method[] getAllMethodsNotInObjectClass(java.lang.reflect.Method[] m)
           
 java.lang.reflect.Method[] getAllPublicMethods()
           
 java.lang.reflect.Method[] getAllPublicStaticMethods()
           
static java.lang.String getBeanDescriptorString(java.beans.BeanInfo bi)
           
 java.lang.String getBeanInfo()
           
 java.lang.Class getC()
          Get the containing class class instance.
 java.lang.Class[] getClasses()
          getClasses is not implemented in the cutils.reflection API, yet.
 java.lang.String getClassName()
          Get the name of the containing class.
 java.lang.reflect.Constructor[] getConstructors()
          Get a list of all the constructors in the containing class.
static java.lang.String getDisplayName(java.lang.reflect.Method m)
           
static java.beans.EventSetDescriptor[] getEventSetDescriptors(java.lang.Object o)
           
 java.lang.reflect.Field[] getFields()
          Get all but the inherited fields.
static java.beans.PropertyDescriptor[] getIndexedPropertyDescriptors(java.lang.Object o)
           
 java.lang.String getInfoString(java.lang.reflect.Method m)
           
 java.lang.reflect.Method getMethod(java.lang.String s)
           
 java.beans.MethodDescriptor[] getMethodDescriptors()
           
static java.beans.MethodDescriptor[] getMethodDescriptors(java.lang.Object o)
           
 MethodList getMethodList()
           
 java.lang.reflect.Method[] getMethods()
          Get all but inherited methods.
 java.lang.reflect.Method[] getMethodsWithNArgs(int n)
           
static java.lang.reflect.Method[] getMethodsWithNoArguments(java.lang.Object o)
           
 int getModifiers(java.lang.reflect.Method m)
           
 java.lang.String getModifierString(java.lang.reflect.Method m)
           
 java.lang.String getName(java.lang.reflect.Method m)
          Get A string representation of the method.
 java.lang.Object getObject()
           
 java.beans.PropertyDescriptor[] getPropertyDescriptors()
           
static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Object o)
           
 java.lang.Class[] getPublicClassMembers()
          Get a list of public class members that are not inherited.
 java.lang.String[] getReadMethodNames()
           
 java.lang.String[] getReadMethodNames(int n)
          Get the method that have exactly n arguments
 java.lang.String[] getReadPublicMethodNames(int n)
          Get the method that have exactly n arguments
static java.lang.String getString(java.lang.String prompt)
           
 java.lang.Class[] getSuperClasses()
           
static java.lang.Class[] getSuperInterfaces(java.lang.Class ci)
          Get all the interfaces implemented by this class, in order of listing.
 java.lang.Class[] getSuperInterfaces(java.lang.Class[] ca)
           
 java.lang.String[] getWriteMethodNames()
           
 java.lang.String[] getWriteMethodNames(java.lang.reflect.Method[] m)
           
static boolean hasMain(java.lang.Class classToBeExamined)
          Returns true if the Class has a public static void main(String args[]) method in it.
 java.lang.Object invoke(java.lang.String methodName)
          invoke a methodName string with no arguments.
 java.lang.Object invoke2(java.lang.String methodName)
          invoke a methodName string with no arguments.
 boolean isContainedBy(java.lang.reflect.Method[] ma, java.lang.reflect.Method m)
           
static void main(java.lang.String[] args)
          Example of reflectUtil usage.
 void print()
           
static void print(java.beans.EventSetDescriptor[] esd)
           
static void print(java.beans.IndexedPropertyDescriptor[] ipd)
           
static void print(java.beans.MethodDescriptor[] md)
           
 void print(java.lang.Object o)
           
 void print(java.lang.Object[] o)
           
static void print(java.beans.PropertyDescriptor[] pd)
           
 void printDeclaredMethods()
           
 void printInfo()
          print information about the containing instance to the console.
 void printInfo(java.lang.reflect.Method m)
           
static void printMethodNamesAndParameters(PrintStub printStub, java.lang.reflect.Method[] ma)
           
 void startCommandLineInterpreter()
          starts a simple command line interpreter that takes in method names.
static void testEventSetDescriptors()
           
static void testIndexedPropertyDescriptors()
           
static void testIntrospectUtil()
           
static void testMethodDescriptors()
           
static void testPropertyDescriptors()
           
static java.lang.String toString(java.lang.Object[] o)
          Convert an array of Object into a string.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectUtil

public ReflectUtil(java.lang.Object _o)
Instance the ReflectUtil with an Object. ReflectUtils gives extra feature not available with reflection.

Parameters:
_o - an instance of an object to be inspected
Method Detail

getConstructors

public java.lang.reflect.Constructor[] getConstructors()
Get a list of all the constructors in the containing class. Default constructors can be returned. For interfaces and primitive data types, no constructor is returned.

Returns:
an array of constructors.

getFields

public java.lang.reflect.Field[] getFields()
Get all but the inherited fields.

Returns:
array of field instances.

getMethods

public java.lang.reflect.Method[] getMethods()
Get all but inherited methods.

Returns:
array of methods

getAllPublicStaticMethods

public java.lang.reflect.Method[] getAllPublicStaticMethods()

printDeclaredMethods

public void printDeclaredMethods()

getAllPublicMethods

public java.lang.reflect.Method[] getAllPublicMethods()

getAllMethods

public java.lang.reflect.Method[] getAllMethods()
Obtain a list of all the methods.

Returns:
an array of all methods (including super classes).

hasMain

public static boolean hasMain(java.lang.Class classToBeExamined)
Returns true if the Class has a public static void main(String args[]) method in it.

Returns:
true if and only if class has a main.

getSuperClasses

public java.lang.Class[] getSuperClasses()

getSuperInterfaces

public java.lang.Class[] getSuperInterfaces(java.lang.Class[] ca)

getSuperInterfaces

public static java.lang.Class[] getSuperInterfaces(java.lang.Class ci)
Get all the interfaces implemented by this class, in order of listing.

Parameters:
ci - class instance to be inspected
Returns:
an array of all the classes that correspond to the interfaces.

getPublicClassMembers

public java.lang.Class[] getPublicClassMembers()
Get a list of public class members that are not inherited.

Returns:
an array of Class class instances.

getAllInterfaces

public static java.lang.Class[] getAllInterfaces(java.lang.Class c)

addImmediateInterfaces

public static void addImmediateInterfaces(java.lang.Class c,
                                          java.util.Vector v)

getReadMethodNames

public java.lang.String[] getReadMethodNames()

getReadPublicMethodNames

public java.lang.String[] getReadPublicMethodNames(int n)
Get the method that have exactly n arguments

Parameters:
n - a number that start affineTransform 0
Returns:
returns the read method array

getReadMethodNames

public java.lang.String[] getReadMethodNames(int n)
Get the method that have exactly n arguments

Parameters:
n - a number that start affineTransform 0
Returns:
returns the read method array

getWriteMethodNames

public java.lang.String[] getWriteMethodNames()
Returns:
method in present class

getWriteMethodNames

public java.lang.String[] getWriteMethodNames(java.lang.reflect.Method[] m)

getMethod

public java.lang.reflect.Method getMethod(java.lang.String s)
Parameters:
s - a method name
Returns:
a method that corresponds to this name

invoke

public java.lang.Object invoke(java.lang.String methodName)
invoke a methodName string with no arguments.


getModifiers

public int getModifiers(java.lang.reflect.Method m)
Parameters:
m - a method to be inspected
Returns:
modifiers encoded as an int.

getModifierString

public java.lang.String getModifierString(java.lang.reflect.Method m)
Parameters:
m - method
Returns:
a string representation of the modifiers

toString

public static java.lang.String toString(java.lang.Object[] o)
Convert an array of Object into a string.

Parameters:
o - an array of string in
Returns:
a big string with new lines out

printInfo

public void printInfo()
print information about the containing instance to the console.


getClassName

public java.lang.String getClassName()
Get the name of the containing class.

Returns:
classname.

getMethodsWithNArgs

public java.lang.reflect.Method[] getMethodsWithNArgs(int n)

getName

public java.lang.String getName(java.lang.reflect.Method m)
Get A string representation of the method.

Parameters:
m - method name
Returns:
the name of the method

getInfoString

public java.lang.String getInfoString(java.lang.reflect.Method m)

printInfo

public void printInfo(java.lang.reflect.Method m)

main

public static void main(java.lang.String[] args)
Example of reflectUtil usage.

Parameters:
args - ignored.

startCommandLineInterpreter

public void startCommandLineInterpreter()
starts a simple command line interpreter that takes in method names.


getString

public static java.lang.String getString(java.lang.String prompt)

getC

public java.lang.Class getC()
Get the containing class class instance.

Returns:
The containing class class.

getAllMethods

public static java.lang.reflect.Method[] getAllMethods(java.lang.Object o)

getMethodsWithNoArguments

public static java.lang.reflect.Method[] getMethodsWithNoArguments(java.lang.Object o)

invoke2

public java.lang.Object invoke2(java.lang.String methodName)
invoke a methodName string with no arguments.


printMethodNamesAndParameters

public static void printMethodNamesAndParameters(PrintStub printStub,
                                                 java.lang.reflect.Method[] ma)

getClasses

public java.lang.Class[] getClasses()
getClasses is not implemented in the cutils.reflection API, yet.


isContainedBy

public boolean isContainedBy(java.lang.reflect.Method[] ma,
                             java.lang.reflect.Method m)

getAllMethodsNotInObjectClass

public java.lang.reflect.Method[] getAllMethodsNotInObjectClass(java.lang.reflect.Method[] m)

testIndexedPropertyDescriptors

public static void testIndexedPropertyDescriptors()
                                           throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

getIndexedPropertyDescriptors

public static java.beans.PropertyDescriptor[] getIndexedPropertyDescriptors(java.lang.Object o)
                                                                     throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

print

public static void print(java.beans.PropertyDescriptor[] pd)

print

public static void print(java.beans.IndexedPropertyDescriptor[] ipd)

getBeanInfo

public java.lang.String getBeanInfo()

getBeanDescriptorString

public static java.lang.String getBeanDescriptorString(java.beans.BeanInfo bi)

print

public void print()

print

public void print(java.lang.Object o)

testPropertyDescriptors

public static void testPropertyDescriptors()
                                    throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

getPropertyDescriptors

public static java.beans.PropertyDescriptor[] getPropertyDescriptors(java.lang.Object o)
                                                              throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

testMethodDescriptors

public static void testMethodDescriptors()
                                  throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

print

public static void print(java.beans.MethodDescriptor[] md)

getMethodDescriptors

public static java.beans.MethodDescriptor[] getMethodDescriptors(java.lang.Object o)
                                                          throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

testEventSetDescriptors

public static void testEventSetDescriptors()
                                    throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

getEventSetDescriptors

public static java.beans.EventSetDescriptor[] getEventSetDescriptors(java.lang.Object o)
                                                              throws java.beans.IntrospectionException
Throws:
java.beans.IntrospectionException

print

public static void print(java.beans.EventSetDescriptor[] esd)

print

public void print(java.lang.Object[] o)

testIntrospectUtil

public static void testIntrospectUtil()

getObject

public java.lang.Object getObject()

getMethodList

public MethodList getMethodList()

getPropertyDescriptors

public java.beans.PropertyDescriptor[] getPropertyDescriptors()

getMethodDescriptors

public java.beans.MethodDescriptor[] getMethodDescriptors()

getDisplayName

public static java.lang.String getDisplayName(java.lang.reflect.Method m)