Tuscany Core

org.apache.tuscany.core.config
Class JavaIntrospectionHelper

java.lang.Object
  extended by org.apache.tuscany.core.config.JavaIntrospectionHelper

public class JavaIntrospectionHelper
extends Object

Implements various reflection-related operations

Version:
$Rev: 408581 $ $Date: 2006-05-21 23:34:24 -0700 (Sun, 21 May 2006) $

Method Summary
static boolean exactMethodMatch(Method method1, Method method2)
          Determines if two methods "match" - that is, they have the same method names and exact parameter types (one is not a supertype of the other)
static Field findClosestMatchingField(String name, Class type, Set<Field> fields)
          Finds the closest matching field with the given name, that is, a field of the exact specified type or, alternately, of a supertype.
static Method findClosestMatchingMethod(String name, Class[] types, Set<Method> methods)
          Finds the closest matching method with the given name, that is, a method taking the exact parameter types or, alternately, parameter supertypes.
static Field findMultiplicityFieldByName(String name, Set<Field> fields)
          Searches a collection of fields for one that matches by name and has a multiplicity type.
static Method findMultiplicityMethodByName(String name, Set<Method> methods)
          Searches a collection of method for one that matches by name and has single parameter of a multiplicity type.
static Set<Field> getAllFields(Class pClass)
          Returns a collection of public, private, protected, or default fields declared by a class or one of its supertypes
static Set<Field> getAllPublicAndProtectedFields(Class clazz)
          Returns a collection of public, and protected fields declared by a class or one of its supertypes
static Set<Method> getAllUniqueMethods(Class clazz)
          Returns a collection of public, private, protected, or default methods declared by a class or one of its supertypes.
static String getBaseName(Class<?> implClass)
          Returns the simple name of a class - i.e.
static AccessibleObject getBeanProperty(Class clazz, String propertName, Class[] paramTypes)
          Returns a field or method defined in the given class or its superclasses matching a literal name and parameter types

This method can potentially be expensive as reflection information is not cached.

static
<T> Constructor<T>
getDefaultConstructor(Class<T> clazz)
           
static List<? extends Type> getGenerics(Type genericType)
          Returns the generic types represented in the given type.
static boolean isImmutable(Class clazz)
           
static Class loadClass(String pName)
          Loads a class corresponding to the class name using the current context class loader.
static String toGetter(String name)
          Takes a property name and converts it to a getter method name according to JavaBean conventions.
static String toPropertyName(String name)
          Takes a setter or getter method name and converts it to a property name according to JavaBean conventions.
static String toSetter(String name)
          Takes a property name and converts it to a setter method name according to JavaBean conventions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getAllFields

public static Set<Field> getAllFields(Class pClass)
Returns a collection of public, private, protected, or default fields declared by a class or one of its supertypes


getAllPublicAndProtectedFields

public static Set<Field> getAllPublicAndProtectedFields(Class clazz)
Returns a collection of public, and protected fields declared by a class or one of its supertypes


getAllUniqueMethods

public static Set<Method> getAllUniqueMethods(Class clazz)
Returns a collection of public, private, protected, or default methods declared by a class or one of its supertypes. Note that overriden methods will not be returned in the collection (i.e. only the method override will be).

This method can potentially be expensive as reflection information is not cached. It is assumed that this method will be used during a configuration phase.


findClosestMatchingField

public static Field findClosestMatchingField(String name,
                                             Class type,
                                             Set<Field> fields)
Finds the closest matching field with the given name, that is, a field of the exact specified type or, alternately, of a supertype.

Parameters:
name - the name of the field
type - the field type
fields - the collection of fields to search
Returns:
the matching field or null if not found

findClosestMatchingMethod

public static Method findClosestMatchingMethod(String name,
                                               Class[] types,
                                               Set<Method> methods)
Finds the closest matching method with the given name, that is, a method taking the exact parameter types or, alternately, parameter supertypes.

Parameters:
name - the name of the method
types - the method parameter types
methods - the collection of methods to search
Returns:
the matching method or null if not found

findMultiplicityFieldByName

public static Field findMultiplicityFieldByName(String name,
                                                Set<Field> fields)
Searches a collection of fields for one that matches by name and has a multiplicity type. i.e. a List or Array of interfaces

Returns:
a matching field or null

findMultiplicityMethodByName

public static Method findMultiplicityMethodByName(String name,
                                                  Set<Method> methods)
Searches a collection of method for one that matches by name and has single parameter of a multiplicity type. i.e. a List or Array of interfaces

Returns:
a matching method or null

getBeanProperty

public static AccessibleObject getBeanProperty(Class clazz,
                                               String propertName,
                                               Class[] paramTypes)
Returns a field or method defined in the given class or its superclasses matching a literal name and parameter types

This method can potentially be expensive as reflection information is not cached. It is assumed that this method will be used during a configuration phase.

Parameters:
clazz - the class to introspect
propertName - the literal name of the property (i.e. JavaBean conventions are not applied)
paramTypes - the parameter types for a method or null for fields or methods with no parameters
Returns:
the field, method or null

exactMethodMatch

public static boolean exactMethodMatch(Method method1,
                                       Method method2)
Determines if two methods "match" - that is, they have the same method names and exact parameter types (one is not a supertype of the other)


getDefaultConstructor

public static <T> Constructor<T> getDefaultConstructor(Class<T> clazz)
                                            throws NoSuchMethodException
Throws:
NoSuchMethodException

loadClass

public static Class loadClass(String pName)
                       throws ClassNotFoundException
Loads a class corresponding to the class name using the current context class loader.

Throws:
ClassNotFoundException - if the class was not found on the classpath

getBaseName

public static String getBaseName(Class<?> implClass)
Returns the simple name of a class - i.e. the class name devoid of its package qualifier

Parameters:
implClass -

isImmutable

public static boolean isImmutable(Class clazz)

toGetter

public static String toGetter(String name)
Takes a property name and converts it to a getter method name according to JavaBean conventions. For example, property foo is returned as getFoo


toPropertyName

public static String toPropertyName(String name)
Takes a setter or getter method name and converts it to a property name according to JavaBean conventions. For example, setFoo(var) is returned as property foo


toSetter

public static String toSetter(String name)
Takes a property name and converts it to a setter method name according to JavaBean conventions. For example, the property foo is returned as setFoo(var)


getGenerics

public static List<? extends Type> getGenerics(Type genericType)
Returns the generic types represented in the given type. Usage as follows:

// to return the generic type of a field: JavaIntrospectionHelper.getGenerics(field.getGenericType());

// to return the generic types for the first parameter of a method: JavaIntrospectionHelper.getGenerics(m.getGenericParameterTypes()[0];);

Returns:
the generic types in order of declaration or an empty array if the type is not genericized

Tuscany Core

-