Class PathHelper


  • public class PathHelper
    extends Object
    Simple class to look up a property path in a java object
    Author:
    Matteo a.k.a. fugerit
    • Field Detail

      • CONTINUE_ON_NULL

        public static final boolean CONTINUE_ON_NULL
        Constant for continuing on empty path value
        See Also:
        Constant Field Values
      • EXIT_ON_NULL

        public static final boolean EXIT_ON_NULL
        Constant for stopping on empty path value
        See Also:
        Constant Field Values
    • Method Detail

      • initEmptyField

        public static Object initEmptyField​(String property,
                                            Object target)
      • initEmptyField

        public static Object initEmptyField​(String property,
                                            Object target,
                                            FacadeImplFinder facadeImplFinder)
        Init a property on object if empty
        Parameters:
        property - the property to init
        target - the target object
        facadeImplFinder - facade for finding target property type
        Returns:
        the object used to initialized the empty field
        Throws:
        ConfigRuntimeException - may throw ConfigRuntimeException see SafeFunction
      • bindInit

        public static Object bindInit​(String path,
                                      Object target)
        Init a path in an object using initEmptyField() on any property in the path.
        Parameters:
        path - the path in the object
        target - the target object
        Returns:
        the last created object
      • bind

        public static boolean bind​(String path,
                                   Object target,
                                   Object value,
                                   Class<?> paramType,
                                   boolean tryInit)
        Bind a value to a path in an object.
        Parameters:
        path - the path
        target - the target object
        value - the value to set
        paramType - the property class type
        tryInit - if true will try to init any null object in path
        Returns:
        if the binding is successful
      • bind

        public static boolean bind​(String path,
                                   Object target,
                                   Object value,
                                   Class<?> paramType,
                                   boolean tryInit,
                                   FacadeImplFinder facadeImplFinder)
        Bind a value to a path in an object.
        Parameters:
        path - the path
        target - the target object
        value - the value to set
        paramType - the property class type
        tryInit - if true will try to init any null object in path
        facadeImplFinder - facade for finding implementing class
        Returns:
        if the binding is successful
      • bind

        public static boolean bind​(String path,
                                   Object target,
                                   Object value)
        Bind a value to a path in an object
        Parameters:
        path - the path
        target - the target object
        value - the value to set
        Returns:
        if the binding is successful
      • lookupMethod

        public static Object lookupMethod​(String path,
                                          Object target,
                                          boolean continueOnNull)
        Lookup for a value by full method value (no get prefix is assumed) If a method in path method is not found will raise exception
        Parameters:
        path - the path in the object (ex. prop1.prop2)
        target - the target object
        continueOnNull - true to continue on null value and eventually raise an exception, false to return null when a null is encountered
        Returns:
        the value found in the path
      • lookupMethod

        public static Object lookupMethod​(String path,
                                          Object target)
        Lookup for a value by full method value (no get prefix is assumed) If a method in path method is not found will raise exception If a method in path return null will stop and return null
        Parameters:
        path - the path in the object (ex. prop1.prop2)
        target - the target object
        Returns:
        the value found in the path
      • lookup

        public static Object lookup​(String path,
                                    Object target,
                                    boolean continueOnNull)
        Lookup for a value by getter methods
        Parameters:
        path - the path in the object (ex. prop1.prop2)
        target - the target object
        continueOnNull - true to continue on null value and eventually raise an exception, false to return null when a null is encountered
        Returns:
        the value found in the path
      • lookup

        public static Object lookup​(String path,
                                    Object target)
        Lookup for a value by getter methods ( return null when a null is encountered ) If a method in path method is not found will raise exception
        Parameters:
        path - the path in the object (ex. prop1.prop2)
        target - the target object
        Returns:
        the value found in the path
      • lookupContinueOnNull

        public static Object lookupContinueOnNull​(String path,
                                                  Object target)
        Lookup for a value by getter methods ( will continue on null value and eventually raise an exception) If a method in path method is not found will raise exception If a method in path return null will stop and return null
        Parameters:
        path - the path in the object (ex. prop1.prop2)
        target - the target object
        Returns:
        the value found in the path