Interface ExtensionHandler

    • Method Detail

      • interceptGetterCall

        default Object interceptGetterCall​(IBeanContext<?> context,
                                           IBeanFieldMetaInfo fieldMeta,
                                           Object returnValue,
                                           Object proxyInstance)
        Called as an optional hook with every getter call on an IBean. Getter calls on IBeans are handled by the IBean implementation itself but an ExtensionHandler can implement this method to hook into the getter call. It can just peak on the return value or it can even change it or throw an exception.

        When you have several extension handlers registered for an IBean type the intercept calls will be called in the order in which the handlers are registered in the ProxyIBeanFactory. See also ProxyIBeanFactory.Builder.withInterfaceSupport(ExtensionSupport).

        The default implementation just returns returnValue.

        Parameters:
        context - provides meta information about the IBean
        fieldMeta - provides meta information about the field related to the getter
        returnValue - the current return value of the getter. This must not match to the field value of the IBean as the value might have already been changed by intercept calls from other handlers
        proxyInstance - the IBean instance itself
        Returns:
        the value to be returned from the getter call. If you do not want to change the getter return value just pass the value provided in returnValue
      • interceptSetterCall

        default Object interceptSetterCall​(IBeanContext<?> context,
                                           IBeanFieldMetaInfo fieldMeta,
                                           Object newValue,
                                           Object proxyInstance)
        Called as an optional hook with every setter call on an IBean. Setter calls on IBeans are handled by the IBean implementation itself but an ExtensionHandler can implement this method to hook into the setter call. It can just peak on the new value or it can even change it or throw an exception.

        When you have several extension handlers registered for an IBean type the intercept calls will be called in the order in which the handlers are registered in the ProxyIBeanFactory. See also ProxyIBeanFactory.Builder.withInterfaceSupport(ExtensionSupport).

        The default implementation just returns newValue.

        Parameters:
        context - provides meta information about the IBean
        fieldMeta - provides meta information about the field related to the setter
        newValue - the current new value of the field. This must not match to the initial value given in the setter call of the IBean as the value might have already been changed by intercept calls from other handlers
        proxyInstance - the IBean instance itself
        Returns:
        the value the field is supposed to be set to. If you do not want to change the value just pass the value provided in newValue
      • onInitStateful

        default void onInitStateful​(Object proxyInstance,
                                    IBeanTypeMetaInfo<?> metaInfo,
                                    IBeanFactory factory)
        Initialization method for stateful handlers that is called after initialization of the IBean. If a handler is registered as stateful a new instance of the ExtensionHandler implementation is created for each new IBean. After the IBean itself and all handlers created this method is called on all stateful handlers. This method should therefore be overwritten if a handler needs some initialization after creation.

        The default implementation does nothing.

        Parameters:
        proxyInstance - the IBean instance
        metaInfo - meta information about the IBean
        factory - the factory that creates the IBean instance