net.sourceforge.annovalidator.util
Class ReflectionUtil

java.lang.Object
  extended by net.sourceforge.annovalidator.util.ReflectionUtil

public class ReflectionUtil
extends java.lang.Object

Utility class for performing common reflection operations with more sensible error handling.


Constructor Summary
ReflectionUtil()
           
 
Method Summary
static java.lang.reflect.Method determineAnnotationParameterMethod(java.lang.annotation.Annotation annotation, java.lang.String parameterName)
          Determines the Method on annotation that matches parameterName.
static java.lang.Class<?> determineAnnotationParameterType(java.lang.annotation.Annotation annotation, java.lang.String parameterName)
          Determines the type of a parameter (implemented as a Method) on an Annotation.
static java.lang.Object determineAnnotationParameterValue(java.lang.annotation.Annotation annotation, java.lang.String parameterName)
          Determines the value of a particular parameter in an Annotation.
static java.lang.Object determineFieldValue(java.lang.Object object, java.lang.reflect.Field field)
          Determines the value of field in object.
static java.lang.Object determineFieldValue(java.lang.Object object, java.lang.String fieldName)
          Returns the value of the Field named fieldName on object.
static java.lang.annotation.Annotation getAnnotation(java.lang.reflect.Field field, java.lang.Class annotationClass)
           
static java.lang.reflect.Field getField(java.lang.Object object, java.lang.String fieldName)
          Returns the Field on object that matches fieldName.
static boolean isAnnotationParameterPresent(java.lang.annotation.Annotation annotation, java.lang.String parameterName)
          Determines whether annotation has a parameter named parameterName.
static boolean isAnnotationPresent(java.lang.Class<?> objectClass, java.lang.Class<ValidationStep> annotationType)
          Determines whether objectClass is annotated with annotationType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionUtil

public ReflectionUtil()
Method Detail

determineAnnotationParameterMethod

public static java.lang.reflect.Method determineAnnotationParameterMethod(java.lang.annotation.Annotation annotation,
                                                                          java.lang.String parameterName)
Determines the Method on annotation that matches parameterName.

Parameters:
annotation - The Annotation to examine.
parameterName - The name of the Method to find.
Returns:
The Method on annotation whose name matches parameterName.
Throws:
ValidatorAnnotationException - If parameterName cannot be accessed or does not exist in annotation.

determineAnnotationParameterValue

public static java.lang.Object determineAnnotationParameterValue(java.lang.annotation.Annotation annotation,
                                                                 java.lang.String parameterName)
Determines the value of a particular parameter in an Annotation.

Parameters:
annotation - The Annotation to inspect.
parameterName - The name of the parameter to fetch.
Returns:
The value of the parameterName parameter in annotation.
Throws:
ValidatorAnnotationException - If parameterName cannot be accessed or does not exist in annotation.

determineAnnotationParameterType

public static java.lang.Class<?> determineAnnotationParameterType(java.lang.annotation.Annotation annotation,
                                                                  java.lang.String parameterName)
Determines the type of a parameter (implemented as a Method) on an Annotation.

Parameters:
annotation - The Annotation containing the parameter.
parameterName - The name of the parameter whose type needs to be determined.
Returns:
The return type of the method identified by parameterName in annotation.

determineFieldValue

public static java.lang.Object determineFieldValue(java.lang.Object object,
                                                   java.lang.reflect.Field field)
Determines the value of field in object.

Parameters:
object - The Object that contains field.
field - The Field that we want to know the value of.
Returns:
The value of field.
Throws:
ValidatorFieldException - If field cannot be read.

determineFieldValue

public static java.lang.Object determineFieldValue(java.lang.Object object,
                                                   java.lang.String fieldName)
Returns the value of the Field named fieldName on object.

Parameters:
object - The Object containing the Field.
fieldName - The name of the Field.
Returns:
The value of the Field named fieldName on object.

getField

public static java.lang.reflect.Field getField(java.lang.Object object,
                                               java.lang.String fieldName)
Returns the Field on object that matches fieldName.

Parameters:
object - The object that contains the field.
fieldName - The name of the field to return.
Returns:
A Field matching fieldName from object.

isAnnotationParameterPresent

public static boolean isAnnotationParameterPresent(java.lang.annotation.Annotation annotation,
                                                   java.lang.String parameterName)
Determines whether annotation has a parameter named parameterName.

Parameters:
annotation - The Annotation to examine.
parameterName - The name of the parameter to check for.
Returns:
true if annotation has a parameter named parameterName, otherwise false.

isAnnotationPresent

public static boolean isAnnotationPresent(java.lang.Class<?> objectClass,
                                          java.lang.Class<ValidationStep> annotationType)
Determines whether objectClass is annotated with annotationType. Behaves the same was as Class.isAnnotationPresent(Class), but checks declared annotations as well as non-declared.

Parameters:
objectClass - The class to check for an Annotation.
annotationType - The Class of the Annotation to check for.
Returns:
true if an Annotation of type annotationClass is found on objectClass, otherwise false.

getAnnotation

public static java.lang.annotation.Annotation getAnnotation(java.lang.reflect.Field field,
                                                            java.lang.Class annotationClass)


Copyright © 2008. All Rights Reserved.