org.openorb.util
Class ReflectionUtils

java.lang.Object
  |
  +--org.openorb.util.ReflectionUtils

public final class ReflectionUtils
extends Object

Various reflection utilities.


Method Summary
static Method getReadObjectMethod(Class clz)
          Get the readObject( java.io.ObjectInputStream ) method from the class and set accessibility to true.
static Method getReadResolveMethod(Class clz)
          Get the readResolve() method from the class and set accessibility to true.
static Object getStubInstance(Class clz, Object obj)
          Return an instance of the specified stub and set the delegate to the one from the specified object.
static Method getWriteObjectMethod(Class clz)
          Get the readObject( java.io.ObjectInputStream ) method from the class and set accessibility to true.
static Method getWriteReplaceMethod(Class clz)
          Get the writeReplace() method from the class and set accessibility to true.
static boolean hasReadObjectMethod(Class clz)
           
static boolean hasWriteObjectMethod(Class clz)
          Check whether the class has a readObject( java.io.ObjectInputStream ) method.
static Object invokeMethod(Object obj, String methName, Class[] types, Object[] params)
          Invoke a method on the specified object.
static boolean isAssignableFrom(String generalClzName, Class specialClz)
          Do the isAssignableFrom check but without loading the class.
static boolean readObject(Method read_object, Object target, ObjectInputStream is)
          Call the readObject method.
static Object readResolve(Method read_resolve, Object target)
          Call the readResolve method.
static void writeObject(Method write_object, Object target, ObjectOutputStream os)
          Call the writeObject method.
static Object writeReplace(Method write_replace, Object target)
          Call the writeReplace method.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

invokeMethod

public static Object invokeMethod(Object obj,
                                  String methName,
                                  Class[] types,
                                  Object[] params)
Invoke a method on the specified object.
Parameters:
obj - The object on which to invoke the method.
methName - The name of the method.
types - The parameter types.
params - The parameter values.

getStubInstance

public static Object getStubInstance(Class clz,
                                     Object obj)
Return an instance of the specified stub and set the delegate to the one from the specified object.
Parameters:
clz - The stub class.
obj - The object to take the delegate from.
Returns:
The instantiated and initialized stub, null when an error occured.

isAssignableFrom

public static boolean isAssignableFrom(String generalClzName,
                                       Class specialClz)
Do the isAssignableFrom check but without loading the class.
Parameters:
generalClzName - The class which should be checked whether it is assignable from.
specialClz - The special class that is checked to be assignable to the general one.
Returns:
True when the classes are assignable.

hasWriteObjectMethod

public static boolean hasWriteObjectMethod(Class clz)
Check whether the class has a readObject( java.io.ObjectInputStream ) method.
Parameters:
clz - The class to check.
Returns:
True when a readObject() method was found, false otherwise.

getWriteObjectMethod

public static Method getWriteObjectMethod(Class clz)
Get the readObject( java.io.ObjectInputStream ) method from the class and set accessibility to true.
Parameters:
clz - The class to get the writeObject() method from.
Returns:
The writeObject method when found, null otherwise.

hasReadObjectMethod

public static boolean hasReadObjectMethod(Class clz)

getReadObjectMethod

public static Method getReadObjectMethod(Class clz)
Get the readObject( java.io.ObjectInputStream ) method from the class and set accessibility to true.
Parameters:
clz - The class to get the readObject() method from.
Returns:
The readObject method when found, null otherwise.

getReadResolveMethod

public static Method getReadResolveMethod(Class clz)
Get the readResolve() method from the class and set accessibility to true.
Parameters:
clz - The class to get the readResolve() method from.
Returns:
The readResolve method when found, null otherwise.

getWriteReplaceMethod

public static Method getWriteReplaceMethod(Class clz)
Get the writeReplace() method from the class and set accessibility to true.
Parameters:
clz - The class to get the writeReplace() method from.
Returns:
The writeReplace() method when found, null otherwise.

readObject

public static boolean readObject(Method read_object,
                                 Object target,
                                 ObjectInputStream is)
                          throws IOException,
                                 ClassNotFoundException
Call the readObject method.
Parameters:
read_object - The readObject() method.
target - The object on which to call the readObject() method.
is - The input stream to pass to the readObject() method.
Returns:
True if readObject was called, false otherwise.
Throws:
IOException - An exception that might occur during the readObject() call.

writeObject

public static void writeObject(Method write_object,
                               Object target,
                               ObjectOutputStream os)
                        throws IOException
Call the writeObject method.
Parameters:
write_object - The write_object method.
target - The object on which to call the writeObject() method.
os - The output stream to pass to the writeObject() method.
Throws:
IOException - That might occur during the writeReplace() call.

readResolve

public static Object readResolve(Method read_resolve,
                                 Object target)
                          throws ObjectStreamException
Call the readResolve method.
Parameters:
read_resolve - The readResolve() method.
target - The object on which to call the readResolve() method.
Returns:
The resolved object returned from readResolve().

writeReplace

public static Object writeReplace(Method write_replace,
                                  Object target)
                           throws ObjectStreamException
Call the writeReplace method.
Parameters:
write_replace - The writeReplace() method.
target - The object on which to call the writeReplace() method.
Returns:
The replaced object returned from writeReplace().