tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djen...@apache.org
Subject svn commit: r1056159 - in /openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi: CdiResourceInjectionService.java OpenEJBLifecycle.java ThreadSingletonServiceImpl.java
Date Fri, 07 Jan 2011 02:00:46 GMT
Author: djencks
Date: Fri Jan  7 02:00:46 2011
New Revision: 1056159

URL: http://svn.apache.org/viewvc?rev=1056159&view=rev
Log:
OWB-503 related updates, improved delegated resource serialization, allow for direct resource
jndi lookup (needs more work)

Modified:
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
    openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java?rev=1056159&r1=1056158&r2=1056159&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiResourceInjectionService.java
Fri Jan  7 02:00:46 2011
@@ -37,13 +37,21 @@ import org.apache.openejb.config.JndiEnc
 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;
 import org.apache.xbean.recipe.Option;
 
+import javax.enterprise.inject.spi.Bean;
 import javax.naming.Context;
+import javax.naming.InitialContext;
 import javax.naming.NamingException;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
 import java.lang.annotation.Annotation;
 import java.util.HashMap;
 import java.util.List;
@@ -99,25 +107,30 @@ public class CdiResourceInjectionService
 
     @Override
     public <X, T extends Annotation> X getResourceReference(ResourceReference<X,
T> resourceReference) {
-        for (Entry<CdiBeanInfo, Context> entry : this.contexts.entrySet()) {
-            if (entry.getKey().getBeanClass() == resourceReference.getOwnerClass()) {
-                List<Injection> injections = entry.getKey().getInjections();
-                for (Injection injection : injections) {
-                    if (injection.getTarget() == resourceReference.getOwnerClass() &&
-                            injection.getName().equals(resourceReference.getName())) {
-                        Context context = InjectionProcessor.unwrap(entry.getValue());
-                        try {
-                            return resourceReference.getResourceType().cast(context.lookup(injection.getJndiName()));
-                        } catch (NamingException e) {
-                            logger.warning("Injection data not found in JNDI context: jndiName='"
+ injection.getJndiName() + "', target=" + injection.getTarget().getName() + "/" + injection.getName());
-                            return null;
-                        }
+        try {
+            return resourceReference.getResourceType().cast(new InitialContext().lookup(resourceReference.getJndiName()));
+        } catch (NamingException e) {
+            for (Entry<CdiBeanInfo, Context> entry : this.contexts.entrySet()) {
+                if (entry.getKey().getBeanClass() == resourceReference.getOwnerClass()) {
+                    List<Injection> injections = entry.getKey().getInjections();
+                    for (Injection injection : injections) {
+                        if (injection.getTarget() == resourceReference.getOwnerClass() &&
+                                injection.getName().equals(resourceReference.getName()))
{
+                            Context context = InjectionProcessor.unwrap(entry.getValue());
+                            try {
+                                return resourceReference.getResourceType().cast(context.lookup(injection.getJndiName()));
+                            } catch (NamingException e2) {
+                                logger.warning("Injection data not found in JNDI context:
jndiName='" + injection.getJndiName() + "', target=" + injection.getTarget().getName() + "/"
+ injection.getName(), e2);
+                                return null;
+                            }
 
+                        }
                     }
                 }
             }
-        }
-        return null;
+            return null;
+//            throw new WebBeansException("Could not look up resource at " + resourceReference.getJndiName(),
e);
+       }
     }
 
     @Override
@@ -179,16 +192,19 @@ public class CdiResourceInjectionService
     }
 
     /**
-     * delegation of serialization behavior
-     */
-    public <T> void writeExternal(Bean<T> bean, T actualResource, ObjectOutput
out) throws IOException{}
-
-    /**
-     * delegation of serialization behavior
-     */
-    public <T> T readExternal(Bean<T> bean, ObjectInput out) throws IOException,
-								    ClassNotFoundException {
-        return null;
-    }
+      * delegation of serialization behavior
+      */
+     public <T> void writeExternal(Bean<T> bean, T actualResource, ObjectOutput
out) throws IOException {
+         //do nothing
+     }
+
+     /**
+      * delegation of serialization behavior
+      */
+     public <T> T readExternal(Bean<T> bean, ObjectInput out) throws IOException,
+             ClassNotFoundException {
+         return (T) ((ResourceBean)bean).getActualInstance();
+     }
+    
 
 }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java?rev=1056159&r1=1056158&r2=1056159&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
