[jboss-cvs] JBossAS SVN: r109369 - in trunk: tomcat/src/main/java/org/jboss/web/tomcat/service and 9 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 18 13:42:41 EST 2010


Author: marius.bogoevici
Date: 2010-11-18 13:42:38 -0500 (Thu, 18 Nov 2010)
New Revision: 109369

Added:
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/BeanManagerResourceProvider.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299Injector.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InjectorDeployer.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/util/JndiUtils.java
Modified:
   trunk/server/src/etc/deployers/switchboard-jboss-beans.xml
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
   trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
   trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml
   trunk/weld-int/deployer/pom.xml
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WebContainterIntegrationDeployer.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/WebJndiBinderDeployer.java
   trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiatorDeployer.java
   trunk/weld-int/deployer/src/test/java/org/jboss/test/deployers/test/BootDeployerTestCase.java
Log:
Switchboard integration for BeanManager && Injector - part 1

- Creates and deploys a ResourceProvider for BeanManager
- registers an Injector that can perform CDI injection and adds it to InjectionManager
- Previous integration code with Web artifacts removed
- removed code that registers BeanManager in JNDI for WARs (java:comp registration for EJB JARs is still being used, to be removed once EJB3 integrates with Switchboard)

Modified: trunk/server/src/etc/deployers/switchboard-jboss-beans.xml
===================================================================
--- trunk/server/src/etc/deployers/switchboard-jboss-beans.xml	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/server/src/etc/deployers/switchboard-jboss-beans.xml	2010-11-18 18:42:38 UTC (rev 109369)
@@ -60,7 +60,8 @@
                 <inject bean="org.jboss.switchboard.EJBRefResourceProvider"/>
                 <inject bean="org.jboss.switchboard.AnnotatedEJBRefResourceProvider"/>
                 -->
-                <!-- Disabled till container themselves stop binding into java:comp 
+                <inject bean="org.jboss.switchboard.BeanManagerResourceProvider"/>
+                <!-- Disabled till container themselves stop binding into java:comp
                     <inject bean="org.jboss.switchboard.UserTransactionRefResourceProvider"/>
                 -->
                 <!-- Disabled till https://jira.jboss.org/browse/JBAS-8465 is fixed

Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/TomcatInjectionContainer.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/TomcatInjectionContainer.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -140,7 +140,6 @@
    private static final Properties restrictedFilters = new Properties();
    private static final Properties restrictedListeners = new Properties();
    private static final Properties restrictedServlets = new Properties();
-   private List<Injector> defaultInjectors;
    // the naming component counter-part
    private JavaEEComponent component;
    
@@ -226,11 +225,6 @@
    }
    
 
