[cdi-dev] [JBoss JIRA] (CDI-224) Support Decoration of no interface beans

Stephan Knitelius (JIRA) issues at jboss.org
Wed Sep 7 07:53:00 EDT 2016


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

Stephan Knitelius commented on CDI-224:
---------------------------------------

[~antoinesabot-durand] That does make life more difficult, but would it really hurt if the Decorator would also be applied in case of "helper class extension". Since those are highly unlikely to be injected? 

[~thenovot] Yes, however I don't see how the user error risk outways the benefit, it would also be true if a different annotation would be introduced or adding a new element to @Decorator. 

Alternatively, the type could be inferred from the @Delegate injection in case of extension.

Another option which pops to mind, not my favorite, is declaring the to be decorated type in the annotation @Decorator(MyRealBean.class). This could then override the interface type inference and be mandatory for extension. 
  

> Support Decoration of no interface beans
> ----------------------------------------
>
>                 Key: CDI-224
>                 URL: https://issues.jboss.org/browse/CDI-224
>             Project: CDI Specification Issues
>          Issue Type: Feature Request
>          Components: Decorators
>    Affects Versions: 1.0
>            Reporter: Aslak Knutsen
>            Assignee: Antoine Sabot-Durand
>              Labels: F2F2016
>             Fix For: 2.0 (discussion)
>
>
> According to CDI 1.0 Spec:
> "Decorators may be associated with any managed bean that is not itself an interceptor or decorator or with any EJB session bean."
> "The set of decorated types of a decorator includes all bean types of the managed bean which are Java interfaces, except for java.io.Serializable. The decorator bean class and its superclasses are not decorated types of the decorator."
> Both CDI and EJB support No interface beans, but for some reason Decorators only work on methods from a Interface. While Interceptors on the other hand work fine with Classes. 
> I can see no technical reason to why Decorators should only work on Interfaces since all Proxies etc should already be in place.
> {code}
> import javax.decorator.Decorator;
> import javax.decorator.Delegate;
> import javax.enterprise.inject.Any;
> import javax.inject.Inject;
> import junit.framework.Assert;
> import org.jboss.arquillian.container.test.api.Deployment;
> import org.jboss.arquillian.junit.Arquillian;
> import org.jboss.shrinkwrap.api.ShrinkWrap;
> import org.jboss.shrinkwrap.api.spec.WebArchive;
> import org.jboss.shrinkwrap.impl.BeansXml;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> @RunWith(Arquillian.class)
> public class DecoratesClassTestCase {
> 	@Deployment
> 	public static WebArchive create() {
> 		return ShrinkWrap.create(WebArchive.class)
> 				.addAsWebInfResource(
> 						new BeansXml().decorators(BusinessDecorator.class), "beans.xml");
> 	}
> 	
> 	@Test
> 	public void shouldBeAbleToDecorate(BusinessObject business) throws Exception {
> 		Assert.assertEquals("Decorated Test", business.send("Test"));
> 	}
> 	
> 	@Decorator
> 	public static abstract class BusinessDecorator extends BusinessObject {
> 		@Inject @Delegate @Any
> 		private BusinessObject delegate;
> 		
> 		public String send(String msg) {
> 			return "Decorated " + delegate.send(msg);
> 		}
> 	}
> 	
> 	public static class BusinessObject {
> 		
> 		public String send(String msg) {
> 			return msg;
> 		}
> 	}
> }
> {code}



--
This message was sent by Atlassian JIRA
(v6.4.11#64026)


More information about the cdi-dev mailing list