Author: peteroyle
Date: 2009-06-17 11:37:44 -0400 (Wed, 17 Jun 2009)
New Revision: 2839
Added:
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/util/WebBeansManagerUtils.java
Modified:
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/ShutdownManager.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/beans/ParametersFactory.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/MainTestBean.java
Log:
Brought up to latest spec, observing new manager initialisation events.
Modified:
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/ShutdownManager.java
===================================================================
---
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/ShutdownManager.java 2009-06-16
21:26:33 UTC (rev 2838)
+++
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/ShutdownManager.java 2009-06-17
15:37:44 UTC (rev 2839)
@@ -1,6 +1,7 @@
package org.jboss.webbeans.environment.se;
import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Current;
import javax.enterprise.inject.spi.BeanManager;
import javax.event.Observes;
@@ -8,13 +9,15 @@
import org.jboss.webbeans.environment.se.events.Shutdown;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.manager.api.WebBeansManager;
@ApplicationScoped
public class ShutdownManager
{
private static LogProvider log = Logging.getLogProvider(ShutdownManager.class);
-
+ private @Current WebBeansManager manager;
+
private boolean hasShutdownBeenCalled = false;
private Bootstrap bootstrap;
@@ -32,7 +35,7 @@
if (!hasShutdownBeenCalled)
{
- hasShutdownBeenCalled = true;
+ hasShutdownBeenCalled = true;
bootstrap.shutdown();
}
else
@@ -42,6 +45,14 @@
}
}
}
+
+ /**
+ * Shutdown WebBeans SE gracefully (call this as an alternative to firing the
+ * "@Shutdown Manager" event.
+ */
+ public void shutdown() {
+ shutdown(manager);
+ }
public void setBootstrap(Bootstrap bootstrap)
{
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-06-16
21:26:33 UTC (rev 2838)
+++
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/StartMain.java 2009-06-17
15:37:44 UTC (rev 2839)
@@ -25,6 +25,7 @@
import org.jboss.webbeans.context.api.helpers.ConcurrentHashMapBeanStore;
import org.jboss.webbeans.environment.se.discovery.SEWebBeanDiscovery;
import org.jboss.webbeans.environment.se.util.Reflections;
+import org.jboss.webbeans.environment.se.util.WebBeansManagerUtils;
import org.jboss.webbeans.manager.api.WebBeansManager;
/**
@@ -56,7 +57,7 @@
this.applicationBeanStore = new ConcurrentHashMapBeanStore();
}
- private void go()
+ public BeanManager go()
{
bootstrap.setEnvironment(Environments.SE);
bootstrap.getServices().add(WebBeanDiscovery.class, new SEWebBeanDiscovery()
{});
@@ -64,7 +65,9 @@
bootstrap.initialize();
this.manager = bootstrap.getManager();
bootstrap.boot();
-
bootstrap.getManager().getInstanceByType(ShutdownManager.class).setBootstrap(bootstrap);
+ WebBeansManagerUtils.getInstanceByType(manager, ShutdownManager.class).
+ setBootstrap(bootstrap);
+ return this.manager;
}
/**
@@ -75,18 +78,13 @@
*/
public static void main(String[] args)
{
- new StartMain(args).main();
+ new StartMain(args).go();
}
- public BeanManager main()
- {
- go();
- return manager;
- }
-
public static String[] getParameters()
{
// TODO(PR): make immutable
return PARAMETERS;
}
+
}
Modified:
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/beans/ParametersFactory.java
===================================================================
---
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/beans/ParametersFactory.java 2009-06-16
21:26:33 UTC (rev 2838)
+++
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/beans/ParametersFactory.java 2009-06-17
15:37:44 UTC (rev 2839)
@@ -23,7 +23,7 @@
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
-import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
import javax.event.Observes;
@@ -86,7 +86,7 @@
*
* @param manager The Manager which has been initialized.
*/
- public void initArgs(@Observes @BeforeBeanDiscovery BeanManager manager) {
+ public void initArgs(@Observes AfterBeanDiscovery after) {
this.setArgs( StartMain.PARAMETERS );
}
}
Added:
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/util/WebBeansManagerUtils.java
===================================================================
---
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/util/WebBeansManagerUtils.java
(rev 0)
+++
extensions/trunk/se/src/main/java/org/jboss/webbeans/environment/se/util/WebBeansManagerUtils.java 2009-06-17
15:37:44 UTC (rev 2839)
@@ -0,0 +1,32 @@
+/**
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, 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.util;
+
+import java.lang.annotation.Annotation;
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ *
+ * @author PeteR
+ */
+public class WebBeansManagerUtils {
+
+ public static <T> T getInstanceByType(BeanManager manager, Class<T> type,
Annotation... bindings) {
+ return (T)manager.getReference(
+ manager.getBeans(type).iterator().next(), type);
+ }
+}
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-06-16
21:26:33 UTC (rev 2838)
+++
extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/StartMainTest.java 2009-06-17
15:37:44 UTC (rev 2839)
@@ -23,6 +23,7 @@
import org.jboss.webbeans.environment.se.events.Shutdown;
import org.jboss.webbeans.environment.se.test.beans.MainTestBean;
import org.jboss.webbeans.environment.se.test.beans.ParametersTestBean;
+import org.jboss.webbeans.environment.se.util.WebBeansManagerUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
@@ -44,9 +45,9 @@
public void testMain()
{
String[] args = ARGS ;
- BeanManager manager = new StartMain(args).main();
+ BeanManager manager = new StartMain(args).go();
- MainTestBean mainTestBean = manager.getInstanceByType( MainTestBean.class );
+ MainTestBean mainTestBean = WebBeansManagerUtils.getInstanceByType( manager,
MainTestBean.class );
Assert.assertNotNull( mainTestBean );
ParametersTestBean paramsBean = mainTestBean.getParametersTestBean();
@@ -60,16 +61,6 @@
Assert.assertEquals( ARGS[2], paramsBean.getParameters().get(2) );
shutdownManager(manager);
- boolean contextNotActive = false;
- try
- {
- assert manager.getInstanceByType(MainTestBean.class) == null;
- }
- catch (Exception e)
- {
- contextNotActive = true;
- }
- assert contextNotActive;
}
/**
@@ -79,9 +70,9 @@
@Test
public void testMainEmptyArgs()
{
- BeanManager manager = new StartMain(ARGS_EMPTY).main();
+ BeanManager manager = new StartMain(ARGS_EMPTY).go();
- MainTestBean mainTestBean = manager.getInstanceByType( MainTestBean.class );
+ MainTestBean mainTestBean = WebBeansManagerUtils.getInstanceByType( manager,
MainTestBean.class );
Assert.assertNotNull( mainTestBean );
ParametersTestBean paramsBean = mainTestBean.getParametersTestBean();
Modified:
extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/MainTestBean.java
===================================================================
---
extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/MainTestBean.java 2009-06-16
21:26:33 UTC (rev 2838)
+++
extensions/trunk/se/src/test/java/org/jboss/webbeans/environment/se/test/beans/MainTestBean.java 2009-06-17
15:37:44 UTC (rev 2839)
@@ -16,16 +16,17 @@
*/
package org.jboss.webbeans.environment.se.test.beans;
+import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Current;
import javax.enterprise.inject.Initializer;
-import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.AfterDeploymentValidation;
import javax.event.Observes;
/**
*
* @author Peter Royle
*/
+@ApplicationScoped
public class MainTestBean
{
@@ -41,7 +42,7 @@
paramsTestBean.getParameters();
}
- public void mainMethod(@Observes @AfterBeanDiscovery BeanManager manager) {
+ public void mainMethod(@Observes AfterDeploymentValidation after) {
System.out.println( "Starting main test app" );
}