[webbeans-commits] Webbeans SVN: r1657 - in ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans: bean and 6 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Mon Feb 23 04:37:38 EST 2009


Author: nickarls
Date: 2009-02-23 04:37:38 -0500 (Mon, 23 Feb 2009)
New Revision: 1657

Added:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/BeanMapAdaptor.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/SimpleBeanMapAdaptor.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockConversationManager.java
Modified:
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/AbstractMapContext.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/AbstractBeanMap.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/BeanMap.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/SimpleBeanMap.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/AbstractLifecycle.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ApplicationBeanMap.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ConversationBeanMap.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/HttpSessionBeanMap.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java
   ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansServletFilter.java
Log:
Conversation management -> lifecycle for review

String based keyPrefix -> BeanMapAdaptor (hmm, not really an adaptor, what would be the correct term?)

Minor import cleanups etc

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/BeanValidator.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -22,7 +22,6 @@
 import java.util.List;
 import java.util.Set;
 
-import javax.context.Dependent;
 import javax.inject.AmbiguousDependencyException;
 import javax.inject.DefinitionException;
 import javax.inject.IllegalProductException;
@@ -41,7 +40,6 @@
 import org.jboss.webbeans.bean.ProducerMethodBean;
 import org.jboss.webbeans.bean.RIBean;
 import org.jboss.webbeans.introspector.AnnotatedField;
-import org.jboss.webbeans.introspector.AnnotatedParameter;
 import org.jboss.webbeans.metadata.MetaDataCache;
 import org.jboss.webbeans.util.Beans;
 import org.jboss.webbeans.util.ListComparator;

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/bean/SimpleBean.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -25,7 +25,6 @@
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 import javax.context.CreationalContext;
-import javax.context.Dependent;
 import javax.inject.DefinitionException;
 import javax.inject.Initializer;
 import javax.persistence.PersistenceContext;

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/AbstractMapContext.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/AbstractMapContext.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/AbstractMapContext.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -25,7 +25,6 @@
 import javax.inject.manager.Bean;
 
 import org.jboss.webbeans.context.beanmap.BeanMap;
-import org.jboss.webbeans.jsf.JSFHelper;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
 
