[cdi-dev] [JBoss JIRA] (CDI-484) Provide forwarding implementations of SPI interfaces

Martin Kouba (JIRA) issues at jboss.org
Mon Nov 2 10:00:00 EST 2015

    [ https://issues.jboss.org/browse/CDI-484?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13124323#comment-13124323 ] 

Martin Kouba commented on CDI-484:

I don't think it's the same. {{ForwardingImplementation}} is more like a decorator pattern - subclasses override one or more methods to modify the behavior. If you look at the example in the description - the annotated type from the event is decorated. And this annotated type could have been modified by any other extension (!) - this cannot be implemented by a builder read method. Therefore, I believe we should add these forwarding implementations.

> Provide forwarding implementations of SPI interfaces
> ----------------------------------------------------
>                 Key: CDI-484
>                 URL: https://issues.jboss.org/browse/CDI-484
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Portable Extensions
>    Affects Versions: 1.2.Final
>            Reporter: Jozef Hartinger
>             Fix For: 2.0 (discussion)
> The decorator design pattern is commonly used in CDI extensions to modify existing metadata by wrapping it with a wrapper implementation that overrides certain method. This can be done in the following callbacks: ProcessAnnotatedType, ProcessProducer, ProcessInjectionTarget, ProcessInjectionPoint and ProcessBeanAttributes.
> In order to do this it is often very convenient to have a forwarding implementation available, e.g.:
> {code:JAVA}
>     void wrap(@Observes ProcessAnnotatedType<Foo> event) {
>         final AnnotatedType<Foo> delegate = event.getAnnotatedType();
>         event.setAnnotatedType(new ForwardingAnnotatedType<Foo>(delegate) {
>             @Override
>             public <A extends Annotation> A getAnnotation(Class<A> annotationType) {
>                 return null;
>             }
>             @Override
>             public Set<Annotation> getAnnotations() {
>                 return Collections.emptySet();
>             }
>             @Override
>             public boolean isAnnotationPresent(Class<? extends Annotation> annotationType) {
>                 return false;
>             }
> }
> {code}
> We should consider providing these utility forwarding implementations as part of the CDI API. This is similar to e.g. Servlet specification doing this for their decorable APIs (http://tomcat.apache.org/tomcat-5.5-doc/servletapi/javax/servlet/http/HttpServletRequestWrapper.html)

This message was sent by Atlassian JIRA

More information about the cdi-dev mailing list