Class FieldUtils


  • public class FieldUtils
    extends Object
    Utility methods for handling field injection.
    • Constructor Detail

      • FieldUtils

        public FieldUtils()
    • Method Detail

      • searchField

        public static FieldUtils.FieldSearchResult searchField​(Class<?> componentClass,
                                                               String fieldName,
                                                               ComponentLogger logger)
        Searches the field named 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.

        Parameters:
        targetClass - The class of the component
        fieldName - The name of the field
        logger - 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 class
        field - 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 field
        component - The component instance
        value - The value to set
        logger - The logger