Fri Jan  7 02:00:46 2011
@@ -36,7 +36,6 @@ import org.apache.webbeans.config.WebBea
 import org.apache.webbeans.config.WebBeansFinder;
 import org.apache.webbeans.container.BeanManagerImpl;
 import org.apache.webbeans.container.InjectionResolver;
-import org.apache.webbeans.corespi.ServiceLoader;
 import org.apache.webbeans.ejb.common.util.EjbUtility;
 import org.apache.webbeans.intercept.InterceptorData;
 import org.apache.webbeans.logger.WebBeansLogger;
@@ -75,6 +74,7 @@ public class OpenEJBLifecycle implements
 
     /**Root container.*/
     private final BeanManagerImpl beanManager;
+    private final WebBeansContext webBeansContext;
 
     public OpenEJBLifecycle()
     {
@@ -85,13 +85,14 @@ public class OpenEJBLifecycle implements
     {
         beforeInitApplication(properties);
 
-        this.beanManager = (BeanManagerImpl) WebBeansFinder.getSingletonInstance(BeanManagerImpl.class.getName());
+        webBeansContext = WebBeansContext.getInstance();
+        this.beanManager = webBeansContext.getBeanManagerImpl();
         this.xmlDeployer = new WebBeansXMLConfigurator();
         this.deployer = new BeansDeployer(this.xmlDeployer);
-        this.jndiService = ServiceLoader.getService(JNDIService.class);
+        this.jndiService = webBeansContext.getService(JNDIService.class);
         this.beanManager.setXMLConfigurator(this.xmlDeployer);
-        this.scannerService = ServiceLoader.getService(ScannerService.class);
-        this.contextsService = ServiceLoader.getService(ContextsService.class);
+        this.scannerService = webBeansContext.getScannerService();
+        this.contextsService = webBeansContext.getContextsService();
 
         initApplication(properties);
     }

Modified: openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java?rev=1056159&r1=1056158&r2=1056159&view=diff
==============================================================================
--- openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
(original)
+++ openejb/trunk/openejb3/container/openejb-core/src/main/java/org/apache/openejb/cdi/ThreadSingletonServiceImpl.java
Fri Jan  7 02:00:46 2011
@@ -24,7 +24,6 @@ import org.apache.openejb.util.LogCatego
 import org.apache.openejb.util.Logger;
 import org.apache.webbeans.config.OpenWebBeansConfiguration;
 import org.apache.webbeans.config.WebBeansContext;
-import org.apache.webbeans.corespi.ServiceLoader;
 import org.apache.webbeans.spi.ContainerLifecycle;
 import org.apache.webbeans.spi.ResourceInjectionService;
 
@@ -50,9 +49,10 @@ public class ThreadSingletonServiceImpl 
         startupObject.getAppContext().set(OWBContext.class, owbContext);
         Object old = contextEntered(owbContext);
         try {
-            setConfiguration(WebBeansContext.getInstance().getOpenWebBeansConfiguration());
+            WebBeansContext webBeansContext = WebBeansContext.getInstance();
+            setConfiguration(webBeansContext.getOpenWebBeansConfiguration());
             try {
-                ServiceLoader.getService(ContainerLifecycle.class).startApplication(startupObject);
+                webBeansContext.getService(ContainerLifecycle.class).startApplication(startupObject);
             } catch (Exception e) {
                 throw new RuntimeException("couldn't start owb context", e);
             }



Mime
View raw message