[webbeans-commits] Webbeans SVN: r329 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: contexts and 1 other directory.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Tue Nov 18 09:11:41 EST 2008


Author: nickarls
Date: 2008-11-18 09:11:41 -0500 (Tue, 18 Nov 2008)
New Revision: 329

Added:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java
Log:
Move ContextMap to context package
Remove return type from BeanMap put
Removed cache from SessionBeanMap

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-11-18 12:23:35 UTC (rev 328)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/ManagerImpl.java	2008-11-18 14:11:41 UTC (rev 329)
@@ -2,17 +2,14 @@
 
 import java.lang.annotation.Annotation;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.CopyOnWriteArrayList;
 
 import javax.webbeans.AmbiguousDependencyException;
 import javax.webbeans.BindingType;
 import javax.webbeans.ContextNotActiveException;
-import javax.webbeans.Dependent;
 import javax.webbeans.DeploymentException;
 import javax.webbeans.DuplicateBindingTypeException;
 import javax.webbeans.Observer;
@@ -32,6 +29,7 @@
 import org.jboss.webbeans.bean.SimpleBean;
 import org.jboss.webbeans.bean.proxy.ProxyPool;
 import org.jboss.webbeans.contexts.ApplicationContext;
+import org.jboss.webbeans.contexts.ContextMap;
 import org.jboss.webbeans.contexts.DependentContext;
 import org.jboss.webbeans.contexts.RequestContext;
 import org.jboss.webbeans.contexts.SessionContext;
@@ -43,40 +41,8 @@
 import org.jboss.webbeans.introspector.jlr.AnnotatedClassImpl;
 import org.jboss.webbeans.util.Reflections;
 
-import com.google.common.collect.ForwardingMap;
-
 public class ManagerImpl implements Manager
 {
-
-   private class ContextMap extends ForwardingMap<Class<? extends Annotation>, List<Context>>
-   {
-      
-      private Map<Class<? extends Annotation>, List<Context>> delegate;
-      
-      public ContextMap()
-      {
-         delegate = new HashMap<Class<? extends Annotation>, List<Context>>();
-      }
-
-      public List<Context> get(Class<? extends Annotation> key)
-      {
-         return (List<Context>) super.get(key);
-      }
-
-      public DependentContext getDependentContext()
-      {
-         return (DependentContext) get(Dependent.class).iterator().next();
-      }
-
-      @Override
-      protected Map<Class<? extends Annotation>, List<Context>> delegate()
-      {
-         return delegate;
-      }
-   }
-   
-   
-
    private List<Class<? extends Annotation>> enabledDeploymentTypes;
    private ModelManager modelManager;
    private EventBus eventBus;
@@ -157,11 +123,11 @@
       return this;
    }
 
-   public <T> void removeObserver(Observer<T> observer)
-   {
+//   public <T> void removeObserver(Observer<T> observer)
+//   {
+//
+//   }
 
-   }
-
    public <T> Set<AnnotatedMethod<Object>> resolveDisposalMethods(Class<T> apiType, Annotation... bindingTypes)
    {
       return new HashSet<AnnotatedMethod<Object>>();

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java	2008-11-18 12:23:35 UTC (rev 328)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/BeanMap.java	2008-11-18 14:11:41 UTC (rev 329)
@@ -69,5 +69,5 @@
     * 
     * @return The instance added
     */
-   public abstract <T extends Object> T put(Bean<? extends T> bean, T instance);
+   public abstract <T> void put(Bean<? extends T> bean, T instance);
 }
