Class FieldUtils
- java.lang.Object
-
- org.apache.felix.scr.impl.inject.field.FieldUtils
-
public class FieldUtils extends Object
Utility methods for handling field injection.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FieldUtils.FieldSearchResult
Return type forsearchField(Class, String, ComponentLogger)
-
Constructor Summary
Constructors Constructor Description FieldUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static FieldUtils.FieldSearchResult
searchField(Class<?> componentClass, String fieldName, ComponentLogger logger)
Searches the field namedfieldName
in the giventargetClass
.static void
setField(Field f, Object component, Object value, ComponentLogger logger)
Set the field, type etc.static String
toString(Class<?> componentClass, Field field)
Return a string representation of the field
-
-
-
Method Detail
-
searchField
public static FieldUtils.FieldSearchResult searchField(Class<?> componentClass, String fieldName, ComponentLogger logger)
Searches the field namedfieldName
in the giventargetClass
. 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 aFieldSearchResult
is returned. If no field is found,FieldSearchResult#field
is set tonull
. If the field is found, but not usable (e.g. due to visibility restrictions),FieldSearchResult#usable
is set tofalse
.- Parameters:
targetClass
- The class of the componentfieldName
- The name of the fieldlogger
- A logger to log errors / problems- Returns:
- A field search result or
null
if an unexpected error occurred.
-
toString
public static String toString(Class<?> componentClass, Field field)
Return a string representation of the field- Parameters:
componentClass
- The component classfield
- The field- Returns:
- A string representation of the field
-
setField
public static void setField(Field f, Object component, Object value, ComponentLogger logger)
Set the field, type etc.- Parameters:
f
- The fieldcomponent
- The component instancevalue
- The value to setlogger
- The logger
-
-