org.jboss.webbeans.util
Class Reflections

java.lang.Object
  extended by org.jboss.webbeans.util.Reflections

public class Reflections
extends java.lang.Object

Utility class for static reflection-type operations

Author:
Pete Muir

Nested Class Summary
static class Reflections.HierarchyDiscovery
           
 
Constructor Summary
Reflections()
           
 
Method Summary
static java.lang.reflect.Type[] getActualTypeArguments(java.lang.Class<?> clazz)
          Gets the actual type arguments of a class
static java.lang.Object getAndWrap(java.lang.reflect.Field field, java.lang.Object target)
          Gets value of a field and wraps exceptions
static java.lang.Object getAndWrap(java.lang.String fieldName, java.lang.Object target)
           
static
<T> java.lang.reflect.Constructor<T>
getDeclaredConstructor(java.lang.Class<T> clazz, java.lang.Class<?>... parameterTypes)
          Gets a constructor with matching parameter types
static java.lang.String getPropertyName(java.lang.reflect.Method method)
          Gets the property name from a getter method
static java.lang.Object invokeAndWrap(java.lang.reflect.Method method, java.lang.Object instance, java.lang.Object... parameters)
          Invokes a method and wraps exceptions
static java.lang.Object invokeAndWrap(java.lang.String methodName, java.lang.Object instance, java.lang.Object... parameters)
           
static boolean isAbstract(java.lang.Class<?> clazz)
          Checks if clazz is abstract
static boolean isArrayType(java.lang.Class<?> rawType)
          Checks if raw type is array type
static boolean isBindings(java.lang.annotation.Annotation binding)
          Deprecated. 
static boolean isFinal(java.lang.Class<?> clazz)
          Checks if class is final
static boolean isFinal(java.lang.reflect.Member member)
          Checks if member is final
static boolean isNonMemberInnerClass(java.lang.Class<?> clazz)
          Checks if class is a non-static inner one
static boolean isParameterizedType(java.lang.Class<?> type)
          Checks if type is parameterized type
static boolean isPrimitive(java.lang.Class<?> type)
          Checks if type is primitive
static boolean isProxy(java.lang.Object instance)
          Indicates if an instance is a Javassist proxy
static boolean isSerializable(java.lang.Class<?> clazz)
           
static boolean isStatic(java.lang.Class<?> type)
          Checks if type is static
static boolean isStatic(java.lang.reflect.Member member)
          Checks if member is static
static boolean isTransient(java.lang.reflect.Member member)
           
static boolean isTypeOrAnyMethodFinal(java.lang.Class<?> type)
          Checks if type or member is final
static java.lang.reflect.Method lookupMethod(java.lang.reflect.Method method, java.lang.Object instance)
          Looks up a method in the type hierarchy of an instance
static java.lang.reflect.Method lookupMethod(java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object instance)
          Looks up a method in the type hierarchy of an instance
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflections

public Reflections()
Method Detail

getPropertyName

public static java.lang.String getPropertyName(java.lang.reflect.Method method)
Gets the property name from a getter method

Parameters:
method - The getter method
Returns:
The name of the property. Returns null if method wasn't JavaBean getter-styled

isFinal

public static boolean isFinal(java.lang.Class<?> clazz)
Checks if class is final

Parameters:
clazz - The class to check
Returns:
True if final, false otherwise

isFinal

public static boolean isFinal(java.lang.reflect.Member member)
Checks if member is final

Parameters:
member - The member to check
Returns:
True if final, false otherwise

isTypeOrAnyMethodFinal

public static boolean isTypeOrAnyMethodFinal(java.lang.Class<?> type)
Checks if type or member is final

Parameters:
type - Type or member
Returns:
True if final, false otherwise

isPrimitive

public static boolean isPrimitive(java.lang.Class<?> type)
Checks if type is primitive

Parameters:
type - Type to check
Returns:
True if primitive, false otherwise

isStatic

public static boolean isStatic(java.lang.Class<?> type)
Checks if type is static

