Author: gavin.king(a)jboss.com
Date: 2008-12-06 16:52:42 -0500 (Sat, 06 Dec 2008)
New Revision: 425
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/PassivatingContextTest.java
Log:
make the contexts which are singletons really be singletons, instead of pretending they
are not and then using singleton-ness of root manager to access them :)
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-06
21:28:44 UTC (rev 424)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java 2008-12-06
21:52:42 UTC (rev 425)
@@ -156,9 +156,9 @@
if (contexts.length == 0)
{
addContext(new DependentContext());
- addContext(new RequestContext());
- addContext(new SessionContext());
- addContext(new ApplicationContext());
+ addContext(RequestContext.INSTANCE);
+ addContext(SessionContext.INSTANCE);
+ addContext(ApplicationContext.INSTANCE);
}
else
{
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java 2008-12-06
21:28:44 UTC (rev 424)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ApplicationContext.java 2008-12-06
21:52:42 UTC (rev 425)
@@ -21,8 +21,6 @@
import javax.webbeans.ApplicationScoped;
-import org.jboss.webbeans.ManagerImpl;
-
/**
* The Application context
*
@@ -32,6 +30,9 @@
*/
public class ApplicationContext extends AbstractContext
{
+
+ public static ApplicationContext INSTANCE = new ApplicationContext();
+
// The beans
private BeanMap beanMap;
// Is the context active?
@@ -40,7 +41,7 @@
/**
* Constructor
*/
- public ApplicationContext()
+ protected ApplicationContext()
{
super(ApplicationScoped.class);
this.active = new AtomicBoolean(true);
@@ -68,16 +69,6 @@
}
/**
- * Helper method for accessing context
- *
- * @return The application context
- */
- public static ApplicationContext instance()
- {
- return (ApplicationContext)
ManagerImpl.rootManager().getBuiltInContext(ApplicationScoped.class);
- }
-
- /**
* Indicates if the context is active
*
* @return True if active, false otherwise
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java 2008-12-06
21:28:44 UTC (rev 424)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/RequestContext.java 2008-12-06
21:52:42 UTC (rev 425)
@@ -19,8 +19,6 @@
import javax.webbeans.RequestScoped;
-import org.jboss.webbeans.ManagerImpl;
-
/**
* The request context
*
@@ -28,24 +26,15 @@
*/
public class RequestContext extends BasicContext
{
+
+ public static RequestContext INSTANCE = new RequestContext();
/**
* Constructor
*/
- public RequestContext()
+ protected RequestContext()
{
super(RequestScoped.class);
- }
-
- /**
- * Helper method for accessing context
- *
- * @return The request context
- */
- public static RequestContext instance()
- {
- return (RequestContext)
ManagerImpl.rootManager().getBuiltInContext(RequestScoped.class);
- }
-
+ }
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java 2008-12-06
21:28:44 UTC (rev 424)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionContext.java 2008-12-06
21:52:42 UTC (rev 425)
@@ -19,7 +19,6 @@
import javax.webbeans.SessionScoped;
-import org.jboss.webbeans.ManagerImpl;
import org.jboss.webbeans.log.LogProvider;
import org.jboss.webbeans.log.Logging;
@@ -31,13 +30,16 @@
public class SessionContext extends AbstractContext
{
private static LogProvider log = Logging.getLogProvider(SessionContext.class);
+
+ public static SessionContext INSTANCE = new SessionContext();
+
// The beans
private ThreadLocal<BeanMap> beanMap;
/**
* Constructor
*/
- public SessionContext()
+ protected SessionContext()
{
super(SessionScoped.class);
log.trace("Created session context");
@@ -65,14 +67,4 @@
this.beanMap.set(beanMap);
}
- /**
- * Helper method for accessing context
- *
- * @return The session context
- */
- public static SessionContext instance()
- {
- return (SessionContext)
ManagerImpl.rootManager().getBuiltInContext(SessionScoped.class);
- }
-
}
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
===================================================================
---
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2008-12-06
21:28:44 UTC (rev 424)
+++
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java 2008-12-06
21:52:42 UTC (rev 425)
@@ -57,7 +57,7 @@
servletContext = context;
Bootstrap bootstrap = new Bootstrap();
bootstrap.boot(getWebBeanDiscovery());
- ApplicationContext.instance().setBeanMap(new ApplicationBeanMap(servletContext));
+ ApplicationContext.INSTANCE.setBeanMap(new ApplicationBeanMap(servletContext));
}
/**
@@ -65,8 +65,8 @@
*/
public static void endApplication()
{
- ApplicationContext.instance().destroy();
- ApplicationContext.instance().setBeanMap(null);
+ ApplicationContext.INSTANCE.destroy();
+ ApplicationContext.INSTANCE.setBeanMap(null);
servletContext = null;
}
@@ -86,8 +86,8 @@
*/
public static void endSession(HttpSession session)
{
- SessionContext.instance().destroy();
- SessionContext.instance().setBeanMap(null);
+ SessionContext.INSTANCE.destroy();
+ SessionContext.INSTANCE.setBeanMap(null);
}
/**
@@ -99,7 +99,7 @@
*/
public static void beginRequest(HttpServletRequest request)
{
- SessionContext.instance().setBeanMap(new SessionBeanMap(request.getSession()));
+ SessionContext.INSTANCE.setBeanMap(new SessionBeanMap(request.getSession()));
}
/**
@@ -109,8 +109,8 @@
*/
public static void endRequest(HttpServletRequest request)
{
- RequestContext.instance().destroy();
- SessionContext.instance().setBeanMap(null);
+ RequestContext.INSTANCE.destroy();
+ SessionContext.INSTANCE.setBeanMap(null);
}
/**
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-12-06
21:28:44 UTC (rev 424)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/AbstractTest.java 2008-12-06
21:52:42 UTC (rev 425)
@@ -17,7 +17,6 @@
protected MockManagerImpl manager;
protected Bootstrap bootstrap;
-
@BeforeMethod
public final void before()
@@ -25,7 +24,7 @@
manager = new MockManagerImpl();
MockManagerImpl.setInstance(manager);
// Mock the ApplicationContext as a simple map
- ApplicationContext.instance().setBeanMap(new SimpleBeanMap());
+ ApplicationContext.INSTANCE.setBeanMap(new SimpleBeanMap());
bootstrap = new MockBootstrap();
init();
}
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-12-06
21:28:44 UTC (rev 424)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ManagerTest.java 2008-12-06
21:52:42 UTC (rev 425)
@@ -21,7 +21,7 @@
@Test(expectedExceptions={ContextNotActiveException.class},
groups={"manager"}) @SpecAssertion(section="8.6")
public void testGetContextWithNoActiveContextsFails()
{
- Context requestContext = new RequestContext();
+ Context requestContext = new RequestContext() {};
((AbstractContext)requestContext).setActive(false);
manager.setContexts(requestContext);
manager.getContext(RequestScoped.class);
@@ -30,8 +30,8 @@
@Test(expectedExceptions={IllegalArgumentException.class},
groups={"manager"}) @SpecAssertion(section="8.6")
public void testGetContextWithTooManyActiveContextsFails()
{
- Context firstContext = new RequestContext();
- Context secondContext = new RequestContext();
+ Context firstContext = new RequestContext() {};
+ Context secondContext = new RequestContext() {};
manager.setContexts(firstContext, secondContext);
manager.getContext(RequestScoped.class);
assert true;
@@ -48,7 +48,7 @@
@Test(groups={"manager"}) @SpecAssertion(section="8.6")
public void testGetContextReturnsActiveContext()
{
- Context requestContext = new RequestContext();
+ Context requestContext = new RequestContext() {};
manager.setContexts(requestContext);
Context testContext = manager.getContext(RequestScoped.class);
assert testContext == requestContext;
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java 2008-12-06
21:28:44 UTC (rev 424)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/NormalContextTest.java 2008-12-06
21:52:42 UTC (rev 425)
@@ -35,7 +35,7 @@
@BeforeMethod
public void initContext() {
- context = new RequestContext();
+ context = new RequestContext() {};
}
@Test(groups="contexts") @SpecAssertion(section="8.1")
Modified:
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/PassivatingContextTest.java
===================================================================
---
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/PassivatingContextTest.java 2008-12-06
21:28:44 UTC (rev 424)
+++
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/PassivatingContextTest.java 2008-12-06
21:52:42 UTC (rev 425)
@@ -19,7 +19,7 @@
@BeforeMethod
public void initContext()
{
- context = new RequestContext();
+ context = new RequestContext() {};
}
@Test(groups = {"stub", "contexts", "passivation" })
@SpecAssertion(section = "8.4")