[jboss-cvs] JBossAS SVN: r109331 - in branches: cdi-instantiator/ejb3/src/resources/META-INF and 8 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 15 01:46:20 EST 2010


Author: marius.bogoevici
Date: 2010-11-15 01:46:19 -0500 (Mon, 15 Nov 2010)
New Revision: 109331

Added:
   branches/cdi-instantiator/
   branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanManagerObjectFactory.java
   branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java
   branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/
   branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiator.java
   branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiatorDeployer.java
   branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/RedirectingBeanInstantiatorDeployer.java
Removed:
   branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanManagerObjectFactory.java
   branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java
Modified:
   branches/cdi-instantiator/ejb3/src/resources/META-INF/ejb3-as-deployers-jboss-beans.xml
   branches/cdi-instantiator/main/src/bin/run.conf
   branches/cdi-instantiator/weld-int/assembly/pom.xml
   branches/cdi-instantiator/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml
   branches/cdi-instantiator/weld-int/deployer/pom.xml
   branches/cdi-instantiator/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/SessionBeanInterceptor.java
Log:
Replacing the default EJB31 instantiator with a CDI implementation

Copied: branches/cdi-instantiator (from rev 109310, trunk)

Modified: branches/cdi-instantiator/ejb3/src/resources/META-INF/ejb3-as-deployers-jboss-beans.xml
===================================================================
--- trunk/ejb3/src/resources/META-INF/ejb3-as-deployers-jboss-beans.xml	2010-11-13 15:12:27 UTC (rev 109310)
+++ branches/cdi-instantiator/ejb3/src/resources/META-INF/ejb3-as-deployers-jboss-beans.xml	2010-11-15 06:46:19 UTC (rev 109331)
@@ -311,11 +311,12 @@
   
     <!-- Responsible for creating the piece used to create EJB3 Bean Instances -->
     <bean name="org.jboss.ejb3.BeanInstantiator" class="org.jboss.ejb3.instantiator.impl.Ejb31SpecBeanInstantiator" />
-    <bean name="org.jboss.ejb3.BeanInstantiatorDeployer" class="org.jboss.ejb3.instantiator.deployer.SingletonBeanInstantiatorDeployer"> 
-      <constructor>
-        <parameter class="org.jboss.ejb3.instantiator.spi.BeanInstantiator"><inject bean="org.jboss.ejb3.BeanInstantiator"/></parameter>
-      </constructor>
-      <property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property>
-    </bean>
 
+    <!--<bean name="org.jboss.ejb3.BeanInstantiatorDeployer" class="org.jboss.ejb3.instantiator.deployer.SingletonBeanInstantiatorDeployer">-->
+      <!--<constructor>-->
+        <!--<parameter class="org.jboss.ejb3.instantiator.spi.BeanInstantiator"><inject bean="org.jboss.ejb3.BeanInstantiator"/></parameter>-->
+      <!--</constructor>-->
+      <!--<property name="kernel"><inject bean="jboss.kernel:service=Kernel"/></property>-->
+    <!--</bean>-->
+
 </deployment>

Modified: branches/cdi-instantiator/main/src/bin/run.conf
===================================================================
--- trunk/main/src/bin/run.conf	2010-11-13 15:12:27 UTC (rev 109310)
+++ branches/cdi-instantiator/main/src/bin/run.conf	2010-11-15 06:46:19 UTC (rev 109331)
@@ -44,7 +44,7 @@
 fi
 
 # Sample JPDA settings for remote socket debuging
-#JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
+JAVA_OPTS="$JAVA_OPTS -ea -Xrunjdwp:transport=dt_socket,address=8787,server=y,suspend=n"
 
 # Sample JPDA settings for shared memory debugging 
 #JAVA_OPTS="$JAVA_OPTS -Xrunjdwp:transport=dt_shmem,server=y,suspend=n,address=jboss"

Modified: branches/cdi-instantiator/weld-int/assembly/pom.xml
===================================================================
--- trunk/weld-int/assembly/pom.xml	2010-11-13 15:12:27 UTC (rev 109310)
+++ branches/cdi-instantiator/weld-int/assembly/pom.xml	2010-11-15 06:46:19 UTC (rev 109331)
@@ -23,6 +23,7 @@
            <plugin>
               <groupId>org.apache.maven.plugins</groupId>
               <artifactId>maven-shade-plugin</artifactId>