-   public void setDefaultInjectors(List<Injector> injectors)
-   {
-      this.defaultInjectors = Collections.unmodifiableList(injectors);
-   }
-
    private void checkAccess(Class<?> clazz)
    {
       if (catalinaContext.getPrivileged())
@@ -377,27 +371,34 @@
       {
          final boolean trace = log.isTraceEnabled();
 
-         final ArrayList<Injector> allInjectors = new ArrayList<Injector>();
          Map<AccessibleObject, Injector> injectors = getEncInjectionsForObject(object);
-         if (injectors != null &&  injectors.size() > 0)
+         if (injectors == null || injectors.size() == 0)
          {
-            allInjectors.addAll(injectors.values());
+            if (trace)
+            {
+               log.trace("-- no injectors found for: " + object);
+            }
          }
-         if (defaultInjectors != null && defaultInjectors.size() > 0)
+         else
          {
-            allInjectors.addAll(defaultInjectors);
+            if (trace)
+            {
+               log.trace("-- doing injections for: " + object);
+            }
+            for (Injector injector : injectors.values())
+            {
+               injector.inject(object);
+            }
          }
-         if (trace)
-            log.trace("-- doing injections for: " + object);
-         for (Injector injector : allInjectors)
-         {
-            injector.inject(object);
-         }
          // TODO: Ultimately, once the injection is completely
          // managed by InjectionManager, we should get rid of all other injectors
          // used in this method (maybe except for "defaultInjectors") and instead
          // just use the InjectionManager
          // Use the InjectionManager
+         if (trace)
+         {
+            log.trace("-- processing InjectionManager for : " + object);
+         }
          this.injectionManager.inject(object);
 
       }

Modified: trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java
===================================================================
--- trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/tomcat/src/main/java/org/jboss/web/tomcat/service/deployers/TomcatDeployment.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -30,11 +30,9 @@
 import org.apache.tomcat.util.modeler.Registry;
 import org.jboss.beans.metadata.api.annotations.Inject;
 import org.jboss.dependency.spi.ControllerContext;
-import org.jboss.dependency.spi.ControllerState;
 import org.jboss.deployers.spi.DeploymentException;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.vfs.spi.structure.VFSDeploymentUnit;
-import org.jboss.injection.Injector;
 import org.jboss.logging.Logger;
 import org.jboss.metadata.web.jboss.JBossWebMetaData;
 import org.jboss.metadata.web.spec.TldMetaData;
@@ -69,7 +67,6 @@
 import java.security.CodeSource;
 import java.security.cert.Certificate;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -200,22 +197,6 @@
          new TomcatInjectionContainer(webApp, depUnit, context, 
                getPersistenceUnitDependencyResolver(), config.getDynamicClassloaders(), component, this.getInjectionManager());
 
-      if (kernel != null)
-      {
-         // Look for a WBInjector bean defined for the current deployment unit. If not found, check the parent.
-         DeploymentUnit inspectedUnit = unit;
-         ControllerContext injectorControllerContext = null;
-         while (inspectedUnit != null && injectorControllerContext == null)
-         {
-            injectorControllerContext = kernel.getController().getContext(inspectedUnit.getName() + "_WBInjector", ControllerState.INSTANTIATED);
-            inspectedUnit = inspectedUnit.getParent();
-         }
-         if (injectorControllerContext != null)
-         {
-            injectionContainer.setDefaultInjectors(Collections.singletonList((Injector)injectorControllerContext.getTarget()));
-         }
-      }
-
       Loader webLoader = depUnit.getAttachment(Loader.class);
       if (webLoader == null)
          webLoader = getWebLoader(depUnit, metaData, loader, warUrl, injectionContainer);

Modified: trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml
===================================================================
--- trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml	2010-11-18 18:42:38 UTC (rev 109369)
@@ -117,7 +117,7 @@
       <depends>NameSpaces</depends>
   </bean>
 
-  <!--  UNCOMMENT THIS TO ENABLE WELD/MC INJECTION - This feature is currently very experimental and so not enabled by default  -->
+  <!--&lt;!&ndash;  UNCOMMENT THIS TO ENABLE WELD/MC INJECTION - This feature is currently very experimental and so not enabled by default  &ndash;&gt;-->
   <!-- Adds plugin to BeanMetaDataDeployer that installs WeldKernelControllerContexts -->
   <!-- bean name="WeldBeanMetaDataDeployerPlugin" class="org.jboss.weld.integration.deployer.mc.WeldBeanMetaDataDeployerPlugin"/ -->  
 
@@ -129,4 +129,13 @@
         <parameter class="org.jboss.reloaded.naming.deployers.javaee.JavaEEComponentInformer"><inject bean="NamingJavaEEComponentInformer"/></parameter>
       </constructor>
     </bean>
+
+  <bean name="org.jboss.switchboard.BeanManagerResourceProvider" class="org.jboss.weld.integration.deployer.jndi.BeanManagerResourceProvider">
+      <property name="moduleInformer"><inject bean="NamingJavaEEModuleInformer"/></property>
+  </bean>
+
+  <bean name="org.jboss.weld.integration.injection.Jsr299InjectorDeployer" class="org.jboss.weld.integration.injection.Jsr299InjectorDeployer">
+      <property name="kernelController"><inject bean="jboss.kernel:service=KernelController"/></property>
+  </bean>
+
 </deployment>

Modified: trunk/weld-int/deployer/pom.xml
===================================================================
--- trunk/weld-int/deployer/pom.xml	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/weld-int/deployer/pom.xml	2010-11-18 18:42:38 UTC (rev 109369)
@@ -307,6 +307,18 @@
         <artifactId>jboss-reloaded-naming-deployers</artifactId>
         <scope>provided</scope>
     </dependency>
+    
+    <dependency>
+    	<groupId>org.jboss.switchboard</groupId>
+    	<artifactId>jboss-switchboard-mc-spi</artifactId>
+    	<scope>provided</scope>
+    </dependency>
+    
+    <dependency>
+    	<groupId>org.jboss.switchboard</groupId>
+    	<artifactId>jboss-switchboard-mc-impl</artifactId>
+    	<scope>provided</scope>
+    </dependency>
 
     <dependency>
       <groupId>org.jboss.test</groupId>

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WebContainterIntegrationDeployer.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WebContainterIntegrationDeployer.java	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/env/WebContainterIntegrationDeployer.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -1,3 +1,25 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
 package org.jboss.weld.integration.deployer.env;
 
 import java.util.ArrayList;
@@ -34,23 +56,14 @@
    {
       if (DeployersUtils.isBootstrapBeanPresent(unit) && unit.getAttachment(DeployersUtils.WELD_FILES) != null)
       {
-         String injectorName = unit.getName() + "_WBInjector";
-         String bootstrapBeanName = DeployersUtils.getBootstrapBeanName(unit);
 
-         BeanMetaDataBuilder weldInjector = BeanMetaDataBuilder.createBuilder(injectorName, WeldInjector.class.getName());
-
-         weldInjector.addConstructorParameter(BootstrapBean.class.getName(), weldInjector.createInject(bootstrapBeanName));
-         weldInjector.addConstructorParameter(String.class.getName(), IdFactory.getIdFromClassLoader(unit.getClassLoader()));
-         weldInjector.setDestroy("cleanup");
-         unit.addAttachment(injectorName + "_" + BeanMetaData.class.getSimpleName(), weldInjector.getBeanMetaData());
-
          List<String> depends = deployment.getDepends();
          if (depends == null)
          {
             depends = new ArrayList<String>();
             deployment.setDepends(depends);
          }
-         depends.add(bootstrapBeanName);
+         depends.add(DeployersUtils.getBootstrapBeanName(unit));
       }
    }
 }

