Class ReflectionSetterInvoker

java.lang.Object
org.smartparam.engine.util.reflection.ReflectionSetterInvoker

public class ReflectionSetterInvoker extends Object

Utility for efficient setter invocation. Useful, when same setters should be find by reflection and invoked multiple times. Whole search magic is hidden in findSetter(java.lang.Class, java.lang.Object) method.

Author:
Adam Dubiel dubiel.adam@gmail.com
  • Constructor Details

    • ReflectionSetterInvoker

      public ReflectionSetterInvoker()
  • Method Details

    • invokeSetter

      public boolean invokeSetter(Object setterHostObject, Object forArg)
      Find and invoke setter on provided object.
      Parameters:
      setterHostObject - host Object
      forArg - argument object
      Returns:
      true if setter for argument found, false otherwise
    • findSetter

      public Method findSetter(Class<?> setterHostClass, Object forArg)

      Find setter method on host class (and its supertypes), that can handle setting provided argument. Setter does not have to be conventional JavaBeans setter, it is enough to be a single-argument void method that can accept provided argument, no naming convention is applied. This method uses setter caching, so subsequent calls to retrieve same setter are fast.

      Caution! Because search method does not follow JavaBeans convention, using it to find different setters for objects of same type will result in nondeterministic results!
      Parameters:
      setterHostClass - host Class
      forArg - argument object
      Returns:
      setter method