[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Gavin King gavin.king at jboss.com
Tue Oct 10 17:00:53 EDT 2006


  User: gavin   
  Date: 06/10/10 17:00:53

  Modified:    src/main/org/jboss/seam/core        Conversation.java
                        ConversationEntry.java ConversationList.java
                        ConversationStack.java Manager.java Switcher.java
  Added:       src/main/org/jboss/seam/core        ConversationEntries.java
  Log:
  long overdue refactoring
  
  Revision  Changes    Path
  1.22      +6 -3      jboss-seam/src/main/org/jboss/seam/core/Conversation.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Conversation.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Conversation.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -b -r1.21 -r1.22
  --- Conversation.java	8 Oct 2006 21:32:27 -0000	1.21
  +++ Conversation.java	10 Oct 2006 21:00:53 -0000	1.22
  @@ -110,9 +110,12 @@
            {
               throw new IllegalStateException("only long-running conversation outcomes are switchable");
            }
  -         if (description!=null) manager.setCurrentConversationDescription(description);
  -         if (viewId!=null) manager.setCurrentConversationViewId(viewId);
  -         if (timeout!=null) manager.setCurrentConversationTimeout(timeout);
  +         if (description!=null)
  +            manager.getCurrentConversationEntry().setDescription(description);
  +         if (viewId!=null)
  +            manager.getCurrentConversationEntry().setViewId(viewId);
  +         if (timeout!=null)
  +            manager.getCurrentConversationEntry().setTimeout(timeout);
            description = null;
            viewId = null;
         }
  
  
  
  1.18      +14 -15    jboss-seam/src/main/org/jboss/seam/core/ConversationEntry.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConversationEntry.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ConversationEntry.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -b -r1.17 -r1.18
  --- ConversationEntry.java	7 Sep 2006 02:04:18 -0000	1.17
  +++ ConversationEntry.java	10 Oct 2006 21:00:53 -0000	1.18
  @@ -4,8 +4,8 @@
   package org.jboss.seam.core;
   
   import java.io.Serializable;
  +import java.util.Collections;
   import java.util.Date;
  -import java.util.LinkedList;
   import java.util.List;
   
   /**
  @@ -23,25 +23,18 @@
      private Date startDatetime;
      private Date lastDatetime;
      private String viewId;
  -   private LinkedList<String> conversationIdStack;
  +   private List<String> conversationIdStack;
      private String initiatorComponentName;
      private Integer timeout;
      private boolean removeAfterRedirect;
  +   private ConversationEntries parent;
   
  -   public ConversationEntry(String id, LinkedList<String> stack)
  +   public ConversationEntry(String id, List<String> stack, ConversationEntries parent)
      {
         this.id = id;
  -      conversationIdStack = stack;
  -      startDatetime = new Date();
  -      touch();
  -   }
  -
  -   public ConversationEntry(String id)
  -   {
  -      this.id = id;
  -      conversationIdStack = new LinkedList<String>();
  -      conversationIdStack.add(id);
  -      startDatetime = new Date();
  +      this.conversationIdStack = Collections.unmodifiableList(stack);
  +      this.startDatetime = new Date();
  +      this.parent = parent;
         touch();
      }
   
  @@ -55,6 +48,7 @@
      }
   
      void setDescription(String description) {
  +      parent.setDirty(this.description, description);
         this.description = description;
      }
   
  @@ -63,6 +57,7 @@
      }
   
      void touch() {
  +      parent.setDirty();
         this.lastRequestTime = System.currentTimeMillis();
         lastDatetime = new Date();
      }
  @@ -95,6 +90,7 @@
      }
   
      void setViewId(String viewId) {
  +      parent.setDirty(this.viewId, viewId);
         this.viewId = viewId;
      }
   
  @@ -112,7 +108,7 @@
         return lastDatetime;
      }
   
  -   public LinkedList<String> getConversationIdStack() {
  +   public List<String> getConversationIdStack() {
         return conversationIdStack;
      }
   
  @@ -121,6 +117,7 @@
      }
   
      void setInitiatorComponentName(String ownerComponentName) {
  +      parent.setDirty(this.initiatorComponentName, ownerComponentName);
         this.initiatorComponentName = ownerComponentName;
      }
   
  @@ -155,6 +152,7 @@
      }
   
      void setTimeout(int conversationTimeout) {
  +      parent.setDirty(this.timeout, timeout);
         this.timeout = conversationTimeout;
      }
   
  @@ -163,6 +161,7 @@
      }
   
      public void setRemoveAfterRedirect(boolean removeAfterRedirect) {
  +      parent.setDirty();
         this.removeAfterRedirect = removeAfterRedirect;
      }
      
  
  
  
  1.8       +4 -5      jboss-seam/src/main/org/jboss/seam/core/ConversationList.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConversationList.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ConversationList.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -b -r1.7 -r1.8
  --- ConversationList.java	19 Jan 2006 13:10:34 -0000	1.7
  +++ ConversationList.java	10 Oct 2006 21:00:53 -0000	1.8
  @@ -5,7 +5,6 @@
   import java.io.Serializable;
   import java.util.ArrayList;
   import java.util.List;
  -import java.util.Map;
   import java.util.Set;
   import java.util.TreeSet;
   
  @@ -19,7 +18,7 @@
   
   /**
    * @author Gavin King
  - * @version $Revision: 1.7 $
  + * @version $Revision: 1.8 $
    */
   @Scope(ScopeType.PAGE)
   @Name("conversationList")
  @@ -31,10 +30,10 @@
      @Create
      public void createConversationEntryList()
      {
  -      Map<String, ConversationEntry> map = Manager.instance().getConversationIdEntryMap();
  +      ConversationEntries conversationEntries = ConversationEntries.instance();
         Set<ConversationEntry> orderedEntries = new TreeSet<ConversationEntry>();
  -      orderedEntries.addAll( map.values() );
  -      conversationEntryList = new ArrayList<ConversationEntry>( map.size() );
  +      orderedEntries.addAll( conversationEntries.getConversationEntries() );
  +      conversationEntryList = new ArrayList<ConversationEntry>( conversationEntries.size() );
         for ( ConversationEntry entry: orderedEntries )
         {
            if ( entry.isDisplayable() && !Seam.isSessionInvalid() )
  
  
  
  1.5       +6 -9      jboss-seam/src/main/org/jboss/seam/core/ConversationStack.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: ConversationStack.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/ConversationStack.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -b -r1.4 -r1.5
  --- ConversationStack.java	19 Jan 2006 13:10:34 -0000	1.4
  +++ ConversationStack.java	10 Oct 2006 21:00:53 -0000	1.5
  @@ -4,10 +4,8 @@
   
   import java.io.Serializable;
   import java.util.ArrayList;
  -import java.util.LinkedList;
   import java.util.List;
   import java.util.ListIterator;
  -import java.util.Map;
   
   import org.jboss.seam.ScopeType;
   import org.jboss.seam.Seam;
  @@ -21,7 +19,7 @@
    * Support for "breadcrumbs".
    * 
    * @author Gavin King
  - * @version $Revision: 1.4 $
  + * @version $Revision: 1.5 $
    */
   @Scope(ScopeType.PAGE)
   @Name("conversationStack")
  @@ -33,17 +31,16 @@
      @Create
      public void createConversationEntryStack()
      {
  -      Manager manager = Manager.instance();
  -      Map<String, ConversationEntry> map = manager.getConversationIdEntryMap();
  -      ConversationEntry currentConversationEntry = manager.getCurrentConversationEntry();
  +      ConversationEntries conversationEntries = ConversationEntries.instance();
  +      ConversationEntry currentConversationEntry = Manager.instance().getCurrentConversationEntry();
         if (currentConversationEntry!=null)
         {
  -         LinkedList<String> idStack = currentConversationEntry.getConversationIdStack();
  -         conversationEntryStack = new ArrayList<ConversationEntry>( map.size() );
  +         List<String> idStack = currentConversationEntry.getConversationIdStack();
  +         conversationEntryStack = new ArrayList<ConversationEntry>( conversationEntries.size() );
            ListIterator<String> ids = idStack.listIterator( idStack.size() );
            while ( ids.hasPrevious() )
            {
  -            ConversationEntry entry = map.get( ids.previous() );
  +            ConversationEntry entry = conversationEntries.getConversationEntry( ids.previous() );
               if ( entry.isDisplayable() && !Seam.isSessionInvalid() ) 
               {
                  conversationEntryStack.add(entry);
  
  
  
  1.90      +33 -128   jboss-seam/src/main/org/jboss/seam/core/Manager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Manager.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Manager.java,v
  retrieving revision 1.89
  retrieving revision 1.90
  diff -u -b -r1.89 -r1.90
  --- Manager.java	10 Oct 2006 19:37:37 -0000	1.89
  +++ Manager.java	10 Oct 2006 21:00:53 -0000	1.90
  @@ -9,12 +9,10 @@
   import static org.jboss.seam.InterceptionType.NEVER;
   
   import java.io.IOException;
  -import java.util.Collections;
  +import java.util.ArrayList;
   import java.util.HashMap;
  -import java.util.Iterator;
  -import java.util.LinkedList;
  +import java.util.List;
   import java.util.Map;
  -import java.util.Set;
   import java.util.StringTokenizer;
   
   import javax.faces.application.FacesMessage;
  @@ -29,7 +27,6 @@
   import org.jboss.seam.Component;
   import org.jboss.seam.ScopeType;
   import org.jboss.seam.Seam;
  -import org.jboss.seam.annotations.Destroy;
   import org.jboss.seam.annotations.Intercept;
   import org.jboss.seam.annotations.Name;
   import org.jboss.seam.annotations.Scope;
  @@ -44,7 +41,7 @@
    *
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.89 $
  + * @version $Revision: 1.90 $
    */
   @Scope(ScopeType.EVENT)
   @Name("org.jboss.seam.core.manager")
  @@ -54,7 +51,6 @@
      private static final Log log = LogFactory.getLog(Manager.class);
   
      private static final String NAME = Seam.getComponentName(Manager.class);
  -   public static final String CONVERSATION_ID_MAP = NAME + ".conversationIdEntryMap";
      public static final String CONVERSATION_ID = NAME + ".conversationId";
      public static final String CONVERSATION_IS_LONG_RUNNING = NAME + ".conversationIsLongRunning";
      public static final String PAGEFLOW_COUNTER = NAME + ".pageflowCounter";
  @@ -66,11 +62,10 @@
      //stored in the session context at the end
      //of each request
      private Map<String, ConversationEntry> conversationIdEntryMap;
  -   private boolean dirty = false;
   
      //The id of the current conversation
      private String currentConversationId;
  -   private LinkedList<String> currentConversationIdStack;
  +   private List<String> currentConversationIdStack;
   
      //Is the current conversation "long-running"?
      private boolean isLongRunningConversation;
  @@ -104,7 +99,6 @@
      
      public void updateCurrentConversationId(String id)
      {
  -      
         String[] names = Contexts.getConversationContext().getNames();
         Object[] values = new Object[names.length];
         for (int i=0; i<names.length; i++)
  @@ -114,75 +108,28 @@
         }
         Contexts.getConversationContext().flush();
         
  -      Map<String, ConversationEntry> map = getConversationIdEntryMap();
  -      ConversationEntry ce = map.remove(currentConversationId);
  -      if (ce!=null){
  -         ce.setId(id);
  -         map.put(id, ce);
  -         dirty();
  -      }
  +      ConversationEntries.instance().updateConversationId(currentConversationId, id);
         currentConversationIdStack.set(0, id);
         currentConversationId = id;
  +      //TODO: update nested conversations!!!!!
         
         for (int i=0; i<names.length; i++)
         {
            Contexts.getConversationContext().set(names[i], values[i]);
         }
  -      
  -   }
  -
  -   public Set<String> getSessionConversationIds()
  -   {
  -      return getConversationIdEntryMap().keySet();
  -   }
  -
  -   public Map<String, ConversationEntry> getConversationIdEntryMap()
  -   {
  -      if (conversationIdEntryMap==null)
  -      {
  -         conversationIdEntryMap = (Map<String, ConversationEntry>) Contexts.getSessionContext().get(CONVERSATION_ID_MAP);
  -         if (conversationIdEntryMap==null)
  -         {
  -            conversationIdEntryMap = Collections.synchronizedMap( new HashMap<String, ConversationEntry>() );
  -         }
  -      }
  -      return conversationIdEntryMap;
  -   }
  -
  -   /**
  -    * Make sure the session notices that we changed something
  -    */
  -   private void dirty()
  -   {
  -      dirty = true;
  -   }
  -
  -   private ConversationEntry removeConversationEntry(String conversationId)
  -   {
  -      Map<String, ConversationEntry> entryMap = getConversationIdEntryMap();
  -      if ( entryMap.containsKey(conversationId) ) //might be a request-only conversationId, not yet existing in session
  -      {
  -         dirty();
  -         return entryMap.remove(conversationId);
  -      }
  -      else
  -      {
  -         return null; //does this ever occur??
  -      }
      }
   
      private void touchConversationStack()
      {
  -      LinkedList<String> stack = getCurrentConversationIdStack();
  +      List<String> stack = getCurrentConversationIdStack();
         if ( stack!=null )
         {
            for ( String conversationId: stack )
            {
  -            ConversationEntry conversationEntry = getConversationEntry(conversationId);
  +            ConversationEntry conversationEntry = ConversationEntries.instance().getConversationEntry(conversationId);
               if (conversationEntry!=null)
               {
                  conversationEntry.touch();
  -               dirty();
               }
            }
         }
  @@ -195,10 +142,6 @@
   
      }
   
  -   private ConversationEntry getConversationEntry(String conversationId) {
  -      return getConversationIdEntryMap().get(conversationId);
  -   }
  -   
      /**
       * Get the name of the component that started the current
       * conversation.
  @@ -216,38 +159,21 @@
         }
      }
   
  -   public LinkedList<String> getCurrentConversationIdStack()
  +   public List<String> getCurrentConversationIdStack()
      {
         return currentConversationIdStack;
      }
   
  -   private void setCurrentConversationIdStack(LinkedList<String> stack)
  +   private void setCurrentConversationIdStack(List<String> stack)
      {
         currentConversationIdStack = stack;
      }
   
  -   private void setCurrentConversationIdStack(String id)
  +   private List<String> createCurrentConversationIdStack(String id)
      {
  -      currentConversationIdStack = new LinkedList<String>();
  +      currentConversationIdStack = new ArrayList<String>();
         currentConversationIdStack.add(id);
  -   }
  -
  -   public void setCurrentConversationDescription(String description)
  -   {
  -      getCurrentConversationEntry().setDescription(description);
  -      dirty();
  -   }
  -
  -   public void setCurrentConversationViewId(String viewId)
  -   {
  -      getCurrentConversationEntry().setViewId(viewId);
  -      dirty();
  -   }
  -
  -   public void setCurrentConversationTimeout(int timeout)
  -   {
  -      getCurrentConversationEntry().setTimeout(timeout);
  -      dirty();
  +      return currentConversationIdStack;
      }
   
      public String getCurrentConversationDescription()
  @@ -268,7 +194,7 @@
      
      public String getParentConversationViewId()
      {
  -      ConversationEntry conversationEntry = getConversationEntry( getParentConversationId() );
  +      ConversationEntry conversationEntry = ConversationEntries.instance().getConversationEntry(getParentConversationId());
         return conversationEntry==null ? null : conversationEntry.getViewId();
      }
      
  @@ -284,18 +210,6 @@
               null : currentConversationIdStack.get( currentConversationIdStack.size()-1 );
      }
   
  -   @Destroy
  -   public void flushConversationIdMapToSession()
  -   {
  -      if ( Contexts.isSessionContextActive() ) // this method might be called from the session listener
  -      {
  -         if (dirty)
  -         {
  -            Contexts.getSessionContext().set(CONVERSATION_ID_MAP, conversationIdEntryMap);
  -         }
  -      }
  -   }
  -
      public boolean isLongRunningConversation()
      {
         return isLongRunningConversation;
  @@ -338,18 +252,15 @@
      public void conversationTimeout(ExternalContext externalContext)
      {
         long currentTime = System.currentTimeMillis();
  -      Iterator<Map.Entry<String, ConversationEntry>> entries = getConversationIdEntryMap().entrySet().iterator();
  -      while ( entries.hasNext() )
  +      List<ConversationEntry> entries = new ArrayList<ConversationEntry>( ConversationEntries.instance().getConversationEntries() );
  +      for (ConversationEntry conversationEntry: entries)
         {
  -         Map.Entry<String, ConversationEntry> entry = entries.next();
  -         ConversationEntry conversationEntry = entry.getValue();
            long delta = currentTime - conversationEntry.getLastRequestTime();
            if ( delta > conversationEntry.getTimeout() )
            {
  -            String conversationId = entry.getKey();
  -            log.debug("conversation timeout for conversation: " + conversationId);
  +            log.debug("conversation timeout for conversation: " + conversationEntry.getId());
               ContextAdaptor session = ContextAdaptor.getSession(externalContext, true);
  -            destroyConversation(conversationId, session, entries);
  +            destroyConversation( conversationEntry.getId(), session );
            }
         }
      }
  @@ -357,14 +268,13 @@
      /**
       * Clean up all state associated with a conversation
       */
  -   private void destroyConversation(String conversationId, ContextAdaptor session, Iterator iter)
  +   private void destroyConversation(String conversationId, ContextAdaptor session)
      {
         ServerConversationContext conversationContext = new ServerConversationContext(session, conversationId);
         Contexts.destroy( conversationContext );
         conversationContext.clear();
         conversationContext.flush();
  -      iter.remove();
  -      dirty();
  +      ConversationEntries.instance().removeConversationEntry(conversationId);
      }
      
      /**
  @@ -425,7 +335,7 @@
      {
         log.debug("Discarding conversation state: " + currentConversationId);
   
  -      LinkedList<String> stack = getCurrentConversationIdStack();
  +      List<String> stack = getCurrentConversationIdStack();
         if ( stack.size()>1 )
         {
            String outerConversationId = stack.get(1);
  @@ -464,20 +374,19 @@
      }
   
      private void removeCurrentConversationAndDestroyNestedContexts(ContextAdaptor session) {
  -      removeConversationEntry(currentConversationId);
  +      ConversationEntries.instance().removeConversationEntry(currentConversationId);
         destroyNestedContexts(session, currentConversationId);
      }
   
      private void destroyNestedContexts(ContextAdaptor session, String conversationId) {
  -      Iterator<ConversationEntry> entries = getConversationIdEntryMap().values().iterator();
  -      while ( entries.hasNext() )
  +      List<ConversationEntry> entries = new ArrayList<ConversationEntry>( ConversationEntries.instance().getConversationEntries() );
  +      for  ( ConversationEntry ce: entries )
         {
  -         ConversationEntry ce = entries.next();
            if ( ce.getConversationIdStack().contains(conversationId) )
            {
               String entryConversationId = ce.getId();
               log.debug("destroying nested conversation: " + entryConversationId);
  -            destroyConversation(entryConversationId, session, entries);
  +            destroyConversation(entryConversationId, session);
            }
         }
      }
  @@ -605,7 +514,7 @@
       */
      public boolean restoreConversation(String storedConversationId, boolean isLongRunningConversation) {
         boolean isStoredConversation = storedConversationId!=null &&
  -            getSessionConversationIds().contains(storedConversationId);
  +            ConversationEntries.instance().getConversationIds().contains(storedConversationId);
         if ( isStoredConversation )
         {
   
  @@ -684,16 +593,13 @@
      {
         String id = Id.nextId();
         setCurrentConversationId(id);
  -      setCurrentConversationIdStack(id);
  +      createCurrentConversationIdStack(id);
         setLongRunningConversation(false);
      }
   
      private ConversationEntry createConversationEntry()
      {
  -      ConversationEntry ce = new ConversationEntry( getCurrentConversationId(), getCurrentConversationIdStack() );
  -      getConversationIdEntryMap().put( getCurrentConversationId() , ce );
  -      dirty();
  -      return ce;
  +      return ConversationEntries.instance().createConversationEntry( getCurrentConversationId(), getCurrentConversationIdStack() );
      }
   
      /**
  @@ -726,17 +632,16 @@
       */
      public void beginNestedConversation(String ownerName)
      {
  -      LinkedList<String> stack = getCurrentConversationIdStack();
  +      List<String> oldStack = getCurrentConversationIdStack();
         String id = Id.nextId();
         setCurrentConversationId(id);
  -      setCurrentConversationIdStack(id);
  -      getCurrentConversationIdStack().addAll(stack);
  +      createCurrentConversationIdStack(id).addAll(oldStack);
         ConversationEntry conversationEntry = createConversationEntry();
         conversationEntry.setInitiatorComponentName(ownerName);
      }
   
      public ConversationEntry getCurrentConversationEntry() {
  -      return getConversationEntry( getCurrentConversationId() );
  +      return ConversationEntries.instance().getConversationEntry(getCurrentConversationId());
      }
      
      /**
  @@ -756,7 +661,7 @@
       */
      public boolean swapConversation(String id)
      {
  -      ConversationEntry ce = getConversationEntry(id);
  +      ConversationEntry ce = ConversationEntries.instance().getConversationEntry(id);
         if (ce!=null)
         {
            setCurrentConversationId(id);
  @@ -789,7 +694,7 @@
      {
         if (!destroyBeforeRedirect)
         {
  -         ConversationEntry ce = getConversationEntry(currentConversationId);
  +         ConversationEntry ce = ConversationEntries.instance().getConversationEntry(currentConversationId);
            if (ce==null)
            {
               ce = createConversationEntry();
  
  
  
  1.10      +4 -4      jboss-seam/src/main/org/jboss/seam/core/Switcher.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Switcher.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Switcher.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -b -r1.9 -r1.10
  --- Switcher.java	19 Jan 2006 13:10:34 -0000	1.9
  +++ Switcher.java	10 Oct 2006 21:00:53 -0000	1.10
  @@ -24,7 +24,7 @@
    * Support for the conversation switcher drop-down menu.
    * 
    * @author Gavin King
  - * @version $Revision: 1.9 $
  + * @version $Revision: 1.10 $
    */
   @Scope(ScopeType.PAGE)
   @Name("switcher")
  @@ -36,10 +36,10 @@
      @Create
      public void createSelectItems()
      {
  -      Map<String, ConversationEntry> map = Manager.instance().getConversationIdEntryMap();
  +      ConversationEntries conversationEntries = ConversationEntries.instance();
         Set<ConversationEntry> orderedEntries = new TreeSet<ConversationEntry>();
  -      orderedEntries.addAll( map.values() );
  -      selectItems = new ArrayList<SelectItem>( map.size() );
  +      orderedEntries.addAll( conversationEntries.getConversationEntries() );
  +      selectItems = new ArrayList<SelectItem>( conversationEntries.size() );
         for ( ConversationEntry entry: orderedEntries )
         {
            if ( entry.isDisplayable() && !Seam.isSessionInvalid() )
  
  
  
  1.1      date: 2006/10/10 21:00:53;  author: gavin;  state: Exp;jboss-seam/src/main/org/jboss/seam/core/ConversationEntries.java
  
  Index: ConversationEntries.java
  ===================================================================
  package org.jboss.seam.core;
  
  import static org.jboss.seam.InterceptionType.NEVER;
  
  import java.io.Serializable;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  
  import org.jboss.seam.Component;
  import org.jboss.seam.ScopeType;
  import org.jboss.seam.annotations.Intercept;
  import org.jboss.seam.annotations.Name;
  import org.jboss.seam.annotations.Scope;
  import org.jboss.seam.contexts.Contexts;
  
  /**
   * Manages a map of conversation id to ConversationEntry 
   * in the session context.
   * 
   * @author Gavin King
   */
  @Name("org.jboss.seam.core.conversationEntries")
  @Scope(ScopeType.SESSION)
  @Intercept(NEVER)
  public class ConversationEntries extends AbstractMutable implements Serializable
  {
     private Map<String, ConversationEntry> conversationIdEntryMap = new HashMap<String, ConversationEntry>();
     
     public synchronized Collection<ConversationEntry> getConversationEntries()
     {
        return Collections.unmodifiableCollection( conversationIdEntryMap.values() );
     }
     
     public synchronized int size()
     {
        return conversationIdEntryMap.size();
     }
     
     public synchronized Set<String> getConversationIds()
     {
        return Collections.unmodifiableSet( conversationIdEntryMap.keySet() );
     }
     
     public synchronized ConversationEntry createConversationEntry(String id, List<String> stack)
     {
        ConversationEntry entry = new ConversationEntry(id, stack, this);
        conversationIdEntryMap.put(id, entry);
        setDirty();
        return entry;
     }
     
     public synchronized ConversationEntry getConversationEntry(String id)
     {
        return conversationIdEntryMap.get(id);
     }
     
     public synchronized ConversationEntry removeConversationEntry(String id)
     {
        ConversationEntry entry = conversationIdEntryMap.remove(id);
        if ( entry!=null ) setDirty();
        return entry;
     }
     
     public synchronized ConversationEntry updateConversationId(String oldId, String newId)
     {
        ConversationEntry entry = conversationIdEntryMap.remove(oldId);
        if (entry==null)
        {
           throw new IllegalStateException("conversation not found");
        }
        entry.setId(newId);
        conversationIdEntryMap.put(newId, entry);
        setDirty();
        return entry;
     }
     
     public static ConversationEntries instance()
     {
        if ( !Contexts.isSessionContextActive() )
        {
           throw new IllegalStateException("No session context active");
        }
        return (ConversationEntries) Component.getInstance(ConversationEntries.class, ScopeType.SESSION, true);
     }
     
  }
  
  
  



More information about the jboss-cvs-commits mailing list