11 Replies Latest reply on Apr 13, 2010 4:27 AM by Marius Bogoevici

    Serializable decorators

    Ramon Rockx Newbie

      Hello,


      I followed the account decorators 'example' with success.
      Instead of one implementation I experimented with two implementations (Account1 and Account2). Here some code:


      public interface Account {
           
           public String withdraw(BigDecimal amount);
      
      }
      


      @Decorator
      public class AccountDecorator implements Account {
           
           @Inject @Delegate @Any Account account;
      
           @Override
           public String withdraw(BigDecimal amount) {
                System.out.println("AccountDecorator withdraw " + account.toString());
                return account.withdraw(amount);
           }
      
      }
      


      public class Account1 implements Account {
      
           @Override
           public String withdraw(BigDecimal amount) {
                return "Account1 withdraw";
           }
           
      }
      



      public class Account2 implements Account {
      
           @Override
           public String withdraw(BigDecimal amount) {
                return "Account2 withdraw";
           }
      
      }
      



      However, when I extend the Account interface from Serializable:


      public interface Account extends Serializable {



      ...an error will show up during deployment:


      org.glassfish.deployment.common.DeploymentException: WELD-001318 Cannot resolve an ambiguous dependency between [org.jboss.weld.bean-/e:/glassfishv3/glassfish/domains/domain1/eclipseApps/POC/POC_ejb_jar/-ManagedBean-class Account2, org.jboss.weld.bean-/e:/glassfishv3/glassfish/domains/domain1/eclipseApps/POC/POC_ejb_jar/-ManagedBean-class Account1]
      ...
      Caused by: org.jboss.weld.exceptions.AmbiguousResolutionException: WELD-001318 Cannot resolve an ambiguous dependency between [org.jboss.weld.bean-/e:/asknow/glassfishv3/glassfish/domains/domain1/eclipseApps/POC/POC_ejb_jar/-ManagedBean-class Account2, org.jboss.weld.bean-/e:/asknow/glassfishv3/glassfish/domains/domain1/eclipseApps/POC/POC_ejb_jar/-ManagedBean-class Account1]
      
      ...
      
           at org.jboss.weld.manager.BeanManagerImpl.resolve(BeanManagerImpl.java:1160)
           at org.jboss.weld.bootstrap.Validator.validateDecorators(Validator.java:234)
           at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:158)
           at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:331)
           at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:317)
           at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:399)
           at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:178)
           ... 30 more



      It seems, since the Account interface is Serializable, only one implementation can be used by the decorator.
      What am I doing wrong? Or is this according to the specifications?
      (I'm using Glassfish 3.0.1, b12)


      Regards,
      Ramon