[jboss-cvs] JBossAS SVN: r109715 - trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Sun Dec 5 03:14:43 EST 2010
Author: marius.bogoevici
Date: 2010-12-05 03:14:41 -0500 (Sun, 05 Dec 2010)
New Revision: 109715
Added:
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InterceptorInjector.java
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299SimpleNonContextualInjector.java
Removed:
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299Injector.java
Modified:
trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InjectorDeployer.java
Log:
JBAS-7046: fix injection into non-contextual EJB interceptors
Deleted: 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 2010-12-04 00:03:12 UTC (rev 109714)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299Injector.java 2010-12-05 08:14:41 UTC (rev 109715)
@@ -1,105 +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.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);
- }
-}
Modified: 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 2010-12-04 00:03:12 UTC (rev 109714)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InjectorDeployer.java 2010-12-05 08:14:41 UTC (rev 109715)
@@ -29,8 +29,10 @@
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.Injector;
import org.jboss.injection.manager.spi.InjectionManager;
import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
import org.jboss.weld.integration.deployer.DeployersUtils;
import org.jboss.weld.integration.util.IdFactory;
@@ -47,10 +49,11 @@
{
super(InjectionManager.class);
setStage(DeploymentStages.REAL);
+ setWantComponents(true);
setOutput(InjectionManager.class);
}
- public void setKernelController(KernelController kernelController)
+ public void setKernelController(KernelController kernelController)
{
this.kernelController = kernelController;
}
@@ -60,15 +63,36 @@
{
if (isCDIDeployment(unit))
{
+ String bdaId = IdFactory.getIdFromClassLoader(unit.getClassLoader());
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));
- builder.addPropertyMetaData("bootstrapBean", injectionValueMetaData);
- builder.addUninstall("release");
- kernelController.install(builder.getBeanMetaData(), injector);
- deployment.addInjector(injector);
+
+ Injector injector = null;
+ BeanMetaDataBuilder builder = null;
+ if (!unit.isComponent())
+ {
+
+ injector = new Jsr299SimpleNonContextualInjector(bdaId);
+ builder = BeanMetaDataBuilder.createBuilder(getJsr299InjectorMcBeanName(unit), Jsr299SimpleNonContextualInjector.class.getName());
+ }
+ else
+ {
+ JBossEnterpriseBeanMetaData enterpriseBeanMetaData = unit.getAttachment(JBossEnterpriseBeanMetaData.class);
+ if (enterpriseBeanMetaData != null && enterpriseBeanMetaData.getJBossMetaData().isEJB3x())
+ {
+ injector = new Jsr299InterceptorInjector(bdaId, enterpriseBeanMetaData);
+ builder = BeanMetaDataBuilder.createBuilder(getJsr299InjectorMcBeanName(unit), Jsr299InterceptorInjector.class.getName());
+ }
+ }
+ if (injector != null)
+ {
+ 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)
{
Added: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InterceptorInjector.java
===================================================================
--- trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InterceptorInjector.java (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299InterceptorInjector.java 2010-12-05 08:14:41 UTC (rev 109715)
@@ -0,0 +1,115 @@
+/*
+ * 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.metadata.ejb.jboss.JBossEnterpriseBeanMetaData;
+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 Jsr299InterceptorInjector implements Injector
+{
+
+ private BootstrapBean bootstrapBean;
+ private String bdaId;
+ private AtomicReference<WeldManager> weldManagerRef;
+ private JBossEnterpriseBeanMetaData enterpriseBeanMetaData;
+
+ public Jsr299InterceptorInjector(String bdaId, JBossEnterpriseBeanMetaData enterpriseBeanMetaData)
+ {
+ this.bdaId = bdaId;
+ this.enterpriseBeanMetaData = enterpriseBeanMetaData;
+ this.weldManagerRef = new AtomicReference<WeldManager>();
+ }
+
+ public void setBootstrapBean(BootstrapBean bootstrapBean)
+ {
+ this.bootstrapBean = bootstrapBean;
+ }
+
+ public <T> void inject(InjectionContext<T> injectionContext) throws InjectionException
+ {
+ if (isInterceptor(injectionContext.getInjectionTarget())) {
+ 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);
+ }
+
+ private boolean isInterceptor(Object instance)
+ {
+ return !instance.getClass().getName().equals(enterpriseBeanMetaData.getEjbClass());
+ }
+
+ public void release()
+ {
+ bootstrapBean = null;
+ weldManagerRef.set(null);
+ }
+}
Copied: trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299SimpleNonContextualInjector.java (from rev 109712, 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/Jsr299SimpleNonContextualInjector.java (rev 0)
+++ trunk/weld-int/deployer/src/main/java/org/jboss/weld/integration/injection/Jsr299SimpleNonContextualInjector.java 2010-12-05 08:14:41 UTC (rev 109715)
@@ -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 Jsr299SimpleNonContextualInjector implements Injector
+{
+
+ private BootstrapBean bootstrapBean;
+ private String bdaId;
+ private AtomicReference<WeldManager> weldManagerRef;
+
+ public Jsr299SimpleNonContextualInjector(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);
+ }
+}
More information about the jboss-cvs-commits
mailing list