You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by db...@apache.org on 2012/06/29 22:22:13 UTC

svn commit: r1355551 - /openejb/trunk/sandbox/tomee-mojarra/src/main/java/org/superbiz/TomEEInjectionProvider.java

Author: dblevins
Date: Fri Jun 29 20:22:12 2012
New Revision: 1355551

URL: http://svn.apache.org/viewvc?rev=1355551&view=rev
Log:
Should work assuming:
 1. Mojarra will pass in ServletContext as it seems it might
 2. We add WebContext to the ServletContext attributes (we currently don't)
TOMEE-259

Modified:
    openejb/trunk/sandbox/tomee-mojarra/src/main/java/org/superbiz/TomEEInjectionProvider.java

Modified: openejb/trunk/sandbox/tomee-mojarra/src/main/java/org/superbiz/TomEEInjectionProvider.java
URL: http://svn.apache.org/viewvc/openejb/trunk/sandbox/tomee-mojarra/src/main/java/org/superbiz/TomEEInjectionProvider.java?rev=1355551&r1=1355550&r2=1355551&view=diff
==============================================================================
--- openejb/trunk/sandbox/tomee-mojarra/src/main/java/org/superbiz/TomEEInjectionProvider.java (original)
+++ openejb/trunk/sandbox/tomee-mojarra/src/main/java/org/superbiz/TomEEInjectionProvider.java Fri Jun 29 20:22:12 2012
@@ -2,35 +2,43 @@ package org.superbiz;
 
 import com.sun.faces.spi.DiscoverableInjectionProvider;
 import com.sun.faces.spi.InjectionProviderException;
+import org.apache.openejb.OpenEJBException;
+import org.apache.openejb.core.WebContext;
 import org.apache.webbeans.config.WebBeansContext;
 import org.apache.webbeans.inject.OWBInjector;
 
+import javax.servlet.ServletContext;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
 public class TomEEInjectionProvider extends DiscoverableInjectionProvider {
-    private final Map<Object, OWBInjector> injectors = new ConcurrentHashMap<Object, OWBInjector>();
+
+    private final ServletContext servletContext;
+    private final WebContext webContext;
+
+    public TomEEInjectionProvider(ServletContext servletContext) {
+        this.servletContext = servletContext;
+        final Object attribute = servletContext.getAttribute(WebContext.class.getName());
+
+        if (attribute == null) throw new IllegalStateException("No WebContext found in ServletContext attributes");
+
+        if (!(attribute instanceof WebContext)) throw new IllegalStateException("WebContext entry in ServletContext attributes is not an instance of WebContext");
+
+        webContext = (WebContext) attribute;
+    }
 
     @Override
     public void inject(final Object managedBean) throws InjectionProviderException {
-        final OWBInjector injector = new OWBInjector(WebBeansContext.currentInstance());
-        injectors.put(managedBean, injector);
         try {
-            injectors.get(managedBean).inject(managedBean);
-        } catch (Exception e) {
+            webContext.inject(managedBean);
+        } catch (OpenEJBException e) {
             throw new InjectionProviderException(e);
         }
     }
 
     @Override
     public void invokePreDestroy(Object managedBean) throws InjectionProviderException {
-        if (injectors.containsKey(managedBean)) {
-            try {
-                injectors.remove(managedBean).destroy();
-            } catch (Exception e) {
-                throw new InjectionProviderException(e);
-            }
-        }
+        webContext.destroy(managedBean);
     }
 
     @Override