org.sf.jlaunchpad.util
Class ReflectionUtil

java.lang.Object
  extended by org.sf.jlaunchpad.util.ReflectionUtil

public class ReflectionUtil
extends java.lang.Object

This is the class for holding reflection utilities.

Version:
1.0 02/19/2006
Author:
Alexander Shvets

Constructor Summary
ReflectionUtil()
           
 
Method Summary
static java.lang.reflect.Method getMainMethod(java.lang.Class clazz)
          Searches for the "main" method.
protected static java.lang.reflect.Method getMainMethod(java.lang.Class clazz, java.lang.Class[] paramTypes)
          Searches for the "main" method.
static java.lang.reflect.Method getMainMethodWithTwoParameters(java.lang.Class clazz, java.lang.Class secondParameterClass)
          Searches for the "main" method.
static java.lang.Object getPrivateField(java.lang.Object source, java.lang.Class clazz, java.lang.String name)
          Gets the private filed.
static java.lang.Object invokePrivateMethod(java.lang.Object source, java.lang.Object[] parameters, java.lang.Class clazz, java.lang.String name, java.lang.Class[] parameterTypes)
          Invokes the private method.
static java.lang.Object launchClass(java.lang.Class mainClass, java.lang.String[] args, java.lang.String illegalArgumentMessage)
          Tries to launch the class.
static java.lang.Object launchClass(java.lang.reflect.Method mainMethod, java.lang.Object[] args, java.lang.String illegalArgumentMessage)
          Tries to launch the class.
static void setPrivateField(java.lang.Object source, java.lang.Class clazz, java.lang.String name, java.lang.Object value)
          Sets the private filed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtil

public ReflectionUtil()
Method Detail

getMainMethod

public static java.lang.reflect.Method getMainMethod(java.lang.Class clazz)
Searches for the "main" method.

Parameters:
clazz - the class where we are searching for "main" methd
Returns:
the "main" method

getMainMethodWithTwoParameters

public static java.lang.reflect.Method getMainMethodWithTwoParameters(java.lang.Class clazz,
                                                                      java.lang.Class secondParameterClass)
Searches for the "main" method.

Parameters:
clazz - the class where we are searching for "main" methd
secondParameterClass - second parameter class
Returns:
the "main" method

getMainMethod

protected static java.lang.reflect.Method getMainMethod(java.lang.Class clazz,
                                                        java.lang.Class[] paramTypes)
Searches for the "main" method.

Parameters:
clazz - the class where we are searching for "main" methd
paramTypes - parameter types
Returns:
the "main" method

launchClass

public static java.lang.Object launchClass(java.lang.Class mainClass,
                                           java.lang.String[] args,
                                           java.lang.String illegalArgumentMessage)
                                    throws java.lang.IllegalAccessException,
                                           java.lang.reflect.InvocationTargetException
Tries to launch the class.

Parameters:
mainClass - the class to be launched
args - the list of arguments
illegalArgumentMessage - the message to be displayed if main method cannot be found
Returns:
result
Throws:
java.lang.IllegalAccessException - exception
java.lang.reflect.InvocationTargetException - exception

launchClass

public static java.lang.Object launchClass(java.lang.reflect.Method mainMethod,
                                           java.lang.Object[] args,
                                           java.lang.String illegalArgumentMessage)
                                    throws java.lang.IllegalAccessException,
                                           java.lang.reflect.InvocationTargetException
Tries to launch the class.

Parameters:
mainMethod - main method
args - the list of arguments
illegalArgumentMessage - the message to be displayed if main method cannot be found
Returns:
result
Throws:
java.lang.IllegalAccessException - exception
java.lang.reflect.InvocationTargetException - exception

getPrivateField

public static java.lang.Object getPrivateField(java.lang.Object source,
                                               java.lang.Class clazz,
                                               java.lang.String name)
                                        throws java.lang.NoSuchFieldException,
                                               java.lang.IllegalAccessException
Gets the private filed. Required, if you cannot make changes in inheritance and still need to access the private field.

Parameters:
source - the source object
name - the field name to access
clazz - the class
Returns:
the private filed
Throws:
java.lang.NoSuchFieldException - the exception
java.lang.IllegalAccessException - the exception

setPrivateField

public static void setPrivateField(java.lang.Object source,
                                   java.lang.Class clazz,
                                   java.lang.String name,
                                   java.lang.Object value)
                            throws java.lang.NoSuchFieldException,
                                   java.lang.IllegalAccessException
Sets the private filed. Required, if you cannot make changes in inheritance and still need to access the private field.

Parameters:
source - the source object
clazz - the class
name - the field name to access
value - the value
Throws:
java.lang.NoSuchFieldException - the exception
java.lang.IllegalAccessException - the exception

invokePrivateMethod

public static java.lang.Object invokePrivateMethod(java.lang.Object source,
                                                   java.lang.Object[] parameters,
                                                   java.lang.Class clazz,
                                                   java.lang.String name,
                                                   java.lang.Class[] parameterTypes)
                                            throws java.lang.NoSuchMethodException,
                                                   java.lang.IllegalAccessException,
                                                   java.lang.reflect.InvocationTargetException
Invokes the private method. Required, if you cannot make changes in inheritance and still need to call the private method.

Parameters:
source - the source object
parameters - the parameters list
clazz - the source class
name - the method name
parameterTypes - the list of parameter types
Returns:
the result of invokation
Throws:
java.lang.NoSuchMethodException - the exception
java.lang.IllegalAccessException - the exception
java.lang.reflect.InvocationTargetException - the exception


Copyright © 2007-2008 Dream Programs Inc.. All Rights Reserved.