Class DecoratedInvoker<T>


  • public final class DecoratedInvoker<T>
    extends java.lang.Object
    A decorated invoker allowing to ignore some exceptions or returning decorator result instead of field result.
    Author:
    Ivan Hristov
    • Method Detail

      • ignoringDecoratorExceptions

        public DecoratedInvoker<T> ignoringDecoratorExceptions()
        Ignores any RuntimeException which comes from the preceding decorator.
        Returns:
        the DecoratedResultInvoker ignoring exceptions.
      • ignoringDecoratorExceptionsOfType

        public DecoratedInvoker<T> ignoringDecoratorExceptionsOfType​(java.lang.Class<?> exceptionClass)
        Ignores any exception of the exceptionClass type which comes from the preceding decorator.
        Parameters:
        exceptionClass - the exception to ignore - usually a checked exception of decorator method
        Returns:
        the DecoratedResultInvoker ignoring given exception type.
      • returningDecoratorResult

        public DecoratedInvoker<T> returningDecoratorResult()
        Specifies that the result from the decorator should be returned.

        If ignoringDecoratorExceptions() is used in combination with this method and an exception is thrown, the default value will be returned (as defined by JLS) for all primitives or null for all non-primitive.

        Example :
        If a RuntimeException is thrown while executing one of the decorated IExampleService field methods which returns primitive boolean value, the default value false will be returned.

         field("fieldName").ofType(IExampleService.class).in(target)
                           .postDecorateWith(postDecoratorService)
                           .returningDecoratorResult()
                           .ignoringDecoratorExceptions();
         
        In case of several decorators attached to a field, the result from the latest will be returned.

        Example 1:
        The result from the preDecoratorService will be returned

         field("fieldName").ofType(IExampleService.class).in(target)
                           .preDecorateWith(preDecoratorService)
                           .returningDecoratorResult();
         
        Example 2:
        The result from the postDecoratorService will be returned
         field("fieldName").ofType(IExampleService.class).in(target)
                           .postDecorateWith(postDecoratorService)
                           .returningDecoratorResult();
         
        Example 3:
        The result from the preDecoratorService will be returned, since it's the latest attached decorator.
         field("fieldName").ofType(IExampleService.class).in(target)
                           .postDecorateWith(postDecoratorService)
                           .returningDecoratorResult()
                           .preDecorateWith(preDecoratorService)
                           .returningDecoratorResult();
         
      • preDecorateWith

        public DecoratedInvoker<T> preDecorateWith​(T decorator)
        Adds a pre-decorator to an already decorated field.

        Note that if there are more than one pre-decorators assigned to a field they will be executed starting from the last attached decorator.

        Parameters:
        decorator - which methods be called before the same targeted object methods
        Returns:
        the DecoratedInvoker pre decorating the target field interface with given decorator.
      • postDecorateWith

        public DecoratedInvoker<T> postDecorateWith​(T decorator)
        Adds a post-decorator to an already decorated field

        Note that if there are more than one post-decorators assigned to a field they will be executed starting from the first attached decorator.

        Parameters:
        decorator - which methods be called after the same targeted object methods
        Returns:
        the DecoratedInvoker post decorating the target field interface with given decorator.