com.emarsys.ecommon.util
Class ReflectionsHelper

java.lang.Object
  extended by com.emarsys.ecommon.util.ReflectionsHelper

public class ReflectionsHelper
extends java.lang.Object

Helper-methods to get things via reflection Creationdate: Sep 12, 2007

Author:
Matthias Marchart, tristan, Michael "kULO" Kulovits

Field Summary
static java.lang.String GET
           
static java.util.Map<java.lang.Class<?>,java.lang.Class<?>> primitivesToWrapperTypes
          Map of primitive to wrapper classes
static java.lang.String SET
           
 
Constructor Summary
ReflectionsHelper()
           
 
Method Summary
static java.lang.Object callMethod(java.lang.Object target, java.lang.String methodName, java.lang.Class<?>[] parameterTypes, java.lang.Object[] args)
           
static java.lang.StackTraceElement getCaller()
           
static java.lang.StackTraceElement getCallerNotIn(java.lang.Class<?>... excludedClasses)
           
static java.lang.String getFieldName(java.lang.String methodName)
           
static java.lang.String getFirstToUpper(java.lang.String name)
           
static java.lang.String getGetterMethodName(java.lang.String fieldName)
           
static java.util.Set<java.lang.Class<?>> getInterfaces(java.lang.Class<?> clazz)
           
static java.lang.String getSetterMethodName(java.lang.String fieldName)
           
static
<A extends java.lang.annotation.Annotation>
A
getTypeAnnotations(java.lang.Class<?> clazz, java.lang.Class<A> annotationClass)
           Will search the passed Class as well as all super classes and interfaces for an Annotation of the passed annotation Class and return the first appearance.
static void inject(java.lang.Object inject, java.lang.String fieldName, java.lang.Object value)
          A simple injection mechanism, used to slam some mock objects to mimic the JBoss injection system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

primitivesToWrapperTypes

public static final java.util.Map<java.lang.Class<?>,java.lang.Class<?>> primitivesToWrapperTypes
Map of primitive to wrapper classes


GET

public static final java.lang.String GET
See Also:
Constant Field Values

SET

public static final java.lang.String SET
See Also:
Constant Field Values
Constructor Detail

ReflectionsHelper

public ReflectionsHelper()
Method Detail

getGetterMethodName

public static java.lang.String getGetterMethodName(java.lang.String fieldName)

getSetterMethodName

public static java.lang.String getSetterMethodName(java.lang.String fieldName)

getFieldName

public static java.lang.String getFieldName(java.lang.String methodName)

getFirstToUpper

public static java.lang.String getFirstToUpper(java.lang.String name)

inject

public static void inject(java.lang.Object inject,
                          java.lang.String fieldName,
                          java.lang.Object value)
                   throws java.lang.SecurityException,
                          java.lang.NoSuchFieldException,
                          java.lang.IllegalArgumentException,
                          java.lang.IllegalAccessException
A simple injection mechanism, used to slam some mock objects to mimic the JBoss injection system.

Throws:
java.lang.SecurityException
java.lang.NoSuchFieldException
java.lang.IllegalArgumentException
java.lang.IllegalAccessException

callMethod

public static java.lang.Object callMethod(java.lang.Object target,
                                          java.lang.String methodName,
                                          java.lang.Class<?>[] parameterTypes,
                                          java.lang.Object[] args)
                                   throws java.lang.SecurityException,
                                          java.lang.NoSuchMethodException,
                                          java.lang.IllegalArgumentException,
                                          java.lang.IllegalAccessException,
                                          java.lang.reflect.InvocationTargetException
Throws:
java.lang.SecurityException
java.lang.NoSuchMethodException
java.lang.IllegalArgumentException
java.lang.IllegalAccessException
java.lang.reflect.InvocationTargetException

getInterfaces

public static java.util.Set<java.lang.Class<?>> getInterfaces(java.lang.Class<?> clazz)
Returns:
a Set of Classes representing all interfaces implemented by the passed class of any of its super classes; never null.

getTypeAnnotations

public static <A extends java.lang.annotation.Annotation> A getTypeAnnotations(java.lang.Class<?> clazz,
                                                                               java.lang.Class<A> annotationClass)

Will search the passed Class as well as all super classes and interfaces for an Annotation of the passed annotation Class and return the first appearance.

First the passed class will be queried for the annotation, if nothing is found then its interfaces will be queried recursively one after another in the ordering returned by Class.getInterfaces() and after that, if not successful yet too, the super class of will be queried recursively.

NOTE that Annotations from interfaces are not Inherited!!! Thus this method makes a lot of sense if you need annotation inheritence both in super classes as well as interfaces.

Type Parameters:
A -
Parameters:
clazz -
annotationClass -
Returns:
the first Annotation of the passed type found on the passed clazz, its interfaces or super classes, or null if not present.

getCaller

public static java.lang.StackTraceElement getCaller()
Returns:

getCallerNotIn

public static java.lang.StackTraceElement getCallerNotIn(java.lang.Class<?>... excludedClasses)
Parameters:
excludedClasses -
Returns:


Copyright © 2010 emarsys AG. All Rights Reserved.