\ No newline at end of file

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/ContextMap.java	2008-11-18 14:11:41 UTC (rev 329)
@@ -0,0 +1,39 @@
+package org.jboss.webbeans.contexts;
+
+import java.lang.annotation.Annotation;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.webbeans.Dependent;
+import javax.webbeans.manager.Context;
+
+import com.google.common.collect.ForwardingMap;
+
+public class ContextMap extends
+      ForwardingMap<Class<? extends Annotation>, List<Context>>
+{
+
+   private Map<Class<? extends Annotation>, List<Context>> delegate;
+
+   public ContextMap()
+   {
+      delegate = new HashMap<Class<? extends Annotation>, List<Context>>();
+   }
+
+   public List<Context> get(Class<? extends Annotation> key)
+   {
+      return (List<Context>) super.get(key);
+   }
+
+   public DependentContext getDependentContext()
+   {
+      return (DependentContext) get(Dependent.class).iterator().next();
+   }
+
+   @Override
+   protected Map<Class<? extends Annotation>, List<Context>> delegate()
+   {
+      return delegate;
+   }
+}
\ No newline at end of file

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java	2008-11-18 12:23:35 UTC (rev 328)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SessionBeanMap.java	2008-11-18 14:11:41 UTC (rev 329)
@@ -37,15 +37,12 @@
 {
    private HttpSession session;
    private ManagerImpl manager;
-   private BeanMap cache;
    private String keyPrefix;
 
    public SessionBeanMap(ManagerImpl manager, String keyPrefix)
    {
       super();
       this.manager = manager;
-      // A "normal" BeanMap is used as cache
-      cache = new SimpleBeanMap();
       this.keyPrefix = keyPrefix;
    }
 
@@ -77,19 +74,15 @@
     * 
     * @return A unique key;
     */
-   @SuppressWarnings("unused")
    private String getBeanKey(Bean<?> bean) {
-      // TODO Append scope to in order to make class usable by multiple contexts
       return keyPrefix + manager.getBeans().indexOf(bean);
    }
    
    /**
     * Gets a bean from the session
     * 
-    * First, checks that the session is present. Then tries to get the instance from the cache and
-    * return it if found. It determines an ID for the bean which and looks for it in the session. 
-    * If the instance is found in, it is added to the cache. The bean instance is returned (null 
-    * if not found in the session).
+    * First, checks that the session is present. It determines an ID for the bean which and 
+    * looks for it in the session. The bean instance is returned (null if not found in the session).
     * 
     * @param bean The bean to get from the session 
     */
@@ -97,26 +90,15 @@
    public <T> T get(Bean<? extends T> bean)
    {
       checkSession();
-      T instance = cache.get(bean);
-      if (instance != null)
-      {
-         return instance;
-      }
       String id = getBeanKey(bean);
-      instance = (T) session.getAttribute(id);
-      if (instance != null)
-      {
-         cache.put(bean, instance);
-      }
-      return instance;
+      return (T) session.getAttribute(id);
    }
 
    /**
     * Removes a bean instance from the session
     * 
-    * First, checks that the session is present. Then, tries to get the bean instance from the cache.
-    * It determines an ID for the bean and that key is then removed from the session and the cache, whether
-    * they were present in the first place or not.
+    * First, checks that the session is present. It determines an ID for the bean and 
+    * that key is then removed from the session, whether it was present in the first place or not.
     * 
     * @param bean The bean whose instance to remove.
     */
@@ -124,9 +106,7 @@
    {
       checkSession();
       T instance = get(bean);
-      String id = getBeanKey(bean);
-      session.removeAttribute(id);
-      cache.remove(bean);
+      session.removeAttribute(getBeanKey(bean));
       return instance;
    }
 
@@ -135,7 +115,6 @@
     * 
     * First, checks that the session is present. Then, iterates
     * over the attribute names in the session and removes them if they start with the know prefix.
-    * Finally, clears the cache.
     */
    @SuppressWarnings("unchecked")
    public void clear()
@@ -146,7 +125,6 @@
          String name = (String) names.nextElement();
          session.removeAttribute(name);
       }
-      cache.clear();
    }
 
    /**
@@ -183,7 +161,7 @@
     * Puts a bean instance in the session
     * 
     * First, checks that the session is present. Generates a bean map key, puts the instance in the 
-    * session under that key and adds the bean instance to the cache.
+    * session under that key.
     * 
     * @param bean The bean to use as key
     * 
@@ -191,12 +169,10 @@
     * 
     * @return The instance added
     */
-   public <T> T put(Bean<? extends T> bean, T instance)
+   public <T> void put(Bean<? extends T> bean, T instance)
    {
       checkSession();
-      String id = getBeanKey(bean);
-      session.setAttribute(id, instance);
-      return cache.put(bean, instance);
+      session.setAttribute(getBeanKey(bean), instance);
    }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java	2008-11-18 12:23:35 UTC (rev 328)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/contexts/SimpleBeanMap.java	2008-11-18 14:11:41 UTC (rev 329)
@@ -66,10 +66,9 @@
       return delegate.keySet();
    }
    
-   @SuppressWarnings("unchecked")
-   public <T> T put(Bean<? extends T> bean, T instance)
+   public <T> void put(Bean<? extends T> bean, T instance)
    {
-      return (T) delegate.put(bean, instance);
+      delegate.put(bean, instance);
    }
 
 }
\ No newline at end of file




More information about the weld-commits mailing list