Interface BeanStyleHandler


  • public interface BeanStyleHandler
    BeanStyleHandlers are used by the ProxyIBeanFactory to deal with BeanStyles that differ from the classic bean style in their runtime behavior.

    BeanStyleHandlerss are necessary in two cases:

    • Setter methods of a bean style do not return void.
    • Getter methods of a bean style return a type that does not match to the type of the corresponding field.

    If you want to provide your own bean style and at least one of the two conditions above match to your custom bean style then you need to also provide a BeanStyleHandler. Style and its matching handler are configured when assembling a ProxyIBeanFactory using method ProxyIBeanFactory.Builder.withBeanStyle(BeanStyle, BeanStyleHandler).

    • Method Detail

      • createReturnValueForSetterCall

        default Object createReturnValueForSetterCall​(Object instance,
                                                      Method setterMethod,
                                                      Object newValue)
        This method is called during runtime of a bean, more precisely, always when setters of a bean are called to assemble the return value of the setter method.
        This method is only called for bean styles that allow setter methods that do not return void. Therefore this method only needs to be implemented for those type of bean styles. This default implementation throws IllegalStateException.

        See ModernBeanStyle for a concrete implementation of this method.

        Parameters:
        instance - the IBean instance
        setterMethod - the setter method in whose return value should be created
        newValue - the new value of the field, given as a parameter to the setter
        Returns:
        the value that will then be returned from the setter
      • convertReturnValueOfGetterCall

        default Object convertReturnValueOfGetterCall​(Class<?> expectedReturnType,
                                                      Object returnValueWithWrongType)
        This method is called during runtime of a bean, more precisely, always when getters of a bean are called to adjust the type of the return value of the getter method.
        This method is only called for bean styles that allow getter methods that do not match to the type of the field. Therefore this method only needs to be implemented for those type of bean styles. This default implementation throws IllegalStateException.

        See ModernBeanStyle for a concrete implementation of this method.

        Parameters:
        expectedReturnType - the type the field value needs to be converted to
        returnValueWithWrongType - the field value that needs to be converted
        Returns:
        the value that will then be returned from the getter