Hi,

i didn't really follow the cdi implementation and i only looked a bit
yesterday because i was not able to inject a persistencecontext into a bean.

as a quick fix i did something like it:

Index:
container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
===================================================================
---
container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
(révision 1151870)
+++
container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
(copie de travail)
@@ -16,29 +16,16 @@
  */
 package org.apache.openejb.cdi;

-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.ObjectOutput;
-import java.lang.annotation.Annotation;
-
-
-import javax.enterprise.inject.spi.Bean;
-
-
 import org.apache.openejb.Injection;
 import org.apache.openejb.InjectionProcessor;
 import org.apache.openejb.OpenEJBException;
-import org.apache.openejb.assembler.classic.AppInfo;
-import org.apache.openejb.assembler.classic.InjectionBuilder;
-import org.apache.openejb.assembler.classic.JndiEncBuilder;
-import org.apache.openejb.assembler.classic.JndiEncInfo;
+import org.apache.openejb.assembler.classic.*;
 import org.apache.openejb.config.AnnotationDeployer;
 import org.apache.openejb.config.JndiEncInfoBuilder;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.PassthroughFactory;
 import org.apache.webbeans.component.ResourceBean;
-import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.spi.ResourceInjectionService;
 import org.apache.webbeans.spi.api.ResourceReference;
 import org.apache.xbean.recipe.ObjectRecipe;
@@ -48,7 +35,6 @@
 import javax.naming.Context;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
-
 import java.io.IOException;
 import java.io.ObjectInput;
 import java.io.ObjectOutput;
@@ -94,6 +80,24 @@
             JndiEncInfo jndiEnc = new JndiEncInfo();
             infoBuilder.build(cdiInfo, cdiInfo.getBeanName(),
appModule.appId, null, moduleJndiEnc, jndiEnc);

+            // todo: some quick lines to try to inject em/emf: look into
deployer, a comment is here to avoid it...
+            for (PersistenceContextReferenceInfo pc :
jndiEnc.persistenceContextRefs) {
+                for (PersistenceUnitInfo unit : appModule.persistenceUnits)
{
+                    if (pc.persistenceUnitName.equals(unit.name)) {
+                        pc.unitId = unit.id;
+                        break;
+                    }
+                }
+            }
+            for (PersistenceUnitReferenceInfo pc :
jndiEnc.persistenceUnitRefs) {
+                for (PersistenceUnitInfo unit : appModule.persistenceUnits)
{
+                    if (pc.persistenceUnitName.equals(unit.name)) {
+                        pc.unitId = unit.id;
+                        break;
+                    }
+                }
+            }
+
             InjectionBuilder builder = new InjectionBuilder(classLoader);
             List<Injection> injections = builder.buildInjections(jndiEnc);

but looking a bit everywhere i found a lot of TODO. From my understanding it
shouldnt' be done here, so should it be completed to be totally functionnal
and commited or not?

Another point i didn't understand is why the scan is not done at startup,
from what i know every bean can be injected but there is always something to
do the injection (@Inject, @Produces, ...) so scanning CDI annotations we
should be able to have the OpenEJB info tree and the patch i did should be
useless since the jndiEncInfo could be complete in the
CdiResourceInjectionService, no?

- Romain

Reply via email to