com.thoughtworks.proxy.kit
Class ReflectionUtils

java.lang.Object
  extended by com.thoughtworks.proxy.kit.ReflectionUtils

public class ReflectionUtils
extends Object

Helper class for introspecting interface and class hierarchies.

Since:
0.2
Author:
Aslak Hellesøy, Jörg Schaible

Field Summary
static Method equals
          the Object.equals(Object) method.
static Method hashCode
          the Object.hashCode() method.
static Method toString
          the Object.toString() method.
 
Method Summary
static void addIfClassProxyingSupportedAndNotObject(Class clazz, Set interfaces, ProxyFactory proxyFactory)
          Add the given type to the set of interfaces, if the given ProxyFactory supports proxy generation for this type.
static Set getAllInterfaces(Class clazz)
          Get all interfaces of the given type.
static Set getAllInterfaces(Object[] objects)
          Get all the interfaces implemented by a list of objects.
static Method getMatchingMethod(Class type, String methodName, Object[] args)
          Get the method of the given type, that has matching parameter types to the given arguments.
static Class getMostCommonSuperclass(Object[] objects)
          Get most common superclass for all given objects.
static Method readMethod(ObjectInputStream in)
          Read a Method from an ObjectInputStream.
static Class[] toClassArray(Collection collection)
          Convert the collection of class types to an array of class types.
static void writeMethod(ObjectOutputStream out, Method method)
          Write a Method into an ObjectOutputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

equals

public static final Method equals
the Object.equals(Object) method.


hashCode

public static final Method hashCode
the Object.hashCode() method.


toString

public static final Method toString
the Object.toString() method.

Method Detail

getAllInterfaces

public static Set getAllInterfaces(Object[] objects)
Get all the interfaces implemented by a list of objects.

Parameters:
objects - the list of objects to consider.
Returns:
an set of interfaces. The set may be empty

getAllInterfaces

public static Set getAllInterfaces(Class clazz)
Get all interfaces of the given type. If the type is a class, the returned set contains any interface, that is implemented by the class. If the type is an interface, the all superinterfaces and the interface itself are included.

Parameters:
clazz - type to explore.
Returns:
a Set with all interfaces. The set may be empty.

getMostCommonSuperclass

public static Class getMostCommonSuperclass(Object[] objects)
Get most common superclass for all given objects.

Parameters:
objects - the array of objects to consider.
Returns:
the superclass or Void.class for an empty array.

addIfClassProxyingSupportedAndNotObject

public static void addIfClassProxyingSupportedAndNotObject(Class clazz,
                                                           Set interfaces,
                                                           ProxyFactory proxyFactory)
Add the given type to the set of interfaces, if the given ProxyFactory supports proxy generation for this type.

Parameters:
clazz - the class type (Object.class will be ignored)
interfaces - the set of interfaces
proxyFactory - the ProxyFactory in use

toClassArray

public static Class[] toClassArray(Collection collection)
Convert the collection of class types to an array of class types.

Parameters:
collection - with class types
Returns:
an array of class types

getMatchingMethod

public static Method getMatchingMethod(Class type,
                                       String methodName,
                                       Object[] args)
                                throws NoSuchMethodException
Get the method of the given type, that has matching parameter types to the given arguments.

Parameters:
type - the type
methodName - the name of the method to search
args - the arguments to match
Returns:
the matching Method
Throws:
NoSuchMethodException - if no matching Method exists
Since:
0.2

writeMethod

public static void writeMethod(ObjectOutputStream out,
                               Method method)
                        throws IOException
Write a Method into an ObjectOutputStream.

Parameters:
out - the stream
method - the Method to write
Throws:
IOException - if writing causes a problem
Since:
1.2

readMethod

public static Method readMethod(ObjectInputStream in)
                         throws IOException,
                                ClassNotFoundException
Read a Method from an ObjectInputStream.

Parameters:
in - the stream
Returns:
the read Method
Throws:
IOException - if reading causes a problem
ClassNotFoundException - if class types from objects of the InputStream cannot be found
InvalidObjectException - if the Method cannot be found
Since:
1.2