org.openmrs.util
Class Reflect

java.lang.Object
  extended by org.openmrs.util.Reflect

public class Reflect
extends java.lang.Object

This class has convenience methods to find the fields on a class and superclass as well as methods to check the class type of members in a collection


Constructor Summary
Reflect(java.lang.Class parametrizedClass)
           
 
Method Summary
static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class<?> fieldClass)
          This method return all the fields (including private) from the given class and its super classes.
 java.util.List<java.lang.reflect.Field> getInheritedFields(java.lang.Class subClass)
          This method return all the fields (including private) until the given parameterized class
 boolean hasField(java.lang.reflect.Field field)
           
static boolean isCollection(java.lang.Class<?> fieldClass)
           
static boolean isCollection(java.lang.Object object)
           
 boolean isCollectionField(java.lang.reflect.Field field)
          This method validate the given field is Collection and the elements should be of parameterized type
 boolean isSuperClass(java.lang.Class subClass)
           
 boolean isSuperClass(java.lang.Object object)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Reflect

public Reflect(java.lang.Class parametrizedClass)
Parameters:
parametrizedClass - Class
Expected behavior:
throw exception when null is passed
Method Detail

isCollection

public static boolean isCollection(java.lang.Class<?> fieldClass)
Parameters:
fieldClass -
Returns:
true if, given fieldClass is Collection otherwise returns false
Expected behavior:
return true if given fieldClass is Collection class, return false if given fieldClass is not a Collection class

isCollection

public static boolean isCollection(java.lang.Object object)
Parameters:
object - Object
Returns:
true if, given object is Collection otherwise returns false
Expected behavior:
return true if given object is Collection class, return false if given object is not a Collection

getAllFields

public static java.util.List<java.lang.reflect.Field> getAllFields(java.lang.Class<?> fieldClass)
This method return all the fields (including private) from the given class and its super classes.

Parameters:
fieldClass - Class
Returns:
List
Expected behavior:
return all fields include private and super classes

isSuperClass

public boolean isSuperClass(java.lang.Class subClass)
Parameters:
subClass - Class
Returns:
true if, given subClass is accessible from the parameterized class
Expected behavior:
return true if given subClass is accessible from given parameterized class, return false if given subClass is not accessible from given parameterized class

isSuperClass

public boolean isSuperClass(java.lang.Object object)
Parameters:
object - Object
Returns:
true if, given object is accessible from the parameterized class
Expected behavior:
return true if given object is accessible from given parameterized class, return false if given object is not accessible from given parameterized class

isCollectionField

public boolean isCollectionField(java.lang.reflect.Field field)
This method validate the given field is Collection and the elements should be of parameterized type

Parameters:
field - Field
Returns:
boolean
Expected behavior:
return true if given field is Collection and its element type is given parameterized class type, return false if given field is not a Collection, return false if given field is Collection and element type is other than given parameterized class type

getInheritedFields

public java.util.List<java.lang.reflect.Field> getInheritedFields(java.lang.Class subClass)
This method return all the fields (including private) until the given parameterized class

Parameters:
subClass - Class
Returns:
List
Expected behavior:
return only the sub class fields of given parameterized class

hasField

public boolean hasField(java.lang.reflect.Field field)
Parameters:
field -
Returns:
true if, given field is declared in parameterized class or its sub classes

OpenMRS-1.7.x

Generated Apr 27 2012 10:06 PM. NOTE - these libraries are in active development and subject to change