Copied: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/BeanManagerResourceProvider.java (from rev 109355, branches/switchboard-integration-bean-manager/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/BeanManagerResourceProvider.java)
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/BeanManagerResourceProvider.java	                        (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/BeanManagerResourceProvider.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -0,0 +1,64 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.weld.integration.deployer.jndi;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.reloaded.naming.deployers.javaee.JavaEEModuleInformer;
+import org.jboss.switchboard.impl.resource.IndependentResource;
+import org.jboss.switchboard.impl.resource.LinkRefResource;
+import org.jboss.switchboard.javaee.environment.BeanManagerRefType;
+import org.jboss.switchboard.mc.spi.MCBasedResourceProvider;
+import org.jboss.switchboard.spi.Resource;
+import org.jboss.weld.integration.deployer.DeployersUtils;
+import org.jboss.weld.integration.util.JndiUtils;
+
+public class BeanManagerResourceProvider implements MCBasedResourceProvider<BeanManagerRefType>
+{
+
+   JavaEEModuleInformer moduleInformer;
+
+
+   public void setModuleInformer(JavaEEModuleInformer moduleInformer)
+   {
+      this.moduleInformer = moduleInformer;
+   }
+
+   public Resource provide(DeploymentUnit deploymentUnit, BeanManagerRefType type)
+   {
+      // TODO Auto-generated method stub
+      if (deploymentUnit.getAttachment(DeployersUtils.WELD_FILES) != null)
+      {
+         return new LinkRefResource(JndiUtils.getGlobalBeanManagerPath(moduleInformer, deploymentUnit));
+      }
+      else
+      {
+         return new IndependentResource(null);
+      }
+   }
+
+   public Class<BeanManagerRefType> getEnvironmentEntryType()
+   {
+      return BeanManagerRefType.class;
+   }
+
+}

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -35,8 +35,8 @@
 import org.jboss.reloaded.naming.deployers.javaee.JavaEEModuleInformer;
 import org.jboss.reloaded.naming.service.NameSpaces;
 import org.jboss.weld.integration.deployer.DeployersUtils;
-import org.jboss.weld.integration.deployer.env.helpers.BootstrapBean;
 import org.jboss.weld.integration.util.IdFactory;
+import org.jboss.weld.integration.util.JndiUtils;
 
 /**
  * This deployer intercepts BootstrapBean metadata,
@@ -49,7 +49,6 @@
  */
 public class JndiBinder
 {
-   public static final String BEAN_MANAGER_JNDI_SUBCONTEXT = "cdi";
 
    public static final String REFADDR_ID = "id";
 
@@ -93,6 +92,8 @@
             throw new RuntimeException(e);
          }
       }
