Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

"before:*" indicates that this decorator should come before any decorator in any module.

Annotation driven decorators

...

since5.2

Note: the ordering of decorators is in terms of the effect desired. Internally, the decorators are invoked last to first (since each once receives the "next" interceptor as its delegate). So the core service implementation is created (via a service builder method) and that is passed to the last decorator method. The interceptor created there is passed to the the next-to-last decorator method, and so forth.

It should now be evident that the delegate passed into a decorator method is sometimes the core service implementation, and some times an interceptor object created by some other decorator method.

Annotation driven decorators

Since
since5.2

Starting from version 5.2, Tapestry supports annotation-driven decorator methods. If the @Decorate annotation is present, the decorator method can be arbitrary named, as shown in the following example.

Code Block

  @Decorate
  

Starting from version 5.2, Tapestry supports annotation-driven decorator methods. If the @Decorate annotation is present, the decorator method can be arbitrary named, as shown in the following example.

Code Block

  @Decorate
  @Match("*DAO")
  public static <T> T byServiceId(Class<T> serviceInterface, T delegate,
    String serviceId, Logger logger,
    LoggingDecorator decorator)
  {
    return decorator.build(serviceInterface, delegate, serviceId, logger);
  }

...

Code Block
  @Decorate(serviceInterface=MyService.class)
  @Blue
  public static <T> T byMarkerAnnotation(Class<T> serviceInterface, T delegate,
    String serviceId, Logger logger,
    LoggingDecorator decorator)
  {
    return decorator.build(serviceInterface, delegate, serviceId, logger);
  }

The decorator above is applied to any implementation of the MyService interface that is marked by the @Blue annotation.

Note: the ordering of decorators is in terms of the effect desired. Internally, the decorators are invoked last to first (since each once receives the "next" interceptor as its delegate). So the core service implementation is created (via a service builder method) and that is passed to the last decorator method. The interceptor created there is passed to the the next-to-last decorator method, and so forth.

(Class<T> serviceInterface, T delegate,
    String serviceId, Logger logger,
    LoggingDecorator decorator)
  {
    return decorator.build(serviceInterface, delegate, serviceId, logger);
  }

The decorator above is applied to any implementation of the MyService interface that is marked by the @Blue annotationIt should now be evident that the delegate passed into a decorator method is sometimes the core service implementation, and some times an interceptor object created by some other decorator method.

Creating your own Decorators

...