Class ReflectionUtils
- java.lang.Object
-
- org.ikasan.configurationService.util.ReflectionUtils
-
public class ReflectionUtils extends java.lang.ObjectReflection utility class. Ikasan Development Team.
-
-
Constructor Summary
Constructors Constructor Description ReflectionUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static java.util.Map<java.lang.String,java.lang.reflect.Field>getDeclaredFields(java.lang.Class cls)Get all fields of the given class and all parent classes regardless of access (public, protected, private, ..).static java.lang.reflect.MethodgetGetterMethod(java.lang.Class cls, java.lang.reflect.Field field)Return a getter method instance in the given class for the specified field.static java.util.Map<java.lang.String,java.lang.Object>getPropertiesIgnoringExceptions(java.lang.Object target)Get all non-static field names and values for the given target object.static java.lang.ObjectgetProperty(java.lang.Object target, java.lang.String fieldName)Get the value from the target object for the given field name.static java.lang.ClassgetPropertyType(java.lang.Object target, java.lang.String fieldName)Get the type for the given field name in the given target object.static java.lang.reflect.MethodgetSetterMethod(java.lang.Class cls, java.lang.reflect.Field field)Return a setter method instance for the given class for the specified field.static voidsetProperty(java.lang.Object target, java.lang.String fieldName, java.lang.Object value)Set property on target object based on the field name and given value.
-
-
-
Method Detail
-
getSetterMethod
public static java.lang.reflect.Method getSetterMethod(java.lang.Class cls, java.lang.reflect.Field field) throws java.lang.NoSuchMethodExceptionReturn a setter method instance for the given class for the specified field. NOTE if no valid method is found, including adherence to the JavaBean standards, then throw a NoSuchMethodException.- Parameters:
cls-field-- Returns:
- Throws:
java.lang.NoSuchMethodException
-
getProperty
public static java.lang.Object getProperty(java.lang.Object target, java.lang.String fieldName) throws java.lang.NoSuchFieldException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessExceptionGet the value from the target object for the given field name.- Parameters:
target-fieldName-- Returns:
- Throws:
java.lang.NoSuchFieldExceptionjava.lang.NoSuchMethodExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessException
-
getPropertyType
public static java.lang.Class getPropertyType(java.lang.Object target, java.lang.String fieldName) throws java.lang.NoSuchFieldException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessExceptionGet the type for the given field name in the given target object.- Parameters:
target-fieldName-- Returns:
- Throws:
java.lang.NoSuchFieldExceptionjava.lang.NoSuchMethodExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessException
-
getPropertiesIgnoringExceptions
public static java.util.Map<java.lang.String,java.lang.Object> getPropertiesIgnoringExceptions(java.lang.Object target)
Get all non-static field names and values for the given target object. Any failures to access fields or methods are logged, but not thrown.- Parameters:
target-- Returns:
-
setProperty
public static void setProperty(java.lang.Object target, java.lang.String fieldName, java.lang.Object value) throws java.lang.NoSuchFieldException, java.lang.NoSuchMethodException, java.lang.reflect.InvocationTargetException, java.lang.IllegalAccessExceptionSet property on target object based on the field name and given value.- Parameters:
target-fieldName-value-- Throws:
java.lang.NoSuchFieldExceptionjava.lang.NoSuchMethodExceptionjava.lang.reflect.InvocationTargetExceptionjava.lang.IllegalAccessException
-
getGetterMethod
public static java.lang.reflect.Method getGetterMethod(java.lang.Class cls, java.lang.reflect.Field field) throws java.lang.NoSuchMethodExceptionReturn a getter method instance in the given class for the specified field. NOTE if no valid method is found, including adherence to the JavaBean standards, then throw a NoSuchMethodException.- Parameters:
cls-field-- Returns:
- Throws:
java.lang.NoSuchMethodException
-
getDeclaredFields
protected static java.util.Map<java.lang.String,java.lang.reflect.Field> getDeclaredFields(java.lang.Class cls)
Get all fields of the given class and all parent classes regardless of access (public, protected, private, ..).- Parameters:
cls-- Returns:
- Map
-
-