+
+      // TODO: cleanup the remaining subcontexts if any (e.g. EAR/WAR etc)
    }
 
    protected Context createContext() throws NamingException
@@ -103,7 +104,7 @@
    public void create() throws Exception
    {
       Context context = createContext();
-      beanManagerContext = context.createSubcontext(BEAN_MANAGER_JNDI_SUBCONTEXT);
+      beanManagerContext = context.createSubcontext(JndiUtils.BEAN_MANAGER_GLOBAL_SUBCONTEXT);
    }
 
    protected Context getBeanManagerContext()
@@ -116,7 +117,7 @@
       try
       {
          Context context = createContext();
-         context.destroySubcontext(BEAN_MANAGER_JNDI_SUBCONTEXT);
+         context.destroySubcontext(JndiUtils.BEAN_MANAGER_GLOBAL_SUBCONTEXT);
       }
       catch (Exception ignore)
       {
@@ -129,14 +130,6 @@
             moduleInformer.getModuleType(deploymentUnit).equals(JavaEEModuleInformer.ModuleType.WEB));
    }
 
-   private String getJndiPath(DeploymentUnit deploymentUnit)
-   {
-      String applicationName = moduleInformer.getApplicationName(deploymentUnit);
-      String path = (applicationName == null) ? "" : applicationName + "/";
-      path += moduleInformer.getModuleName(deploymentUnit);
-      return path;
-   }
-
    private class BinderVisitor implements DeploymentUnitVisitor
    {
       private final Context rootContext;
@@ -152,7 +145,7 @@
          {
             if (hasJndiBoundBeanManager(unit))
             {
-               String path = getJndiPath(unit);
+               String path = JndiUtils.getJndiSubcontexPathtForBeanManager(moduleInformer, unit);
                Context subcontext = Util.createSubcontext(rootContext, path);
                Reference reference = new Reference(BeanManager.class.getName(), "org.jboss.weld.integration.deployer.jndi.JBossBeanManagerObjectFactory", null);
                reference.add(new StringRefAddr(REFADDR_ID, IdFactory.getIdFromClassLoader(unit.getClassLoader())));
@@ -186,7 +179,7 @@
          {
             if (hasJndiBoundBeanManager(unit))
             {
-               String path = getJndiPath(unit);
+               String path = JndiUtils.getJndiSubcontexPathtForBeanManager(moduleInformer, unit);
                Context subcontext = (Context) rootContext.lookup(path);
                subcontext.unbind("BeanManager");
                rootContext.destroySubcontext(path);
@@ -204,5 +197,4 @@
       }
    }
 
-
 }

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/WebJndiBinderDeployer.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/WebJndiBinderDeployer.java	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/WebJndiBinderDeployer.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -50,26 +50,18 @@
    @Override
    public void deploy(DeploymentUnit deploymentUnit, JBossWebMetaData jBossWebMetaData) throws DeploymentException
    {
-      BeanMetaData bbBMD = getBootstrapBeanAttachment(deploymentUnit.getTopLevel());
-      if (bbBMD != null && deploymentUnit.isAttachmentPresent(JBossWebMetaData.class))
-      {
-         AbstractInjectionValueMetaData javaModule = new AbstractInjectionValueMetaData(getModuleBeanName(deploymentUnit));
-
-         String beanMetaDataMcNamespace = getModuleBeanName(deploymentUnit);
-         BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(beanMetaDataMcNamespace + "_WebCompJndiBinder", SimpleCompJndiBinder.class.getName());
-         builder.addConstructorParameter(DeploymentUnit.class.getName(), deploymentUnit);
-         builder.addConstructorParameter(JavaEEModule.class.getName(), javaModule);
-         builder.addInstall("bindToJavaComp");
-         // no uninstall method for SimpleCompJndiBinder (context will be destroyed by Tomcat)
-         //builder.addUninstall("unbind");
-         deploymentUnit.getTopLevel().addAttachment(beanMetaDataMcNamespace + "_WebCompJndiBinder", builder.getBeanMetaData());
-
-         BeanMetaDataBuilder moduleBinderBuilder = BeanMetaDataBuilder.createBuilder(beanMetaDataMcNamespace + "_JavaModuleJndiBinder", JavaEEModuleJndiBinder.class.getName());
-         moduleBinderBuilder.addConstructorParameter(JavaEEModule.class.getName(), javaModule);
-         moduleBinderBuilder.addInstall("bindToJavaComp");
-         moduleBinderBuilder.addUninstall("unbind");
-         deploymentUnit.getTopLevel().addAttachment(beanMetaDataMcNamespace + "_JavaModuleJndiBinder", moduleBinderBuilder.getBeanMetaData());
-      }
+//      BeanMetaData bbBMD = getBootstrapBeanAttachment(deploymentUnit.getTopLevel());
+//      if (bbBMD != null && deploymentUnit.isAttachmentPresent(JBossWebMetaData.class))
+//      {
+//         AbstractInjectionValueMetaData javaModule = new AbstractInjectionValueMetaData(getModuleBeanName(deploymentUnit));
+//
+//         String beanMetaDataMcNamespace = getModuleBeanName(deploymentUnit);
+//         BeanMetaDataBuilder moduleBinderBuilder = BeanMetaDataBuilder.createBuilder(beanMetaDataMcNamespace + "_JavaModuleJndiBinder", JavaEEModuleJndiBinder.class.getName());
+//         moduleBinderBuilder.addConstructorParameter(JavaEEModule.class.getName(), javaModule);
+//         moduleBinderBuilder.addInstall("bindToJavaComp");
+//         moduleBinderBuilder.addUninstall("unbind");
+//         deploymentUnit.getTopLevel().addAttachment(beanMetaDataMcNamespace + "_JavaModuleJndiBinder", moduleBinderBuilder.getBeanMetaData());
+//      }
    }
 
    private BeanMetaData getBootstrapBeanAttachment(DeploymentUnit deploymentUnit)

Added: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299Injector.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299Injector.java	                        (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299Injector.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -0,0 +1,105 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.weld.integration.injection;
+
+import org.jboss.injection.manager.spi.InjectionContext;
+import org.jboss.injection.manager.spi.InjectionException;
+import org.jboss.injection.manager.spi.Injector;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.integration.deployer.env.helpers.BootstrapBean;
+import org.jboss.weld.manager.api.WeldManager;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionTarget;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class Jsr299Injector implements Injector
+{
+
+   private BootstrapBean bootstrapBean;
+   private String bdaId;
+   private AtomicReference<WeldManager> weldManagerRef;
+
+   public Jsr299Injector(String bdaId)
+   {
+      this.bdaId = bdaId;
+      this.weldManagerRef = new AtomicReference<WeldManager>();
+   }
+
+   public void setBootstrapBean(BootstrapBean bootstrapBean)
+   {
+      this.bootstrapBean = bootstrapBean;
+   }
+
+   public <T> void inject(InjectionContext<T> injectionContext) throws InjectionException
+   {
+      WeldManager weldManager = initWeldManagerIfNecessary();
+      Object instance = injectionContext.getInjectionTarget();
+
+      if (weldManager == null)
+         throw new IllegalArgumentException("Null bean manager.");
+
+      CreationalContext<Object> creationalContext =  weldManager.createCreationalContext(null);
+      InjectionTarget<Object> injectionTarget = (InjectionTarget<Object>) weldManager.fireProcessInjectionTarget(weldManager.createAnnotatedType(instance.getClass()));
+      injectionTarget.inject(instance, creationalContext);
+      injectionContext.proceed();
+   }
+
+   private WeldManager initWeldManagerIfNecessary()
+   {
+      WeldManager weldManager = weldManagerRef.get();
+      if (weldManager == null)
+      {
+         weldManager = locateWeldManager();
+      }
+      weldManagerRef.compareAndSet(null, weldManager);
+      return weldManager;
+   }
+
+   private WeldManager locateWeldManager()
+   {
+      BeanDeploymentArchive foundBeanDeploymentArchive = null;
+      for (BeanDeploymentArchive beanDeploymentArchive: bootstrapBean.getDeployment().getBeanDeploymentArchives())
+      {
+         if (beanDeploymentArchive.getId().equals(bdaId))
+         {
+            foundBeanDeploymentArchive = beanDeploymentArchive;
+         }
+      }
+      if (foundBeanDeploymentArchive == null)
+      {
+         throw new IllegalStateException("Cannot find BeanManager for BeanDeploymentArchive with id=" + bdaId);
+      }
+
+      return bootstrapBean.getBootstrap().getManager(foundBeanDeploymentArchive);
+   }
+
+   public void release()
+   {
+      bootstrapBean = null;
+      weldManagerRef.set(null);
+   }
+}

Added: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InjectorDeployer.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InjectorDeployer.java	                        (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InjectorDeployer.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -0,0 +1,106 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.weld.integration.injection;
+
+import org.jboss.beans.metadata.api.model.InjectOption;
+import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStages;
+import org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.injection.manager.spi.InjectionManager;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.weld.integration.deployer.DeployersUtils;
+import org.jboss.weld.integration.util.IdFactory;
+
+/**
+ * A deployer for a Jsr299Injector
+ *
+ * @author Marius Bogoevici
+ */
+public class Jsr299InjectorDeployer extends AbstractSimpleRealDeployer<InjectionManager>
+{
+   private KernelController kernelController;
+
+   public Jsr299InjectorDeployer()
+   {
+      super(InjectionManager.class);
+      setStage(DeploymentStages.POST_CLASSLOADER);
+      setOutput(InjectionManager.class);
+   }
+
+   public void setKernelController(KernelController kernelController)
+   {
+      this.kernelController = kernelController;
+   }
+
+   @Override
+   public void deploy(DeploymentUnit unit, InjectionManager deployment) throws DeploymentException
+   {
+      if (isCDIDeployment(unit))
+      {
+         try
+         {
+            Jsr299Injector injector = new Jsr299Injector(IdFactory.getIdFromClassLoader(unit.getClassLoader()));
+            BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(getJsr299InjectorMcBeanName(unit), Jsr299Injector.class.getName());
+            AbstractInjectionValueMetaData injectionValueMetaData = new AbstractInjectionValueMetaData(DeployersUtils.getBootstrapBeanName(unit));
+            injectionValueMetaData.setInjectionOption(InjectOption.CALLBACK);
+            builder.addPropertyMetaData("bootstrapBean", injectionValueMetaData);
+            builder.addUninstall("release");
+            kernelController.install(builder.getBeanMetaData(), injector);
+            deployment.addInjector(injector);
+         }
+         catch (Throwable throwable)
+         {
+            throw new DeploymentException(throwable);
+         }
+      }
+   }
+
+   private boolean isCDIDeployment(DeploymentUnit unit)
+   {
+      return unit.getAttachment(DeployersUtils.WELD_FILES) != null;
+   }
+
+   @Override
+   public void undeploy(DeploymentUnit unit, InjectionManager deployment)
+   {
+      if (isCDIDeployment(unit))
+      {
+         kernelController.uninstall(getJsr299InjectorMcBeanName(unit));
+      }
+   }
+
+   private String getJsr299InjectorMcBeanName(DeploymentUnit deploymentUnit)
+   {
+      if (!deploymentUnit.isComponent())
+      {
+         return deploymentUnit.getName() + "_Jsr299BeanInjector";
+      }
+      else
+      {
+         return deploymentUnit.getParent().getName() + "/" + deploymentUnit.getName() + "_Jsr299Injector";
+      }
+   }
+}

Modified: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiatorDeployer.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiatorDeployer.java	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiatorDeployer.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -26,11 +26,13 @@
 
 import org.jboss.beans.metadata.api.model.InjectOption;
 import org.jboss.beans.metadata.plugins.AbstractInjectionValueMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
 import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.ejb3.instantiator.deployer.BeanInstantiatorDeployerBase;
 import org.jboss.ejb3.instantiator.spi.BeanInstantiator;
 import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.metadata.ejb.jboss.JBossSessionBean31MetaData;
 import org.jboss.weld.integration.deployer.DeployersUtils;
 import org.jboss.weld.integration.util.IdFactory;
 
@@ -55,5 +57,19 @@
       AbstractInjectionValueMetaData bootstrapBean = new AbstractInjectionValueMetaData(DeployersUtils.getBootstrapBeanName(unit));
       bootstrapBean.setInjectionOption(InjectOption.CALLBACK);
       beanMetaDataBuilder.addPropertyMetaData("bootstrapBean", bootstrapBean);
+
+      //
+      if (ejb instanceof JBossSessionBean31MetaData &&
+            ((JBossSessionBean31MetaData) ejb).isSingleton())
+      {
+         String containerName = ejb.getContainerName() == null ?
+               ejb.getGeneratedContainerName() :
+               ejb.getContainerName();
+
+         BeanMetaData containerBeanMetadata = unit.getAttachment(BeanMetaData.class + ":" + containerName, BeanMetaData.class);
+         BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(containerBeanMetadata);
+         builder.addDependency(DeployersUtils.getBootstrapBeanName(unit));
+         builder.addDependency(beanMetaDataBuilder.getBeanMetaData().getName());
+      }
    }
 }

Added: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/util/JndiUtils.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/util/JndiUtils.java	                        (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/util/JndiUtils.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.weld.integration.util;
+
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.reloaded.naming.deployers.javaee.JavaEEModuleInformer;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class JndiUtils
+{
+   /**
+    * The global path for bean managers is java:/global/cdi/<applicationName>/<moduleName>/BeanManager
+    */
+   public static final String BEAN_MANAGER_GLOBAL_SUBCONTEXT = "cdi";
+
+   public static String getJndiSubcontexPathtForBeanManager(JavaEEModuleInformer moduleInformer, DeploymentUnit unit)
+   {
+      String applicationName = moduleInformer.getApplicationName(unit);
+      String path = (applicationName == null) ? "" : (applicationName + "/");
+      path += moduleInformer.getModuleName(unit);
+      return path;
+   }
+
+   public static String getGlobalBeanManagerPath(JavaEEModuleInformer moduleInformer, DeploymentUnit unit)
+   {
+      return "java:global/" + BEAN_MANAGER_GLOBAL_SUBCONTEXT + "/" + getJndiSubcontexPathtForBeanManager(moduleInformer, unit) + "/BeanManager";
+   }
+}

Modified: trunk/weld-int/deployer/src/test/java/org/jboss/test/deployers/test/BootDeployerTestCase.java
===================================================================
--- trunk/weld-int/deployer/src/test/java/org/jboss/test/deployers/test/BootDeployerTestCase.java	2010-11-18 18:15:28 UTC (rev 109368)
+++ trunk/weld-int/deployer/src/test/java/org/jboss/test/deployers/test/BootDeployerTestCase.java	2010-11-18 18:42:38 UTC (rev 109369)
@@ -42,6 +42,7 @@
 import org.jboss.test.deployers.support.deployer.CheckableJndiBinder;
 import org.jboss.vfs.VirtualFile;
 import org.jboss.weld.integration.deployer.DeployersUtils;
+import org.jboss.weld.integration.util.JndiUtils;
 
 /**
  * Test boot deployer.
@@ -73,7 +74,7 @@
    {
       // should already be on the deployer
       Context bmContext = assertInstanceOf(
-            CheckableJndiBinder.ROOT.lookup(CheckableJndiBinder.BEAN_MANAGER_JNDI_SUBCONTEXT),
+            CheckableJndiBinder.ROOT.lookup(JndiUtils.BEAN_MANAGER_GLOBAL_SUBCONTEXT),
             Context.class,
             false
       );



More information about the jboss-cvs-commits mailing list