Index: web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java =================================================================== --- web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java (revision 44692) +++ web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java (working copy) @@ -55,7 +55,6 @@ import org.jboss.weld.manager.api.WeldManager; import org.jvnet.hk2.annotations.Inject; import org.jvnet.hk2.annotations.Service; -import org.jvnet.hk2.component.Habitat; import com.sun.enterprise.container.common.spi.JCDIService; import com.sun.enterprise.container.common.spi.util.ComponentEnvManager; @@ -71,9 +70,6 @@ private WeldDeployer weldDeployer; @Inject - private Habitat h; - - @Inject private ComponentEnvManager compEnvManager; @Inject @@ -132,7 +128,7 @@ ejb.getEjbBundleDescriptor().getModuleDescriptor().getDescriptor(); // First get BeanDeploymentArchive for this ejb - BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc); + BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, ejb.getEjbClassName()); WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(ejb.getEjbBundleDescriptor().getApplication()); WeldManager weldManager = bootstrap.getManager(bda); @@ -148,28 +144,49 @@ // Per instance required, create the creational context CreationalContext cc = weldManager.createCreationalContext(bean); - Object beanInstance = instance; + Object beanInstance = instance; + + if( beanInstance == null ) { + // Create instance , perform constructor injection. + beanInstance = it.produce(cc); + } - if( beanInstance == null ) { - // Create instance , perform constructor injection. - beanInstance = it.produce(cc); - } - - // Injection is not performed yet. Separate injectEJBInstance() call is required. - + // Injection is not performed yet. Separate injectEJBInstance() call is required. return new JCDIInjectionContextImpl(it, cc, beanInstance); } + + private BeanDeploymentArchive getBDAForBeanClass(BundleDescriptor bundleDesc, String beanClassName){ + System.out.println("getBDAForBeanClass -- search in " + bundleDesc.getModuleName() + " for " + beanClassName); + BeanDeploymentArchive topLevelBDA = weldDeployer.getBeanDeploymentArchiveForBundle(bundleDesc); + if (topLevelBDA.getBeanClasses().contains(beanClassName)){ + System.out.println("JCDIServiceImpl.getBDAForBeanClass:: TopLevelBDA " + + topLevelBDA.getId() + " contains beanClassName:" + beanClassName); + return topLevelBDA; + } + + //for all sub-BDAs + for (BeanDeploymentArchive bda: topLevelBDA.getBeanDeploymentArchives()){ + if (bda.getBeanClasses().contains(beanClassName)){ + System.out.println("JCDIServiceImpl.getBDAForBeanClass:: subBDA " + + bda.getId() + " contains beanClassName:" + beanClassName); + return bda; + } + } + //If not found in any BDA's subclasses, return topLevel BDA + return topLevelBDA; + } + + public void injectEJBInstance(JCDIInjectionContext injectionCtx) { - - JCDIInjectionContextImpl injectionCtxImpl = - (JCDIInjectionContextImpl) injectionCtx; - - // Perform injection and call initializers - injectionCtxImpl.it.inject(injectionCtxImpl.instance, injectionCtxImpl.cc); - - // NOTE : PostConstruct is handled by ejb container + JCDIInjectionContextImpl injectionCtxImpl = + (JCDIInjectionContextImpl) injectionCtx; + + // Perform injection and call initializers + injectionCtxImpl.it.inject(injectionCtxImpl.instance, injectionCtxImpl.cc); + + // NOTE : PostConstruct is handled by ejb container } public JCDIInjectionContext createManagedObject(Class managedClass, BundleDescriptor bundle) { @@ -187,8 +204,8 @@ BundleDescriptor topLevelBundleDesc = (BundleDescriptor) bundle.getModuleDescriptor().getDescriptor(); // First get BeanDeploymentArchive for this ejb - BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc); + //BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, managedObject.getClass().getName()); WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); BeanManager beanManager = bootstrap.getManager(bda); AnnotatedType annotatedType = beanManager.createAnnotatedType(managedObject.getClass()); @@ -206,6 +223,7 @@ // First get BeanDeploymentArchive for this ejb BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc); + //BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, managedClass.getName()); WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); @@ -258,10 +276,5 @@ cc.release(); } - } - - -} - - +} \ No newline at end of file Index: web/weld-integration/src/main/java/org/glassfish/weld/ejb/EjbDescriptorImpl.java =================================================================== --- web/weld-integration/src/main/java/org/glassfish/weld/ejb/EjbDescriptorImpl.java (revision 44692) +++ web/weld-integration/src/main/java/org/glassfish/weld/ejb/EjbDescriptorImpl.java (working copy) @@ -352,4 +352,9 @@ return remoteBusIntfs; } + + @Override + public String toString(){ + return ejbDesc.getEjbClassName(); + } } Index: web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java =================================================================== --- web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java (revision 44692) +++ web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java (working copy) @@ -140,11 +140,8 @@ this.beanDeploymentArchives = new ArrayList(); this.context = ctx; - for(com.sun.enterprise.deployment.EjbDescriptor next : ejbs) { - EjbDescriptorImpl wbEjbDesc = new EjbDescriptorImpl(next); - ejbDescImpls.add(wbEjbDesc); - } - populate(); + populate(ejbs); + populateEJBsForThisBDA(ejbs); try { this.archive.close(); } catch (Exception e) { @@ -156,6 +153,18 @@ } + private void populateEJBsForThisBDA( + Collection ejbs) { + for(com.sun.enterprise.deployment.EjbDescriptor next : ejbs) { + for(Class c: this.moduleClasses) { + if (c.getName().equals(next.getEjbClassName())){ + EjbDescriptorImpl wbEjbDesc = new EjbDescriptorImpl(next); + ejbDescImpls.add(wbEjbDesc); + } + } + } + } + //These are for empty BDAs that do not model Bean classes in the current //deployment unit -- for example: BDAs for portable Extensions. public BeanDeploymentArchiveImpl(String id, List> wClasses, List wUrls, @@ -167,12 +176,9 @@ this.ejbDescImpls = new HashSet>(); this.beanDeploymentArchives = new ArrayList(); this.context = ctx; + + populateEJBsForThisBDA(ejbs); - for(com.sun.enterprise.deployment.EjbDescriptor next : ejbs) { - EjbDescriptorImpl wbEjbDesc = new EjbDescriptorImpl(next); - ejbDescImpls.add(wbEjbDesc); - } - //set to the current TCL this.moduleClassLoaderForBDA = Thread.currentThread().getContextClassLoader(); } @@ -272,7 +278,7 @@ String beanClassesString = ((getBeanClasses().size() > 0) ? getBeanClasses().toString() : ""); String val = "|ID: " + getId() + ", bdaType= " + bdaType + ", accessibleBDAs #:" + getBeanDeploymentArchives().size() + ", " + formatAccessibleBDAs(this) - + ", Bean Classes #: " + getBeanClasses().size() + "," + beanClassesString + "\n"; + + ", Bean Classes #: " + getBeanClasses().size() + "," + beanClassesString + ", ejbs=" + getEjbs() +"\n"; Collection bdas = getBeanDeploymentArchives(); Iterator iter = bdas.iterator(); @@ -285,7 +291,7 @@ String embedBDABeanClasses = ((bda.getBeanClasses().size() > 0) ? bda.getBeanClasses().toString() : ""); val += "|---->ID: " + bda.getId() + ", bdaType= " + embedBDAType.toString() + ", accessibleBDAs #:" + bda.getBeanDeploymentArchives().size() + ", " + formatAccessibleBDAs(bda) - + ", Bean Classes #: " + bda.getBeanClasses().size() + "," + embedBDABeanClasses + "\n"; + + ", Bean Classes #: " + bda.getBeanClasses().size() + "," + embedBDABeanClasses + ", ejbs=" + bda.getEjbs() + "\n"; } return val; } @@ -305,7 +311,7 @@ return bdaType; } - private void populate() { + private void populate(Collection ejbs) { try { if (archive.exists(WEB_INF_BEANS_XML)) { logger.log(FINE, "-processing " + archive.getURI() @@ -369,7 +375,7 @@ while (libJarIterator.hasNext()) { ReadableArchive libJarArchive = (ReadableArchive)libJarIterator.next(); BeanDeploymentArchiveImpl wlbda = new BeanDeploymentArchiveImpl(libJarArchive, - new HashSet(), + ejbs, context, WEB_INF_LIB + SEPARATOR_CHAR + libJarArchive.getName() /* Use WEB-INF/lib/jarName as BDA Id*/); this.beanDeploymentArchives.add(wlbda); //add to list of BDAs for this WAR