[webbeans-commits] Webbeans SVN: r140 - ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Fri Oct 24 08:42:57 EDT 2008


Author: nickarls
Date: 2008-10-24 08:42:57 -0400 (Fri, 24 Oct 2008)
New Revision: 140

Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java
Log:
Added add(Bean<?> component, Object instance)
rename values => beans
set active=false when destroy called (correct?)

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-24 12:20:59 UTC (rev 139)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BasicContext.java	2008-10-24 12:42:57 UTC (rev 140)
@@ -13,82 +13,89 @@
  * Basic implementation of javax.webbeans.Context, backed by a HashMap
  * 
  * @author Shane Bryzak
- *
+ * @author Nicklas Karlsson (nickarls at gmail.com)
  */
 public class BasicContext implements Context
 {
-   private Map<Bean<? extends Object>, Object> values;
+   private Map<Bean<? extends Object>, Object> beans;
    private Class<? extends Annotation> scopeType;
    private boolean active;
-   
+
    public BasicContext(Class<? extends Annotation> scopeType)
    {
       this.scopeType = scopeType;
-      values = new HashMap<Bean<?>,Object>();
+      beans = new HashMap<Bean<?>, Object>();
       active = true;
    }
-   
-   public <T> T get(Bean<T> component, boolean create) 
+
+   public void add(Bean<?> component, Object instance)
    {
+      beans.put(component, instance);
+   }
+
+   public <T> T get(Bean<T> component, boolean create)
+   {
       if (!active)
       {
          throw new ContextNotActiveException();
       }
-      T instance = (T) values.get(component);
+      T instance = (T) beans.get(component);
       if (instance != null)
       {
          return instance;
       }
-      
+
       if (!create)
       {
          return null;
       }
-      
+
       // TODO should component creation be synchronized?
-      
+
       instance = component.create();
-      
-      values.put(component, instance);
+
+      beans.put(component, instance);
       return instance;
    }
 
-   public Class<? extends Annotation> getScopeType() 
+   public Class<? extends Annotation> getScopeType()
    {
       return scopeType;
    }
 
-   public <T> void remove(Manager container, Bean<T> bean) 
+   public <T> void remove(Manager container, Bean<T> bean)
    {
-      T instance = (T) values.get(bean);
-      
+      T instance = (T) beans.get(bean);
+
       if (instance != null)
       {
-         values.remove(bean);
+         beans.remove(bean);
          bean.destroy(instance);
       }
       else
       {
          // TODO is this the correct exception to throw? See section 9.1 of spec
-         throw new RuntimeException("Component " + bean.getName() + " cannot be removed as it " + 
-               "does not exist in [" + scopeType + "] context.");
+         throw new RuntimeException("Component " + bean.getName() + " cannot be removed as it " + "does not exist in [" + scopeType + "] context.");
       }
    }
-   
+
    public void destroy(Manager container)
    {
-      for (Bean c : values.keySet())
+      for (Bean c : beans.keySet())
       {
-         c.destroy(values.get(c));
+         c.destroy(beans.get(c));
       }
-      values.clear();
+      beans.clear();
+      active = false;
    }
-   
-   public boolean isActive() {
+
+   public boolean isActive()
+   {
       return active;
    }
-   
-   public void setActive(boolean active) {
+
+   public void setActive(boolean active)
+   {
       this.active = active;
    }
 




More information about the weld-commits mailing list