2 Replies Latest reply on Dec 13, 2010 7:01 AM by Pete Muir

    Producer method object as a delegate object?

    Sivakumar Thyagarajan Newbie
      Hi

      Could someone clarify if this is a valid portable scenario?

      My application has an enabled Decorator whose decorated type and qualifiers are specified such that they are satisfied through a producer method. Can produced objects be decorated? For instance, a test case reproducing the issue is at [2]:
      - It has a Qualifier, ProducedAtRuntime.
      - A producer method producing instances of TestBeanInterface that has the @ProducedAtRuntime qualifier:


      `@Produces
      @ProducedAtRuntime
      @RequestScoped
      public TestBeanInterface getRuntimeTB(@New TestBeanImpl tbi) { ..}
      `

      and, a Decorator that uses the @ProducesAtRuntime TestBeanInterface as the delagate injection point.


      `@Decorator
      public abstract class TestBeanDecorator implements TestBeanInterface{
      @Inject
      @Delegate
      @ProducedAtRuntime
      TestBeanInterface tb;
      `

      Is this scenario valid? The Spec, AFAICT, says nothing explicitly indicating that a produced object cant be used as a delegate object.

      Thanks
      --Siva.
      [1] https://svn.java.net/svn/glassfish~svn/trunk/v2/appserv-tests/devtests/cdi/decorators/decorators-over-beans-from-producer-methods/
        • 1. Re: Producer method object as a delegate object?
          Stuart Douglas Master

          This is not a valid scenario.


          I agree that the spec is not clear on the issue, however I know that Gavin has stated that the expert group expected interceptors and decorators to be implemented via sub classing rather than proxies, which means that it would not be possible to apply them to produced beans (The spec sort of implies this in a round about way, as it does not place restrictions such as no-arg constructors on decorated beans, which are necessary for implementation via proxy).


          Weld has just changed to implementing interceptors/decorators via subclassing, which will be in the next release.


           

          • 2. Re: Producer method object as a delegate object?
            Pete Muir Master

            Stuart Douglas wrote on Dec 13, 2010 00:45:


            This is not a valid scenario.

            I agree that the spec is not clear on the issue, however I know that Gavin has stated that the expert group expected interceptors and decorators to be implemented via sub classing rather than proxies, which means that it would not be possible to apply them to produced beans (The spec sort of implies this in a round about way, as it does not place restrictions such as no-arg constructors on decorated beans, which are necessary for implementation via proxy).

            Weld has just changed to implementing interceptors/decorators via subclassing, which will be in the next release.




            The spec does state this




            Decorators may be associated with any managed bean that is not itself an interceptor or decorator or with any EJB session bean. A decorator instance is a dependent object of the object it decorates.


            However annoyingly doesn't clearly define associated very clearly, however it is possible to infer from reading the spec that associated does mean mean applied.