+              <version>1.4</version>
               <executions>
                  <execution>
                     <id>core-no-jsf</id>

Modified: branches/cdi-instantiator/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-13 15:12:27 UTC (rev 109310)
+++ branches/cdi-instantiator/weld-int/assembly/src/main/assembly/resources/META-INF/weld-deployers-jboss-beans.xml	2010-11-15 06:46:19 UTC (rev 109331)
@@ -121,4 +121,11 @@
   <!-- Adds plugin to BeanMetaDataDeployer that installs WeldKernelControllerContexts -->
   <!-- bean name="WeldBeanMetaDataDeployerPlugin" class="org.jboss.weld.integration.deployer.mc.WeldBeanMetaDataDeployerPlugin"/ -->  
 
+    <bean name="org.jboss.ejb3.BeanInstantiatorDeployer" class="org.jboss.weld.integration.instantiator.RedirectingBeanInstantiatorDeployer">
+      <constructor>
+        <parameter class="org.jboss.ejb3.instantiator.spi.BeanInstantiator"><inject bean="org.jboss.ejb3.BeanInstantiator"/></parameter>
+        <parameter class="org.jboss.kernel.Kernel"><inject bean="jboss.kernel:service=Kernel"/></parameter>
+        <parameter class="org.jboss.reloaded.naming.deployers.javaee.JavaEEComponentInformer"><inject bean="NamingJavaEEComponentInformer"/></parameter>
+      </constructor>
+    </bean>
 </deployment>

Modified: branches/cdi-instantiator/weld-int/deployer/pom.xml
===================================================================
--- trunk/weld-int/deployer/pom.xml	2010-11-13 15:12:27 UTC (rev 109310)
+++ branches/cdi-instantiator/weld-int/deployer/pom.xml	2010-11-15 06:46:19 UTC (rev 109331)
@@ -464,6 +464,16 @@
         </exclusion>
       </exclusions>
     </dependency>
+
+    <dependency>
+        <groupId>org.jboss.ejb3.instantiator</groupId>
+        <artifactId>jboss-ejb3-instantiator-deployer</artifactId>
+    </dependency>
+
+    <dependency>
+        <groupId>org.jboss.ejb3.instantiator</groupId>
+        <artifactId>jboss-ejb3-instantiator-impl</artifactId>
+    </dependency>
     
    </dependencies>
 

Deleted: branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanManagerObjectFactory.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanManagerObjectFactory.java	2010-11-13 15:12:27 UTC (rev 109310)
+++ branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanManagerObjectFactory.java	2010-11-15 06:46:19 UTC (rev 109331)
@@ -1,58 +0,0 @@
-/*
- * 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 javax.naming.Context;
-import javax.naming.Name;
-import javax.naming.NamingException;
-import javax.naming.spi.ObjectFactory;
-import java.util.Hashtable;
-import java.util.Map;
-
-import org.jboss.weld.Container;
-import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
-import org.jboss.weld.integration.util.IdFactory;
-import org.jboss.weld.manager.BeanManagerImpl;
-
-/**
- * @author Marius Bogoevici
- */
-public class JBossBeanManagerObjectFactory implements ObjectFactory
-{
-   public Object getObjectInstance(Object o, Name name, Context context, Hashtable<?, ?> hashtable) throws Exception
-   {
-      ClassLoader tccl = Thread.currentThread().getContextClassLoader();
-      Container container = Container.instance();
-      if (Container.available() && tccl != null)
-      {
-         String beanManagerId = IdFactory.getIdFromClassLoader(tccl);
-         for (Map.Entry<BeanDeploymentArchive, BeanManagerImpl> mapElement : container.beanDeploymentArchives().entrySet())
-         {
-            if (mapElement.getKey().getId().equals(beanManagerId))
-            {
-               return mapElement.getValue().getCurrent();
-            }
-         }
-      }
-      throw new NamingException("Cannot resolve BeanManager");
-   }
-}