Parameters:
type - Type to check
Returns:
True if static, false otherwise

isStatic

public static boolean isStatic(java.lang.reflect.Member member)
Checks if member is static

Parameters:
member - Member to check
Returns:
True if static, false otherwise

isTransient

public static boolean isTransient(java.lang.reflect.Member member)

isAbstract

public static boolean isAbstract(java.lang.Class<?> clazz)
Checks if clazz is abstract

Parameters:
clazz - Class to check
Returns:
True if abstract, false otherwise

isNonMemberInnerClass

public static boolean isNonMemberInnerClass(java.lang.Class<?> clazz)
Checks if class is a non-static inner one

Parameters:
clazz - Class to Check
Returns:
True if static, false otherwise

getDeclaredConstructor

public static <T> java.lang.reflect.Constructor<T> getDeclaredConstructor(java.lang.Class<T> clazz,
                                                                          java.lang.Class<?>... parameterTypes)
Gets a constructor with matching parameter types

Type Parameters:
T - The type
Parameters:
clazz - The class
parameterTypes - The parameter types
Returns:
The matching constructor. Null is returned if none is found

getActualTypeArguments

public static java.lang.reflect.Type[] getActualTypeArguments(java.lang.Class<?> clazz)
Gets the actual type arguments of a class

Parameters:
clazz - The class to examine
Returns:
The type arguments

isArrayType

public static boolean isArrayType(java.lang.Class<?> rawType)
Checks if raw type is array type

Parameters:
rawType - The raw type to check
Returns:
True if array, false otherwise

isParameterizedType

public static boolean isParameterizedType(java.lang.Class<?> type)
Checks if type is parameterized type

Parameters:
type - The type to check
Returns:
True if parameterized, false otherwise

invokeAndWrap

public static java.lang.Object invokeAndWrap(java.lang.reflect.Method method,
                                             java.lang.Object instance,
                                             java.lang.Object... parameters)
Invokes a method and wraps exceptions

Parameters:
method - The method to invoke
instance - The instance to invoke on
parameters - The parameters
Returns:
The return value

invokeAndWrap

public static java.lang.Object invokeAndWrap(java.lang.String methodName,
                                             java.lang.Object instance,
                                             java.lang.Object... parameters)

getAndWrap

public static java.lang.Object getAndWrap(java.lang.reflect.Field field,
                                          java.lang.Object target)
Gets value of a field and wraps exceptions

Parameters:
field - The field to set on
target - The instance to set on
Returns:
The value to set

getAndWrap

public static java.lang.Object getAndWrap(java.lang.String fieldName,
                                          java.lang.Object target)

lookupMethod

public static java.lang.reflect.Method lookupMethod(java.lang.reflect.Method method,
                                                    java.lang.Object instance)
Looks up a method in the type hierarchy of an instance

Parameters:
method - The method to look for
instance - The instance to start from
Returns:
The method found
Throws:
java.lang.IllegalArgumentException - if the method is not found

lookupMethod

public static java.lang.reflect.Method lookupMethod(java.lang.String methodName,
                                                    java.lang.Class<?>[] parameterTypes,
                                                    java.lang.Object instance)
                                             throws java.lang.NoSuchMethodException
Looks up a method in the type hierarchy of an instance

Parameters:
method - The method to look for
instance - The instance to start from
Returns:
the method
Throws:
java.lang.NoSuchMethodException - if the method is not found

isProxy

public static boolean isProxy(java.lang.Object instance)
Indicates if an instance is a Javassist proxy

Parameters:
instance - The instance to examine
Returns:
True if proxy, false otherwise

isBindings

@Deprecated
public static boolean isBindings(java.lang.annotation.Annotation binding)
Deprecated. 

Checks the bindingType to make sure the annotation was declared properly as a binding type (annotated with @BindingType).

Parameters:
binding - The binding type to check
Returns:
true only if the annotation is really a binding type

isSerializable

public static boolean isSerializable(java.lang.Class<?> clazz)


Copyright © 2011. All Rights Reserved.