[webbeans-commits] Webbeans SVN: r3777 - in extensions/trunk/se/src: main/java/org/jboss/webbeans/environment/se/events and 2 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Sep 24 06:44:54 EDT 2009


Author: peteroyle
Date: 2009-09-24 06:44:54 -0400 (Thu, 24 Sep 2009)
New Revision: 3777

Added:
   extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/ContainerInitialized.java
   extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/InitObserverTestBean.java
Modified:
   extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java
   extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/StartMainTest.java
   extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/ObserverTestBean.java
Log:
Added SE-specific application initialisation event - ContainerInitialized.

Modified: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java	2009-09-23 22:08:02 UTC (rev 3776)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java	2009-09-24 10:44:54 UTC (rev 3777)
@@ -24,6 +24,7 @@
 import org.jboss.webbeans.context.api.BeanStore;
 import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
 import org.jboss.webbeans.environment.se.discovery.SEWebBeansDeployment;
+import org.jboss.webbeans.environment.se.events.ContainerInitialized;
 import org.jboss.webbeans.environment.se.util.Reflections;
 import org.jboss.webbeans.environment.se.util.WebBeansManagerUtils;
 import org.jboss.webbeans.manager.api.WebBeansManager;
@@ -73,6 +74,8 @@
       WebBeansManagerUtils.getInstanceByType(manager, ShutdownManager.class).setBootstrap(bootstrap);
       bootstrap.validateBeans();
       bootstrap.endInitialization();
+
+      this.manager.fireEvent(new ContainerInitialized());
       return this.manager;
    }
 

Added: extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/ContainerInitialized.java
===================================================================
--- extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/ContainerInitialized.java	                        (rev 0)
+++ extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/events/ContainerInitialized.java	2009-09-24 10:44:54 UTC (rev 3777)
@@ -0,0 +1,28 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.events;
+
+/**
+ * The event that is fired when the WebBeans CDI container is initialized and
+ * ready for applications to take control, which it may do by observing this
+ * event.
+ *
+ * @author Peter Royle
+ */
+public class ContainerInitialized {
+
+}

Modified: extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/StartMainTest.java
===================================================================
--- extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/StartMainTest.java	2009-09-23 22:08:02 UTC (rev 3776)
+++ extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/StartMainTest.java	2009-09-24 10:44:54 UTC (rev 3777)
@@ -22,6 +22,7 @@
 import org.jboss.webbeans.environment.se.StartMain;
 import org.jboss.webbeans.environment.se.events.Shutdown;
 import org.jboss.webbeans.environment.se.test.beans.CustomEvent;
+import org.jboss.webbeans.environment.se.test.beans.InitObserverTestBean;
 import org.jboss.webbeans.environment.se.test.beans.MainTestBean;
 import org.jboss.webbeans.environment.se.test.beans.ObserverTestBean;
 import org.jboss.webbeans.environment.se.test.beans.ParametersTestBean;
@@ -88,13 +89,17 @@
    @Test
    public void testObservers()
    {
+      InitObserverTestBean.reset();
       ObserverTestBean.reset();
-      
+
       BeanManager manager = new StartMain(ARGS_EMPTY).go();
       manager.fireEvent(new CustomEvent());
-      
+
       Assert.assertTrue(ObserverTestBean.isBuiltInObserved());
       Assert.assertTrue(ObserverTestBean.isCustomObserved());
+      Assert.assertTrue(ObserverTestBean.isInitObserved());
+
+      Assert.assertTrue(InitObserverTestBean.isInitObserved());
    }
 
    private void shutdownManager(BeanManager manager)

Added: extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/InitObserverTestBean.java
===================================================================
--- extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/InitObserverTestBean.java	                        (rev 0)
+++ extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/InitObserverTestBean.java	2009-09-24 10:44:54 UTC (rev 3777)
@@ -0,0 +1,57 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, Red Hat, Inc. and/or its affiliates, and individual
+ * contributors by the @authors tag. See the copyright.txt in the
+ * distribution for a full listing of individual contributors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jboss.webbeans.environment.se.test.beans;
+
+import javax.enterprise.event.Observes;
+import javax.inject.Inject;
+import org.jboss.webbeans.environment.se.events.ContainerInitialized;
+
+/**
+ * Tests the observing of both built-in and application-specific events.
+ * 
+ * @author Peter Royle
+ */
+public class InitObserverTestBean
+{
+
+   private static boolean initObserved = false;
+
+   @Inject MainTestBean bean;
+
+   public InitObserverTestBean()
+   {
+   }
+
+   public void observeInitEvent(@Observes ContainerInitialized event) {
+       initObserved = true;
+       assert this.bean != null;
+   }
+   
+   public static void reset()
+   {
+      initObserved = false;
+   }
+
+   /**
+    * @return
+    */
+   public static boolean isInitObserved()
+   {
+      return initObserved;
+   }
+
+}

Modified: extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/ObserverTestBean.java
===================================================================
--- extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/ObserverTestBean.java	2009-09-23 22:08:02 UTC (rev 3776)
+++ extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/ObserverTestBean.java	2009-09-24 10:44:54 UTC (rev 3777)
@@ -16,10 +16,11 @@
  */
 package org.jboss.webbeans.environment.se.test.beans;
 
-import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.event.Observes;
 import javax.enterprise.inject.spi.AfterDeploymentValidation;
 import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+import org.jboss.webbeans.environment.se.events.ContainerInitialized;
 
 /**
  * Tests the observing of both built-in and application-specific events.
@@ -31,7 +32,10 @@
 
    private static boolean builtInObserved = false;
    private static boolean customObserved = false;
+   private static boolean initObserved = false;
 
+   @Inject MainTestBean bean;
+
    public ObserverTestBean()
    {
    }
@@ -39,17 +43,26 @@
    public void observeBuiltInEvent(@Observes AfterDeploymentValidation after)
    {
       builtInObserved = true;
+       assert this.bean == null;
    }
 
    public void observeCustomEvent(@Observes CustomEvent event)
    {
       customObserved = true;
+       assert this.bean != null;
    }
+
+   public void observeInitEvent(@Observes ContainerInitialized event)
+   {
+       initObserved = true;
+       assert this.bean != null;
+   }
    
    public static void reset()
    {
       customObserved = false;
       builtInObserved = false;
+      initObserved = false;
    }
 
    /**
@@ -68,4 +81,12 @@
       return customObserved;
    }
 
+   /**
+    * @return
+    */
+   public static boolean isInitObserved()
+   {
+      return initObserved;
+   }
+
 }




More information about the weld-commits mailing list