public class FieldUtils
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
FieldUtils.FieldSearchResult
Return type for
searchField(Class, String, ComponentLogger) |
Constructor and Description |
---|
FieldUtils() |
Modifier and Type | Method and Description |
---|---|
private static FieldUtils.FieldSearchResult |
accept(java.lang.Class<?> componentClass,
java.lang.reflect.Field field,
boolean acceptPrivate,
boolean acceptPackage,
ComponentLogger logger)
This method checks whether the found field is acceptable (= usable)
for the component instance.
|
private static FieldUtils.FieldSearchResult |
getField(java.lang.Class<?> componentClass,
java.lang.Class<?> targetClass,
java.lang.String fieldName,
boolean acceptPrivate,
boolean acceptPackage,
ComponentLogger logger)
Finds the field named
fieldName field in the given
targetClass . |
static FieldUtils.FieldSearchResult |
searchField(java.lang.Class<?> componentClass,
java.lang.String fieldName,
ComponentLogger logger)
Searches the field named
fieldName in the given
targetClass . |
private static void |
setAccessible(java.lang.reflect.Field field)
Make the field accessible
|
static void |
setField(java.lang.reflect.Field f,
java.lang.Object component,
java.lang.Object value,
ComponentLogger logger)
Set the field, type etc.
|
static java.lang.String |
toString(java.lang.Class<?> componentClass,
java.lang.reflect.Field field)
Return a string representation of the field
|
public static FieldUtils.FieldSearchResult searchField(java.lang.Class<?> componentClass, java.lang.String fieldName, ComponentLogger logger)
fieldName
in the given
targetClass
. If the target class has no acceptable field
the class hierarchy is traversed until a field is found or the root
of the class hierarchy is reached without finding a field.
If an unexpected error occurs while searching, null
is
returned. In all other cases a FieldSearchResult
is
returned. If no field is found, FieldSearchResult#field
is set to null
. If the field is found, but not usable
(e.g. due to visibility restrictions), FieldSearchResult#usable
is set to false
.
targetClass
- The class of the componentfieldName
- The name of the fieldlogger
- A logger to log errors / problemsnull
if an unexpected
error occurred.private static FieldUtils.FieldSearchResult getField(java.lang.Class<?> componentClass, java.lang.Class<?> targetClass, java.lang.String fieldName, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger) throws java.lang.reflect.InvocationTargetException
fieldName
field in the given
targetClass
. If the target class has no acceptable field
the class hierarchy is traversed until a field is found or the root
of the class hierarchy is reached without finding a field.componentClass
- The class of the component (for logging)targetClass
- The class in which to look for the methodfieldName
- The name of the fieldacceptPrivate
- true
if private fields should be
considered.acceptPackage
- true
if package private fields should
be considered.logger
- For error loggingFieldSearchResult
is returned.
If the field is not found, null
is returned.java.lang.reflect.InvocationTargetException
- If an unexpected Throwable is caught
trying to find the requested field.private static FieldUtils.FieldSearchResult accept(java.lang.Class<?> componentClass, java.lang.reflect.Field field, boolean acceptPrivate, boolean acceptPackage, ComponentLogger logger)
FieldSearchResult
with the usable flag set to
true
if the field is not static and
acceptPrivate
is true
acceptPackage
is true
If the field is usable, this method makes the field accessible.
If the field is not usable, a FieldSearchResult
with the usable
flag set to false
is returned and an error is logged with
the provided logger.
componentClass
- The class of the component,.field
- The field to checkacceptPrivate
- Whether a private field is acceptableacceptPackage
- Whether a package private field is acceptablelogger
- The logger for error loggingnull
public static java.lang.String toString(java.lang.Class<?> componentClass, java.lang.reflect.Field field)
componentClass
- The component classfield
- The fieldprivate static void setAccessible(java.lang.reflect.Field field)
field
- The fieldpublic static void setField(java.lang.reflect.Field f, java.lang.Object component, java.lang.Object value, ComponentLogger logger)
f
- The fieldcomponent
- The component instancevalue
- The value to setlogger
- The logger