2 Replies Latest reply on Feb 18, 2009 3:11 AM by Carlo de Wolf

    Deployment unit aware annotations

    Carlo de Wolf Master

      I need to have deployment unit aware injection / annotations, so stuff like:

      @PersistenceUnit
       public void setEntityManagerFactory(EntityManagerFactory emf)
       {
       this.emf = emf;
       }

      works within a MC bean while obeying the scoping rules.

      @EJB annotations need the same thing. Now AbstractEjbReferenceValueMetadata.getTargetJndiName throws scoping out the window, which is wrong.

      I think it boils down to knowing the cause of a MC bean install. While the current resolvers work on deployment unit (as being the root cause) this might now be truly the proper abstraction.

      For the moment it would be great to actually know the deployment unit which is causing a MC bean install.

        • 1. Re: Deployment unit aware annotations
          Ales Justin Master

           

          "wolfc" wrote:
          For the moment it would be great to actually know the deployment unit which is causing a MC bean install.

          This info is under Deployment(Unit|Context)::getControllerContextNames.

          • 2. Re: Deployment unit aware annotations
            Carlo de Wolf Master

            That doesn't work because the bean itself isn't there yet. So right now I examine the BeanMetaData.

            (iterating over mainDeployer.getTopLevel())

            private DeploymentUnit findBean(DeploymentUnit deploymentUnit, String contextName)
             {
             if(deploymentUnit == null)
             return null;
             /*
             Set<Object> controllerContextNames = deploymentUnit.getControllerContextNames();
             if(controllerContextNames != null)
             {
             for(Object name : controllerContextNames)
             {
             if(name.equals(contextName))
             return deploymentUnit;
             }
             }
             */
             BeanMetaData bmd = deploymentUnit.getAttachment(BeanMetaData.class);
             if(bmd != null && bmd.getName().equals(contextName))
             return deploymentUnit;
             DeploymentUnit result;
             for(DeploymentUnit component : deploymentUnit.getComponents())
             {
             result = findBean(component, contextName);
             if(result != null)
             return deploymentUnit;
             }
             for(DeploymentUnit child : deploymentUnit.getChildren())
             {
             result = findBean(child, contextName);
             if(result != null)
             return result;
             }
             return null;
             }