Copied: branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanManagerObjectFactory.java (from rev 109325, trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanManagerObjectFactory.java)
===================================================================
--- branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanManagerObjectFactory.java	                        (rev 0)
+++ branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JBossBeanManagerObjectFactory.java	2010-11-15 06:46:19 UTC (rev 109331)
@@ -0,0 +1,57 @@
+/*
+ * 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 javax.naming.*;
+import javax.naming.spi.ObjectFactory;
+import java.util.Hashtable;
+import java.util.Map;
+
+import org.jboss.weld.Container;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.integration.util.IdFactory;
+import org.jboss.weld.manager.BeanManagerImpl;
+
+/**
+ * @author Marius Bogoevici
+ */
+public class JBossBeanManagerObjectFactory implements ObjectFactory
+{
+   public Object getObjectInstance(Object o, Name name, Context context, Hashtable<?, ?> hashtable) throws Exception
+   {
+      Reference reference = (Reference) o;
+      StringRefAddr refAddr = (StringRefAddr) reference.get(JndiBinder.REFADDR_ID);
+      if (Container.available())
+      {
+         Container container = Container.instance();
+         String beanManagerId = (String)refAddr.getContent();
+         for (Map.Entry<BeanDeploymentArchive, BeanManagerImpl> mapElement : container.beanDeploymentArchives().entrySet())
+         {
+            if (mapElement.getKey().getId().equals(beanManagerId))
+            {
+               return mapElement.getValue().getCurrent();
+            }
+         }
+      }
+      throw new NamingException("Cannot resolve BeanManager");
+   }
+}

