Repository: tomee
Updated Branches:
  refs/heads/fb_tomee2_owb16 7620e2f31 -> ceedb8594


TOMEE-1572 fix @Initialized(ApplicationScoped.class) event


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/43287765
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/43287765
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/43287765

Branch: refs/heads/fb_tomee2_owb16
Commit: 4328776520f346e96d417de85e51384dfaf72d30
Parents: 7620e2f
Author: Mark Struberg <strub...@apache.org>
Authored: Wed May 6 22:51:22 2015 +0200
Committer: Mark Struberg <strub...@apache.org>
Committed: Wed May 6 22:51:22 2015 +0200

----------------------------------------------------------------------
 .../openejb/cdi/CdiAppContextsService.java      | 40 +++++++++++++++++---
 .../apache/openejb/cdi/OpenEJBLifecycle.java    |  2 +-
 2 files changed, 35 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/43287765/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
index 6ca395e..1d20b7a 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/CdiAppContextsService.java
@@ -18,16 +18,20 @@
 
 package org.apache.openejb.cdi;
 
+import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
+import org.apache.webbeans.annotation.InitializedLiteral;
 import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.event.EventMetadataImpl;
 import org.apache.webbeans.spi.ContextsService;
 import org.apache.webbeans.web.context.WebContextsService;
 
+import java.lang.annotation.Annotation;
 import java.util.ArrayList;
 import java.util.Collection;
-import javax.enterprise.context.ApplicationScoped;
-import javax.inject.Singleton;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletContextEvent;
 
 
 public class CdiAppContextsService extends WebContextsService implements 
ContextsService {
@@ -65,11 +69,35 @@ public class CdiAppContextsService extends 
WebContextsService implements Context
 
     @Override // this method is called after the deployment (BeansDeployer) 
but need beans to be here to get events
     public void init(final Object initializeObject) {
-        //Start application context
-        startContext(ApplicationScoped.class, initializeObject);
+        super.init(initializeObject);
+
+        Object payload = null;
+        if (initializeObject instanceof ServletContext) {
+            payload = initializeObject;
+        }
+
+        if (initializeObject != null) {
+            Object event = initializeObject;
+            if (StartupObject.class.isInstance(initializeObject)) {
+                final StartupObject so = 
StartupObject.class.cast(initializeObject);
+                if (so.isFromWebApp()) { // ear webapps
+                    event = so.getWebContext().getServletContext();
+                } else if (so.getAppInfo().webAppAlone) {
+                    event = 
SystemInstance.get().getComponent(ServletContext.class);
+                }
+            } else if (ServletContextEvent.class.isInstance(initializeObject)) 
{
+                event = 
ServletContextEvent.class.cast(initializeObject).getServletContext();
+            }
+            Object appEvent = event != null ? event : applicationContext;
+            webBeansContext.getBeanManagerImpl().fireEvent(
+                    appEvent,
+                    new EventMetadataImpl(null,
+                            ServletContext.class.isInstance(appEvent) ? 
ServletContext.class : Object.class, null,
+                            new 
Annotation[]{InitializedLiteral.INSTANCE_APPLICATION_SCOPED},
+                            webBeansContext),
+                    false);
+        }
 
-        //Start signelton context
-        startContext(Singleton.class, initializeObject);
     }
 
     public void destroy(final Object destroyObject) {

http://git-wip-us.apache.org/repos/asf/tomee/blob/43287765/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
----------------------------------------------------------------------
diff --git 
a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
 
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
index 4a05de7..3bfa8ad 100644
--- 
a/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
+++ 
b/container/openejb-core/src/main/java/org/apache/openejb/cdi/OpenEJBLifecycle.java
@@ -200,7 +200,7 @@ public class OpenEJBLifecycle implements ContainerLifecycle 
{
 
                 //Deploy bean from XML. Also configures deployments, 
interceptors, decorators.
                 deployer.deploy(scannerService);
-                contextsService.init(startupObject); // fire app event, this 
doesnt init anything else
+                contextsService.init(startupObject); // fire app event and 
also starts SingletonContext and ApplicationContext
             } catch (final Exception e1) {
                 
SystemInstance.get().getComponent(Assembler.class).logger.error("CDI Beans 
module deployment failed", e1);
                 throw new OpenEJBRuntimeException(e1);

Reply via email to