Author: pete.muir(a)jboss.org
Date: 2008-10-26 15:14:11 -0400 (Sun, 26 Oct 2008)
New Revision: 170
Modified:
ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java
ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java
Log:
Remove remove method
Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java 2008-10-26
18:53:43 UTC (rev 169)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java 2008-10-26
19:14:11 UTC (rev 170)
@@ -15,8 +15,8 @@
*
* @author Shane Bryzak
* @author Nicklas Karlsson (nickarls(a)gmail.com)
- * @author Pete\ Muir
- * @
+ * @author Pete Muir
+ *
*/
public class BasicContext implements Context
{
@@ -54,7 +54,15 @@
{
throw new ContextNotActiveException();
}
+
+ if (beans == null)
+ {
+ // Context has been destroyed
+ return null;
+ }
+
T instance = beans.get(bean);
+
if (instance != null)
{
return instance;
@@ -78,28 +86,18 @@
return scopeType;
}
- public <T> void remove(Manager manager, Bean<T> bean)
+ private <T> void destroy(Manager manager, Bean<T> bean)
{
- T instance = beans.get(bean);
-
- if (instance != null)
- {
- beans.remove(bean);
- bean.destroy(instance);
- }
- else
- {
- // TODO is this the correct exception to throw? See section 9.1 of spec
- throw new RuntimeException("Bean " + bean.getName() + " cannot be
removed as it " + "does not exist in [" + scopeType + "]
context.");
- }
+ bean.destroy(beans.get(bean));
}
public void destroy(Manager manager)
{
for (Bean<? extends Object> bean : beans.keySet())
{
- remove(manager, bean);
+ destroy(manager, bean);
}
+ beans = null;
}
public boolean isActive()
Modified: ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java
===================================================================
--- ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java 2008-10-26
18:53:43 UTC (rev 169)
+++ ri/trunk/webbeans-ri/src/test/java/org/jboss/webbeans/test/ContextTest.java 2008-10-26
19:14:11 UTC (rev 170)
@@ -63,10 +63,10 @@
}
@Test(groups="contexts")
- public void testRemoveBean() {
+ public void testDestroy() {
Bean<Tuna> tunaBean = Util.createSimpleWebBean(Tuna.class, manager);
- Tuna firstTuna = context.get(tunaBean, true);
- ((BasicContext)context).remove(manager, tunaBean);
+ assert context.get(tunaBean, true) instanceof Tuna;
+ ((BasicContext)context).destroy(manager);
assert context.get(tunaBean, false) == null;
}
}
Show replies by date