Deleted: branches/cdi-instantiator/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-13 15:12:27 UTC (rev 109310)
+++ branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java	2010-11-15 06:46:19 UTC (rev 109331)
@@ -1,201 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, 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 javax.enterprise.inject.spi.BeanManager;
-import javax.naming.Context;
-import javax.naming.NamingException;
-import javax.naming.Reference;
-
-import org.jboss.beans.metadata.spi.BeanMetaData;
-import org.jboss.deployers.spi.DeploymentException;
-import org.jboss.deployers.structure.spi.DeploymentUnit;
-import org.jboss.deployers.structure.spi.DeploymentUnitVisitor;
-import org.jboss.naming.Util;
-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;
-
-/**
- * This deployer intercepts BootstrapBean metadata,
- * and adds JndiBinder invocations to it.
- *
- * @author Pete Muir
- * @author <a href="mailto:stan.silvert at jboss.org">Stan Silvert</a>
- * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
- * @author Marius Bogoevici
- */
-public class JndiBinder
-{
-   public static final String BEAN_MANAGER_JNDI_SUBCONTEXT = "cdi";
-   private Context beanManagerContext;
-   private NameSpaces nameSpaces;
-   private JavaEEModuleInformer moduleInformer;
-
-   public void setModuleInformer(JavaEEModuleInformer moduleInformer)
-   {
-      this.moduleInformer = moduleInformer;
-   }
-
-   public void setNameSpaces(NameSpaces nameSpaces)
-   {
-      this.nameSpaces = nameSpaces;
-   }
-
-   // --- binding logic ---
-
-
-   public void bind(DeploymentUnit unit) throws DeploymentException
-   {
-      if (DeployersUtils.checkForWeldFilesAcrossDeployment(unit))
-      {
-         unit.visit(new BinderVisitor(getBeanManagerContext()));
-      }
-   }
-
-   public void unbind(DeploymentUnit unit)
-   {
-      BeanMetaData bbBMD = unit.getTopLevel().getAttachment(DeployersUtils.getBootstrapBeanAttachmentName(unit), BeanMetaData.class);
-
-      if (bbBMD != null)
-      {
-         try
-         {
-            unit.visit(new UnbinderVisitor(getBeanManagerContext()));
-         }
-         catch (DeploymentException e)
-         {
-            throw new RuntimeException(e);
-         }
-      }
-   }
-
-   protected Context createContext() throws NamingException
-   {
-      return nameSpaces.getGlobalContext();
-   }
-
-   public void create() throws Exception
-   {
-      Context context = createContext();
-      beanManagerContext = context.createSubcontext(BEAN_MANAGER_JNDI_SUBCONTEXT);
-   }
-
-   protected Context getBeanManagerContext()
-   {
-      return beanManagerContext;
-   }
-
-   public void destroy()
-   {
-      try
-      {
-         Context context = createContext();
-         context.destroySubcontext(BEAN_MANAGER_JNDI_SUBCONTEXT);
-      }
-      catch (Exception ignore)
-      {
-      }
-   }
-
-   private boolean hasJndiBoundBeanManager(DeploymentUnit deploymentUnit)
-   {
-      return DeployersUtils.checkForWeldFiles(deploymentUnit, false) && (moduleInformer.getModuleType(deploymentUnit).equals(JavaEEModuleInformer.ModuleType.EJB) ||
-            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;
-
-      private BinderVisitor(Context rootContext)
-      {
-         this.rootContext = rootContext;
-      }
-
-      public void visit(DeploymentUnit unit) throws DeploymentException
-      {
-         try
-         {
-            if (hasJndiBoundBeanManager(unit))
-            {
-               String path = getJndiPath(unit);
-               Context subcontext = Util.createSubcontext(rootContext, path);
-               subcontext.bind("BeanManager", new Reference(BeanManager.class.getName(), "org.jboss.weld.integration.deployer.jndi.JBossBeanManagerObjectFactory", null));
-            }
-         }
-         catch (NamingException e)
-         {
-            throw new DeploymentException(e);
-         }
-      }
-
-      public void error(DeploymentUnit unit)
-      {
-         // do nothing
-      }
-   }
-
-   private class UnbinderVisitor implements DeploymentUnitVisitor
-   {
-      private final Context rootContext;
-
-      private UnbinderVisitor(Context rootContext)
-      {
-         this.rootContext = rootContext;
-      }
-
-      public void visit(DeploymentUnit unit) throws DeploymentException
-      {
-         try
-         {
-            if (hasJndiBoundBeanManager(unit))
-            {
-               String path = getJndiPath(unit);
-               Context subcontext = (Context) rootContext.lookup(path);
-               subcontext.unbind("BeanManager");
-               rootContext.destroySubcontext(path);
-            }
-         }
-         catch (NamingException e)
-         {
-            throw new DeploymentException(e);
-         }
-      }
-
-      public void error(DeploymentUnit unit)
-      {
-         // do nothing
-      }
-   }
-
-
-}

Copied: branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java (from rev 109325, trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java)
===================================================================
--- branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java	                        (rev 0)
+++ branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/deployer/jndi/JndiBinder.java	2010-11-15 06:46:19 UTC (rev 109331)
@@ -0,0 +1,208 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, 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 javax.enterprise.inject.spi.BeanManager;
+import javax.naming.Context;
+import javax.naming.NamingException;
+import javax.naming.Reference;
+import javax.naming.StringRefAddr;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.deployers.structure.spi.DeploymentUnitVisitor;
+import org.jboss.naming.Util;
+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;
+
+/**
+ * This deployer intercepts BootstrapBean metadata,
+ * and adds JndiBinder invocations to it.
+ *
+ * @author Pete Muir
+ * @author <a href="mailto:stan.silvert at jboss.org">Stan Silvert</a>
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ * @author Marius Bogoevici
+ */
+public class JndiBinder
+{
+   public static final String BEAN_MANAGER_JNDI_SUBCONTEXT = "cdi";
+
+   public static final String REFADDR_ID = "id";
+
+   private Context beanManagerContext;
+   private NameSpaces nameSpaces;
+   private JavaEEModuleInformer moduleInformer;
+
+   public void setModuleInformer(JavaEEModuleInformer moduleInformer)
+   {
+      this.moduleInformer = moduleInformer;
+   }
+
+   public void setNameSpaces(NameSpaces nameSpaces)
+   {
+      this.nameSpaces = nameSpaces;
+   }
+
+   // --- binding logic ---
+
+
+   public void bind(DeploymentUnit unit) throws DeploymentException
+   {
+      if (DeployersUtils.checkForWeldFilesAcrossDeployment(unit))
+      {
+         unit.visit(new BinderVisitor(getBeanManagerContext()));
+      }
+   }
+
+   public void unbind(DeploymentUnit unit)
+   {
+      BeanMetaData bbBMD = unit.getTopLevel().getAttachment(DeployersUtils.getBootstrapBeanAttachmentName(unit), BeanMetaData.class);
+
+      if (bbBMD != null)
+      {
+         try
+         {
+            unit.visit(new UnbinderVisitor(getBeanManagerContext()));
+         }
+         catch (DeploymentException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+   }
+
+   protected Context createContext() throws NamingException
+   {
+      return nameSpaces.getGlobalContext();
+   }
+
+   public void create() throws Exception
+   {
+      Context context = createContext();
+      beanManagerContext = context.createSubcontext(BEAN_MANAGER_JNDI_SUBCONTEXT);
+   }
+
+   protected Context getBeanManagerContext()
+   {
+      return beanManagerContext;
+   }
+
+   public void destroy()
+   {
+      try
+      {
+         Context context = createContext();
+         context.destroySubcontext(BEAN_MANAGER_JNDI_SUBCONTEXT);
+      }
+      catch (Exception ignore)
+      {
+      }
+   }
+
+   private boolean hasJndiBoundBeanManager(DeploymentUnit deploymentUnit)
+   {
+      return DeployersUtils.checkForWeldFiles(deploymentUnit, false) && (moduleInformer.getModuleType(deploymentUnit).equals(JavaEEModuleInformer.ModuleType.EJB) ||
+            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;
+
+      private BinderVisitor(Context rootContext)
+      {
+         this.rootContext = rootContext;
+      }
+
+      public void visit(DeploymentUnit unit) throws DeploymentException
+      {
+         try
+         {
+            if (hasJndiBoundBeanManager(unit))
+            {
+               String path = getJndiPath(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())));
+               subcontext.bind("BeanManager", reference);
+            }
+         }
+         catch (NamingException e)
+         {
+            throw new DeploymentException(e);
+         }
+      }
+
+      public void error(DeploymentUnit unit)
+      {
+         // do nothing
+      }
+   }
+
+   private class UnbinderVisitor implements DeploymentUnitVisitor
+   {
+      private final Context rootContext;
+
+      private UnbinderVisitor(Context rootContext)
+      {
+         this.rootContext = rootContext;
+      }
+
+      public void visit(DeploymentUnit unit) throws DeploymentException
+      {
+         try
+         {
+            if (hasJndiBoundBeanManager(unit))
+            {
+               String path = getJndiPath(unit);
+               Context subcontext = (Context) rootContext.lookup(path);
+               subcontext.unbind("BeanManager");
+               rootContext.destroySubcontext(path);
+            }
+         }
+         catch (NamingException e)
+         {
+            throw new DeploymentException(e);
+         }
+      }
+
+      public void error(DeploymentUnit unit)
+      {
+         // do nothing
+      }
+   }
+
+
+}

Added: branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiator.java
===================================================================
--- branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiator.java	                        (rev 0)
+++ branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiator.java	2010-11-15 06:46:19 UTC (rev 109331)
@@ -0,0 +1,97 @@
+package org.jboss.weld.integration.instantiator;
+
+import org.jboss.ejb3.instantiator.impl.Ejb31SpecBeanInstantiator;
+import org.jboss.ejb3.instantiator.spi.BeanInstantiationException;
+import org.jboss.ejb3.instantiator.spi.InvalidConstructionParamsException;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+import org.jboss.weld.bean.SessionBean;
+import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive;
+import org.jboss.weld.ejb.spi.EjbDescriptor;
+import org.jboss.weld.integration.deployer.env.helpers.BootstrapBean;
+import org.jboss.weld.manager.api.WeldManager;
+
+import javax.enterprise.inject.spi.InjectionTarget;
+import java.util.concurrent.atomic.AtomicReference;
+
+public class Jsr299BeanInstantiator extends Ejb31SpecBeanInstantiator
+{
+
+   private BootstrapBean bootstrapBean;
+
+   private String bdaId;
+
+   private JBossEnterpriseBeanMetaData enterpriseBeanMetaData;
+
+   private AtomicReference<WeldManager> weldManagerRef = new AtomicReference<WeldManager>();
+
+   public Jsr299BeanInstantiator(JBossEnterpriseBeanMetaData enterpriseBeanMetaData)
+   {
+      if (enterpriseBeanMetaData == null)
+      {
+         throw new RuntimeException("EnterpriseBeanMetadata cannot be null");
+      }
+      this.enterpriseBeanMetaData = enterpriseBeanMetaData;
+   }
+
+   public void setBdaId(String bdaId)
+   {
+      this.bdaId = bdaId;
+   }
+
+   public void setBootstrapBean(BootstrapBean bootstrapBean)
+   {
+      this.bootstrapBean = bootstrapBean;
+   }
+
+   public <T> T create(Class<T> clazz, Object[] objects) throws IllegalArgumentException, InvalidConstructionParamsException, BeanInstantiationException
+   {
+      WeldManager weldManager = getWeldManager();
+      EjbDescriptor<Object> ejbDescriptor = weldManager.getEjbDescriptor(enterpriseBeanMetaData.getEjbName());
+      if (ejbDescriptor.getBeanClass().equals(clazz))
+      {
+         SessionBean<Object> bean = (SessionBean) weldManager.getBean(ejbDescriptor);
+         InjectionTarget<Object> injectionTarget = weldManager.createInjectionTarget(ejbDescriptor);
+         return (T)injectionTarget.produce(weldManager.createCreationalContext(bean));
+      }
+      else
+      {
+         return super.create(clazz, objects);
+      }
+   }
+
+   private WeldManager getWeldManager()
+   {
+      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 uninstall()
+   {
+      weldManagerRef.set(null);
+      enterpriseBeanMetaData = null;
+   }
+
+
+}

Added: branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiatorDeployer.java
===================================================================
--- branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiatorDeployer.java	                        (rev 0)
+++ branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/Jsr299BeanInstantiatorDeployer.java	2010-11-15 06:46:19 UTC (rev 109331)
@@ -0,0 +1,59 @@
+/*
+ *
+ *  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.instantiator;
+
+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.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.weld.integration.deployer.DeployersUtils;
+import org.jboss.weld.integration.util.IdFactory;
+
+public class Jsr299BeanInstantiatorDeployer extends BeanInstantiatorDeployerBase
+{
+
+   protected BeanInstantiator getBeanInstantiator(JBossEnterpriseBeanMetaData ebmd)
+   {
+      return new Jsr299BeanInstantiator(ebmd);
+   }
+
+   protected  BeanInstantiator getBeanInstantiator(JBossEnterpriseBeanMetaData ebmd, DeploymentUnit unit)
+   {
+      return getBeanInstantiator(ebmd);
+   }
+
+   @Override
+   protected void processMetadata(BeanMetaDataBuilder beanMetaDataBuilder, DeploymentUnit unit, JBossEnterpriseBeanMetaData ejb)
+   {
+      beanMetaDataBuilder.setBean(Jsr299BeanInstantiator.class.getName());
+      beanMetaDataBuilder.addPropertyMetaData("bdaId", IdFactory.getIdFromClassLoader(unit.getClassLoader()));
+      AbstractInjectionValueMetaData bootstrapBean = new AbstractInjectionValueMetaData(DeployersUtils.getBootstrapBeanName(unit));
+      bootstrapBean.setInjectionOption(InjectOption.CALLBACK);
+      beanMetaDataBuilder.addPropertyMetaData("bootstrapBean", bootstrapBean);
+   }
+}

Added: branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/RedirectingBeanInstantiatorDeployer.java
===================================================================
--- branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/RedirectingBeanInstantiatorDeployer.java	                        (rev 0)
+++ branches/cdi-instantiator/weld-int/deployer/src/main/java/org/jboss/weld/integration/instantiator/RedirectingBeanInstantiatorDeployer.java	2010-11-15 06:46:19 UTC (rev 109331)
@@ -0,0 +1,83 @@
+/*
+ *
+ *  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.instantiator;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.helpers.AbstractDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.ejb3.instantiator.deployer.BeanInstantiatorDeployerBase;
+import org.jboss.ejb3.instantiator.deployer.SingletonBeanInstantiatorDeployer;
+import org.jboss.ejb3.instantiator.spi.BeanInstantiator;
+import org.jboss.kernel.Kernel;
+import org.jboss.metadata.ejb.jboss.JBossMetaData;
+import org.jboss.reloaded.naming.deployers.javaee.JavaEEComponentInformer;
+import org.jboss.weld.integration.deployer.DeployersUtils;
+
+/**
+ * @author Marius Bogoevici
+ */
+//TODO: remove this class after updating BeanInstantiatorDeployerBase
+public class RedirectingBeanInstantiatorDeployer extends AbstractDeployer
+{
+
+   private Jsr299BeanInstantiatorDeployer jsr299BeanInstantiatorDeployer;
+   private SingletonBeanInstantiatorDeployer singletonBeanInstantiatorDeployer;
+
+   public RedirectingBeanInstantiatorDeployer(BeanInstantiator defaultBeanInstantiator, Kernel kernel, JavaEEComponentInformer javaEEComponentInformer)
+   {
+      super();
+      this.addInput(JBossMetaData.class);
+      this.addOutput(BeanInstantiator.class);
+      jsr299BeanInstantiatorDeployer = new Jsr299BeanInstantiatorDeployer();
+      jsr299BeanInstantiatorDeployer.setKernel(kernel);
+      jsr299BeanInstantiatorDeployer.setJavaEEComponentInformer(javaEEComponentInformer);
+      singletonBeanInstantiatorDeployer = new SingletonBeanInstantiatorDeployer(defaultBeanInstantiator);
+      singletonBeanInstantiatorDeployer.setKernel(kernel);
+      singletonBeanInstantiatorDeployer.setJavaEEComponentInformer(javaEEComponentInformer);
+   }
+
+   public void deploy(DeploymentUnit unit) throws DeploymentException
+   {
+      getApplicableBeanInstantiatorDeployer(unit).deploy(unit);
+   }
+
+   @Override
+   public void undeploy(DeploymentUnit unit)
+   {
+      getApplicableBeanInstantiatorDeployer(unit).undeploy(unit);
+   }
+
+   public BeanInstantiatorDeployerBase getApplicableBeanInstantiatorDeployer(DeploymentUnit unit)
+   {
+      if (DeployersUtils.checkForWeldFiles(unit, false))
+      {
+         return jsr299BeanInstantiatorDeployer;
+      }
+      else
+      {
+         return singletonBeanInstantiatorDeployer;
+      }
+   }
+}

Modified: branches/cdi-instantiator/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/SessionBeanInterceptor.java
===================================================================
--- trunk/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/SessionBeanInterceptor.java	2010-11-13 15:12:27 UTC (rev 109310)
+++ branches/cdi-instantiator/weld-int/ejb/src/main/java/org/jboss/weld/integration/ejb/SessionBeanInterceptor.java	2010-11-15 06:46:19 UTC (rev 109331)
@@ -76,7 +76,6 @@
    private WeldManager beanManager;
 
    private CreationalContext<Object> creationalContext;
-   private InjectionTarget<Object> injectionTarget;
 
    public static final String CREATIONAL_CONTEXT = "org.jboss.weld.integration.ejb.SessionBeanInterceptor.creationalContext";
    public static final String EJB_DESCRIPTOR = "org.jboss.weld.integration.ejb.SessionBeanInterceptor.ejbName";
@@ -92,10 +91,6 @@
    {
       String ejbName = getEjbName();
       EjbDescriptor<Object> descriptor = beanManager.getEjbDescriptor(ejbName);
-      injectionTarget = beanManager.createInjectionTarget(descriptor);
-      Bean<Object> bean = beanManager.getBean(descriptor);
-      creationalContext = beanManager.createCreationalContext(bean);
-      injectionTarget.inject(invocationContext.getTarget(), creationalContext);
       invocationContext.getContextData().put(CREATIONAL_CONTEXT, creationalContext);
       invocationContext.getContextData().put(EJB_DESCRIPTOR, descriptor);
       invocationContext.proceed();
@@ -157,4 +152,4 @@
 
    }
 
-}
\ No newline at end of file
+}



More information about the jboss-cvs-commits mailing list