@@ -113,7 +112,7 @@
    public void destroy()
    {
       log.trace("Destroying context");
-      for (Contextual<? extends Object> bean : getBeanMap().keySet())
+      for (Contextual<? extends Object> bean : getBeanMap().getContents())
       {
          destroy(bean);
       }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/AbstractBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/AbstractBeanMap.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/AbstractBeanMap.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -26,7 +26,6 @@
 import org.jboss.webbeans.CurrentManager;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
-import org.jboss.webbeans.servlet.ApplicationBeanMap;
 import org.jboss.webbeans.util.EnumerationIterable;
 import org.jboss.webbeans.util.Names;
 
@@ -44,13 +43,13 @@
    /**
     * Gets a bean from the map
     * 
-    * @param bean The bean to get
+    * @param contextual The bean to get
     * @return The instance
     */
    @SuppressWarnings("unchecked")
-   public <T> T get(Contextual<? extends T> bean)
+   public <T> T get(Contextual<? extends T> contextual)
    {
-      String key = getBeanKey(bean);
+      String key = getBeanMapAdaptor().getContextualKey(contextual);
       T instance = (T) getAttribute(key);
       log.trace("Looked for " + key + " and got " + instance);
       return instance;
@@ -59,13 +58,13 @@
    /**
     * Removes an instance from the map
     * 
-    * @param bean The bean of the instance to remove
+    * @param contextual The bean of the instance to remove
     * @return The removed instance
     */
-   public <T> T remove(Contextual<? extends T> bean)
+   public <T> T remove(Contextual<? extends T> contextual)
    {
-      T instance = get(bean);
-      String key = getBeanKey(bean);
+      T instance = get(contextual);
+      String key = getBeanMapAdaptor().getContextualKey(contextual);
       removeAttribute(key);
       log.trace("Removed bean under key " + key);
       return instance;
@@ -76,9 +75,9 @@
     */
    public void clear()
    {
-      for (String name : getFilteredAttributeNames())
+      for (String attributeName : getFilteredAttributeNames())
       {
-         removeAttribute(name);
+         removeAttribute(attributeName);
       }
       log.trace("Bean Map cleared");
    }
@@ -88,16 +87,17 @@
     * 
     * @return The beans
     */
-   public Iterable<Contextual<? extends Object>> keySet()
+   public Iterable<Contextual<? extends Object>> getContents()
    {
-      List<Contextual<?>> beans = new ArrayList<Contextual<?>>();
-      for (String name : getFilteredAttributeNames())
+      List<Contextual<?>> contextuals = new ArrayList<Contextual<?>>();
+      BeanMapAdaptor adaptor = getBeanMapAdaptor();
+      for (String attributeName : getFilteredAttributeNames())
       {
-         String id = name.substring(getKeyPrefix().length() + 1);
-         Contextual<?> bean = CurrentManager.rootManager().getBeans().get(Integer.parseInt(id));
-         beans.add(bean);
+         int beanIndex = adaptor.getBeanIndexFromKey(attributeName);
+         Contextual<?> contextual = CurrentManager.rootManager().getBeans().get(beanIndex);
+         contextuals.add(contextual);
       }
-      return beans;
+      return contextuals;
    }
 
    /**
@@ -108,11 +108,10 @@
    private List<String> getFilteredAttributeNames()
    {
       List<String> attributeNames = new ArrayList<String>();
-      Enumeration<String> e = getAttributeNames();
-      while (e.hasMoreElements())
+      BeanMapAdaptor adaptor = getBeanMapAdaptor();
+      for (String attributeName : new EnumerationIterable<String>(getAttributeNames()))
       {
-         String attributeName = e.nextElement();
-         if (attributeName.startsWith(getKeyPrefix()))
+         if (adaptor.acceptKey(attributeName))
          {
             attributeNames.add(attributeName);
          }
@@ -129,7 +128,7 @@
     */
    public <T> void put(Contextual<? extends T> bean, T instance)
    {
-      String key = getBeanKey(bean);
+      String key = getBeanMapAdaptor().getContextualKey(bean);
       setAttribute(key, instance);
       log.trace("Added bean " + bean + " under key " + key);
    }
@@ -166,27 +165,16 @@
    protected abstract void setAttribute(String key, Object instance);
 
    /**
-    * Gets a key prefix that should be prefixed to names
+    * Gets an adaptor for handling keys in a bean map
     * 
-    * @return The prefix
+    * @return The filter
     */
-   protected abstract String getKeyPrefix();
+   protected abstract BeanMapAdaptor getBeanMapAdaptor();
 
-   /**
-    * Returns a map key to a bean. Uses a known prefix and appends the index of
-    * the Bean in the Manager bean list.
-    * 
-    * @param bean The bean to generate a key for.
-    * @return A unique key;
-    */
-   protected String getBeanKey(Contextual<?> bean)
-   {
-      return getKeyPrefix() + "#" + CurrentManager.rootManager().getBeans().indexOf(bean);
-   }
 
    @Override
    public String toString()
    {
-      return "holding " + Names.count(keySet()) + " instances under the key prefix " + getKeyPrefix();
+      return "holding " + Names.count(getContents()) + " instances";
    }
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/BeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/BeanMap.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/BeanMap.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -53,11 +53,11 @@
    public abstract void clear();
 
    /**
-    * Returns an Iterable over the current keys in the storage
+    * Returns an Iterable over the current contents in the storage
     * 
     * @return An Iterable over the keys in the storage
     */
-   public abstract Iterable<Contextual<? extends Object>> keySet();
+   public abstract Iterable<Contextual<? extends Object>> getContents();
 
    /**
     * Adds a bean instance to the storage

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/BeanMapAdaptor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/BeanMapAdaptor.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/BeanMapAdaptor.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -0,0 +1,52 @@
+/*
+ * 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.context.beanmap;
+
+import javax.context.Contextual;
+
+/**
+ * Interface against a BeanMap to handle different naming schemes
+ * 
+ * @author Nicklas Karlsson
+ *
+ */
+public interface BeanMapAdaptor
+{
+   /**
+    * Checks if a key is handled by the bean map
+    * 
+    * @param key The key to match
+    * @return True if match, false otherwise
+    */
+   public abstract boolean acceptKey(String key);
+   
+   /**
+    * Gets a bean map key for a contextual
+    * 
+    * @param contextual The contextual to make the key for
+    * @return A map key
+    */
+   public abstract String getContextualKey(Contextual<?> contextual);
+   
+   /**
+    * Gets a bean index key from a key
+    * 
+    * @param key The key to parse
+    * @return The bean index
+    */
+   public abstract int getBeanIndexFromKey(String key);
+}

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/SimpleBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/SimpleBeanMap.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/SimpleBeanMap.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -108,9 +108,9 @@
     * 
     * @return The beans present
     * 
-    * @see org.jboss.webbeans.context.beanmap.BeanMap#keySet()
+    * @see org.jboss.webbeans.context.beanmap.BeanMap#getContents()
     */
-   public Set<Contextual<? extends Object>> keySet()
+   public Set<Contextual<? extends Object>> getContents()
    {
       return delegate.keySet();
    }

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/SimpleBeanMapAdaptor.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/SimpleBeanMapAdaptor.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/context/beanmap/SimpleBeanMapAdaptor.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -0,0 +1,52 @@
+/*
+ * 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.context.beanmap;
+
+import javax.context.Contextual;
+
+import org.jboss.webbeans.CurrentManager;
+
+/**
+ * Simple prefix-based implementation of a bean map adaptor
+ * 
+ * @author Nicklas Karlsson
+ */
+public class SimpleBeanMapAdaptor implements BeanMapAdaptor
+{
+   public String prefix;
+
+   public SimpleBeanMapAdaptor(String prefix)
+   {
+      this.prefix = prefix;
+   }
+
+   public boolean acceptKey(String key)
+   {
+      return key.startsWith(prefix);
+   }
+
+   public int getBeanIndexFromKey(String key)
+   {
+      return Integer.parseInt(key.substring(prefix.length() + 1));
+   }
+
+   public String getContextualKey(Contextual<?> contextual)
+   {
+      return prefix + "#" + CurrentManager.rootManager().getBeans().indexOf(contextual);
+   }
+
+}

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ConversationEntry.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -26,6 +26,7 @@
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.servlet.ConversationBeanMap;
+import org.jboss.webbeans.servlet.ServletLifecycle;
 
 /**
  * Represents a long-running conversation entry
@@ -100,9 +101,7 @@
       {
          cancelTermination();
       }
-      ConversationContext terminationContext = new ConversationContext();
-      terminationContext.setBeanMap(new ConversationBeanMap(session, cid));
-      terminationContext.destroy();
+      ServletLifecycle.instance().destroyConversation(session, cid);
       log.trace("Conversation " + cid + " destroyed");
    }
 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/conversation/ServletConversationManager.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -28,13 +28,13 @@
 
 import org.jboss.webbeans.CurrentManager;
 import org.jboss.webbeans.WebBean;
-import org.jboss.webbeans.context.ConversationContext;
 import org.jboss.webbeans.conversation.bindings.ConversationConcurrentAccessTimeout;
 import org.jboss.webbeans.conversation.bindings.ConversationIdName;
 import org.jboss.webbeans.conversation.bindings.ConversationInactivityTimeout;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.servlet.HttpSessionManager;
+import org.jboss.webbeans.servlet.ServletLifecycle;
 
 /**
  * The default conversation manager
@@ -195,7 +195,8 @@
             longRunningConversations.get(cid).cancelTermination();
             longRunningConversations.get(cid).unlock();
          }
-         ConversationContext.INSTANCE.destroy();
+         HttpSession session = CurrentManager.rootManager().getInstanceByType(HttpSessionManager.class).getSession();
+         ServletLifecycle.instance().destroyConversation(session, cid);
       }
       // If Conversation.begin(String) is called, it might be that the
       // conversation will be switched. We need to unlock this original 

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/JSFHelper.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -16,10 +16,15 @@
  */
 package org.jboss.webbeans.jsf;
 
+import java.io.IOException;
+
 import javax.faces.component.html.HtmlInputHidden;
 import javax.faces.context.FacesContext;
+import javax.inject.AnnotationLiteral;
 import javax.servlet.http.HttpSession;
 
+import org.jboss.webbeans.CurrentManager;
+import org.jboss.webbeans.conversation.bindings.ConversationIdName;
 import org.jboss.webbeans.log.LogProvider;
 import org.jboss.webbeans.log.Logging;
 
@@ -27,14 +32,13 @@
  * Helper class for JSF related operations
  * 
  * @author Nicklas Karlsson
- *
+ * 
  */
 public class JSFHelper
 {
    private static LogProvider log = Logging.getLogProvider(JSFHelper.class);
 
    private static final String CONVERSATION_PROPAGATION_COMPONENT_ID = "webbeans_conversation_propagation";
-   private static final String CONVERSATION_ID_NAME = "cid";
 
    /**
     * Gets a FacesContext instance
@@ -70,7 +74,8 @@
    }
 
    /**
-    * Creates and/or updates the conversation propagation component in the UI view root
+    * Creates and/or updates the conversation propagation component in the UI
+    * view root
     * 
     * @param cid The conversation id to propagate
     */
@@ -105,15 +110,17 @@
     */
    public static String getConversationIdFromRequest()
    {
-      String cid = context().getExternalContext().getRequestParameterMap().get(CONVERSATION_ID_NAME);
+      String cidName = CurrentManager.rootManager().getInstanceByType(String.class, new AnnotationLiteral<ConversationIdName>(){});
+      String cid = context().getExternalContext().getRequestParameterMap().get(cidName);
       log.trace("Got cid " + cid + " from request");
       return cid;
    }
 
    /**
     * Gets the propagated conversation id from the propagation component
-    *  
+    * 
     * @return The conversation id (or null if not found)
+    * @throws IOException
     */
    public static String getConversationIdFromPropagationComponent()
    {
@@ -130,7 +137,7 @@
    /**
     * Gets the propagated conversation id
     * 
-    * @return The conversatio nid (or null if not found)
+    * @return The conversation id (or null if not found)
     */
    public static String getConversationId()
    {

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/jsf/WebBeansPhaseListener.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -29,6 +29,7 @@
 import org.jboss.webbeans.log.Logging;
 import org.jboss.webbeans.servlet.ConversationBeanMap;
 import org.jboss.webbeans.servlet.HttpSessionManager;
+import org.jboss.webbeans.servlet.ServletLifecycle;
 
 /**
  * A phase listener for propagating conversation id over postbacks through a
@@ -112,7 +113,7 @@
       CurrentManager.rootManager().getInstanceByType(HttpSessionManager.class).setSession(session);
       CurrentManager.rootManager().getInstanceByType(ConversationManager.class).beginOrRestoreConversation(JSFHelper.getConversationId());
       String cid = CurrentManager.rootManager().getInstanceByType(Conversation.class).getId();
-      ConversationContext.INSTANCE.setBeanMap(new ConversationBeanMap(session, cid));
+      ServletLifecycle.instance().restoreConversation(session, cid);
    }
 
    /**

Added: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockConversationManager.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockConversationManager.java	                        (rev 0)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/mock/MockConversationManager.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -0,0 +1,31 @@
+/*
+ * 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.mock;
+
+import org.jboss.webbeans.conversation.ServletConversationManager;
+
+/**
+ * Mock of a conversation manager without servlet dependencies
+ * 
+ * @author Nicklas Karlsson
+ *
+ */
+// TODO dummy
+public class MockConversationManager extends ServletConversationManager
+{
+
+}

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/AbstractLifecycle.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/AbstractLifecycle.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/AbstractLifecycle.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -17,23 +17,23 @@
  * and destroying all the built in contexts
  * 
  * @author Pete Muir
- *
+ * 
  */
 public abstract class AbstractLifecycle
 {
-   
-   private static AbstractLifecycle instance; 
-   
+
+   private static AbstractLifecycle instance;
+
    public static AbstractLifecycle instance()
    {
       return instance;
    }
-   
+
    protected static void setInstance(AbstractLifecycle instance)
    {
       AbstractLifecycle.instance = instance;
    }
-   
+
    private static LogProvider log = Logging.getLogProvider(AbstractLifecycle.class);
 
    protected void initialize()
@@ -49,21 +49,21 @@
       manager.addContext(ApplicationContext.create());
       manager.addContext(ConversationContext.create());
    }
-   
+
    protected void beginApplication(String id, BeanMap applicationBeanMap)
    {
       log.trace("Starting application " + id);
       ApplicationContext.INSTANCE.setBeanMap(applicationBeanMap);
       ApplicationContext.INSTANCE.setActive(true);
-      
+
    }
-   
+
    protected void beginDeploy(BeanMap requestBeanMap)
    {
       RequestContext.INSTANCE.setBeanMap(requestBeanMap);
       RequestContext.INSTANCE.setActive(true);
    }
-   
+
    protected void endDeploy(BeanMap requestBeanMap)
    {
       RequestContext.INSTANCE.setBeanMap(null);
@@ -77,7 +77,7 @@
       ApplicationContext.INSTANCE.setActive(false);
       ApplicationContext.INSTANCE.setBeanMap(null);
    }
-   
+
    protected void beginSession(String id, BeanMap sessionBeanMap)
    {
       log.trace("Starting session " + id);
@@ -102,7 +102,7 @@
       RequestContext.INSTANCE.setActive(true);
       DependentContext.INSTANCE.setActive(true);
    }
-   
+
    public void endRequest(String id, BeanMap requestBeanMap)
    {
       log.trace("Ending request " + id);
@@ -111,5 +111,20 @@
       RequestContext.INSTANCE.destroy();
       RequestContext.INSTANCE.setActive(false);
    }
-     
+
+   protected void restoreConversation(String id, BeanMap conversationBeanMap)
+   {
+      log.trace("Starting conversation " + id);
+      ConversationContext.INSTANCE.setBeanMap(conversationBeanMap);
+      ConversationContext.INSTANCE.setActive(true);
+   }
+
+   protected void destroyConversation(String id, ConversationBeanMap conversationBeanMap)
+   {
+      log.trace("Ending conversation " + id);
+      ConversationContext destructionContext = new ConversationContext();
+      destructionContext.setBeanMap(conversationBeanMap);
+      destructionContext.destroy();
+   }
+
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ApplicationBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ApplicationBeanMap.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ApplicationBeanMap.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -23,6 +23,8 @@
 
 import org.jboss.webbeans.context.ApplicationContext;
 import org.jboss.webbeans.context.beanmap.AbstractBeanMap;
+import org.jboss.webbeans.context.beanmap.BeanMapAdaptor;
+import org.jboss.webbeans.context.beanmap.SimpleBeanMapAdaptor;
 
 /**
  * A BeanMap that uses a servlet context as backing map
@@ -37,7 +39,7 @@
    private ServletContext context;
 
    /**
-    * Constructor 
+    * Constructor
     * 
     * @param context The servlet context instance
     */
@@ -48,15 +50,6 @@
    }
 
    /**
-    * @see org.jboss.webbeans.context.beanmap.AbstractBeanMap#getKeyPrefix()
-    */
-   @Override
-   protected String getKeyPrefix()
-   {
-      return ApplicationContext.class.getName();
-   }
-
-   /**
     * @see org.jboss.webbeans.context.beanmap.AbstractBeanMap#getAttribute()
     */
    @Override
@@ -93,4 +86,10 @@
       context.setAttribute(key, instance);
    }
 
+   @Override
+   protected BeanMapAdaptor getBeanMapAdaptor()
+   {
+      return new SimpleBeanMapAdaptor(ApplicationContext.class.getName());
+   }
+
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ConversationBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ConversationBeanMap.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ConversationBeanMap.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -20,6 +20,8 @@
 import javax.servlet.http.HttpSession;
 
 import org.jboss.webbeans.context.ConversationContext;
+import org.jboss.webbeans.context.beanmap.BeanMapAdaptor;
+import org.jboss.webbeans.context.beanmap.SimpleBeanMapAdaptor;
 
 /**
  * A HTTP session backed bean map for the conversational scope
@@ -37,9 +39,9 @@
    }
 
    @Override
-   protected String getKeyPrefix()
+   protected BeanMapAdaptor getBeanMapAdaptor()
    {
-      return ConversationContext.class.getName() + "[" + cid + "]";
+      return new SimpleBeanMapAdaptor(ConversationContext.class.getName() + "[" + cid + "]");
    }
 
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/HttpSessionBeanMap.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/HttpSessionBeanMap.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/HttpSessionBeanMap.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -22,6 +22,8 @@
 
 import org.jboss.webbeans.context.SessionContext;
 import org.jboss.webbeans.context.beanmap.AbstractBeanMap;
+import org.jboss.webbeans.context.beanmap.BeanMapAdaptor;
+import org.jboss.webbeans.context.beanmap.SimpleBeanMapAdaptor;
 
 /**
  * A BeanMap that uses a HTTP session as backing map
@@ -47,15 +49,6 @@
    }
 
    /**
-    * @see org.jboss.webbeans.context.beanmap.AbstractBeanMap#getKeyPrefix()
-    */
-   @Override
-   protected String getKeyPrefix()
-   {
-      return SessionContext.class.getName();
-   }
-
-   /**
     * @see org.jboss.webbeans.context.beanmap.AbstractBeanMap#getAttribute()
     */
    @Override
@@ -92,4 +85,10 @@
       session.setAttribute(key, instance);
    }
 
+   @Override
+   protected BeanMapAdaptor getBeanMapAdaptor()
+   {
+      return new SimpleBeanMapAdaptor(SessionContext.class.getName());
+   }
+
 }

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	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/ServletLifecycle.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -39,21 +39,21 @@
 @Deprecated
 public class ServletLifecycle extends AbstractLifecycle
 {
-   
+
    public static final String REQUEST_ATTRIBUTE_NAME = ServletLifecycle.class.getName() + ".requestBeanMap";
-   
+
    static
    {
       AbstractLifecycle.setInstance(new ServletLifecycle());
    }
-   
+
    public static ServletLifecycle instance()
    {
       return (ServletLifecycle) AbstractLifecycle.instance();
    }
-   
+
    private static LogProvider log = Logging.getLogProvider(ServletLifecycle.class);
-   
+
    @Override
    public void initialize()
    {
@@ -105,9 +105,9 @@
    {
       super.endSession(session.getId(), restoreSessionContext(session));
    }
-   
+
    /**
-    * Restore the session from the underlying session object. Also allow the 
+    * Restore the session from the underlying session object. Also allow the
     * session to be injected by the Session manager
     * 
     * @param session
@@ -120,7 +120,7 @@
       CurrentManager.rootManager().getInstanceByType(HttpSessionManager.class).setSession(session);
       return sessionBeanMap;
    }
-   
+
    /**
     * Begins a HTTP request
     * 
@@ -149,4 +149,26 @@
       SessionContext.INSTANCE.setBeanMap(null);
    }
 
+   /**
+    * Restores a conversation
+    * 
+    * @param session The HTTP session
+    * @param cid The conversation to resume
+    */
+   public void restoreConversation(HttpSession session, String cid)
+   {
+      super.restoreConversation(session.getId() + "[" + cid + "]", new ConversationBeanMap(session, cid));
+   }
+
+   /**
+    * Destroys a conversation
+    * 
+    * @param session The HTTP session
+    * @param cid The conversation to destroy
+    */
+   public void destroyConversation(HttpSession session, String cid)
+   {
+      super.destroyConversation(session.getId() + "[" + cid + "]", new ConversationBeanMap(session, cid));
+   }
+
 }

Modified: ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansServletFilter.java
===================================================================
--- ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansServletFilter.java	2009-02-23 01:08:12 UTC (rev 1656)
+++ ri/trunk/webbeans-ri/src/main/java/org/jboss/webbeans/servlet/WebBeansServletFilter.java	2009-02-23 09:37:38 UTC (rev 1657)
@@ -80,6 +80,7 @@
 
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException
    {
+      System.out.println("!!!");
       chain.doFilter(request, wrapResponse((HttpServletResponse) response));
    }
 




More information about the weld-commits mailing list