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<?> type, Set<Class<?>> interfaces, ProxyFactory proxyFactory)
          Add the given type to the set of interfaces, if the given ProxyFactory supports proxy generation for this type.
static Set<Class<?>> getAllInterfaces(Class<?> type)
          Get all interfaces of the given type.
static Set<Class<?>> 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 Class<?>[] makeTypesArray(Class<?> primaryType, Class<?>[] types)
          Create an array of types.
static Method readMethod(ObjectInputStream in)
          Read a Method from an ObjectInputStream.
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<Class<?>> 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
Since:
0.2

getAllInterfaces

public static Set<Class<?>> getAllInterfaces(Class<?> type)
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:
type - type to explore.
Returns:
a Set with all interfaces. The set may be empty.
Since:
0.2

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.
Since:
0.2

addIfClassProxyingSupportedAndNotObject

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

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

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:
0.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:
0.2

makeTypesArray

public static Class<?>[] makeTypesArray(Class<?> primaryType,
                                        Class<?>[] types)
Create an array of types.

Parameters:
primaryType - the primary types
types - the additional types (may be null)
Returns:
an array of all the given types with the primary type as first element
Since:
1.0


Copyright © 2005-2010 Codehaus. All Rights Reserved.