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

Shane Bryzak sbryzak at redhat.com
Thu Mar 8 02:34:15 EST 2007


  User: sbryzak2
  Date: 07/03/08 02:34:15

  Modified:    src/main/org/jboss/seam/core    ConversationEntry.java
                        Manager.java Pages.java
  Log:
  natural conversation ids
  
  Revision  Changes    Path
  1.36      +2 -0      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.35
  retrieving revision 1.36
  diff -u -b -r1.35 -r1.36
  --- ConversationEntry.java	8 Mar 2007 07:25:06 -0000	1.35
  +++ ConversationEntry.java	8 Mar 2007 07:34:14 -0000	1.36
  @@ -37,8 +37,10 @@
      public ConversationEntry(String id, List<String> stack, ConversationEntries entries)
      {
         this.id = id;
  +
         if (stack==null || id==null) throw new IllegalArgumentException();
         this.conversationIdStack = stack;
  +
         this.startDatetime = new Date();
         this.entries = entries;
         
  
  
  
  1.156     +67 -18    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.155
  retrieving revision 1.156
  diff -u -b -r1.155 -r1.156
  --- Manager.java	8 Mar 2007 07:25:06 -0000	1.155
  +++ Manager.java	8 Mar 2007 07:34:14 -0000	1.156
  @@ -36,6 +36,8 @@
   import org.jboss.seam.contexts.Lifecycle;
   import org.jboss.seam.log.LogProvider;
   import org.jboss.seam.log.Logging;
  +import org.jboss.seam.pages.ConversationIdParameter;
  +import org.jboss.seam.pages.Page;
   import org.jboss.seam.util.Id;
   
   /**
  @@ -43,7 +45,7 @@
    *
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.155 $
  + * @version $Revision: 1.156 $
    */
   @Scope(ScopeType.EVENT)
   @Name("org.jboss.seam.core.manager")
  @@ -426,9 +428,19 @@
       */
      public boolean restoreConversation(Map parameters)
      {
  +      String storedConversationId = null;
         
         //First, try to get the conversation id from a request parameter
  -      String storedConversationId = getRequestParameterValue(parameters, conversationIdParameter);
  +      if (FacesContext.getCurrentInstance() != null)
  +      {
  +         Page page = Pages.instance().getPage(FacesContext.getCurrentInstance().getViewRoot().getViewId());
  +         storedConversationId = page.getConversationIdParameter().getRequestConversationId();
  +      }
  +      else
  +      {
  +         storedConversationId = getRequestParameterValue(parameters, conversationIdParameter);   
  +      }
  +      
         String storedParentConversationId = getRequestParameterValue(parameters, parentConversationIdParameter);
         Boolean isLongRunningConversation = "true".equals( getRequestParameterValue(parameters, conversationIsLongRunningParameter) );
         
  @@ -640,7 +652,19 @@
       */
      public void initializeTemporaryConversation()
      {
  -      String id = Id.nextId();
  +      String id = null;
  +      
  +      FacesContext ctx = FacesContext.getCurrentInstance();
  +      if (ctx != null && ctx.getViewRoot() != null)
  +      {
  +         Page page = Pages.instance().getPage(ctx.getViewRoot().getViewId());      
  +         id = page.getConversationIdParameter().getInitialConversationId();
  +      }
  +      else
  +      {
  +         id = Id.nextId();
  +      }
  +      
         setCurrentConversationId(id);
         createCurrentConversationIdStack(id);
         setLongRunningConversation(false);
  @@ -780,6 +804,11 @@
         this.conversationTimeout = conversationTimeout;
      }
   
  +   public void beforeRedirect()
  +   {
  +      beforeRedirect(null);
  +   }
  +
      /**
       * Temporarily promote a temporary conversation to
       * a long running conversation for the duration of
  @@ -787,7 +816,7 @@
       * conversation will be demoted back to a temporary
       * conversation.
       */
  -   public void beforeRedirect()
  +   public void beforeRedirect(String viewId)
      {
         //DONT BREAK, icefaces uses this
         if (!destroyBeforeRedirect)
  @@ -801,15 +830,36 @@
            ce.setRemoveAfterRedirect( !isLongRunningConversation() );
            setLongRunningConversation(true);
         }
  +      
  +      FacesContext ctx = FacesContext.getCurrentInstance();
  +      
  +      if (viewId != null && ctx != null && ctx.getViewRoot() != null)
  +      {
  +         Page source = Pages.instance().getPage(ctx.getViewRoot().getViewId());
  +         Page target = Pages.instance().getPage(viewId);
  +         
  +         ConversationIdParameter sp = source.getConversationIdParameter();
  +         ConversationIdParameter tp = target.getConversationIdParameter();
  +         
  +         if ((sp.getName() == null && tp.getName() != null) ||
  +             (sp.getName() != null && tp.getName() == null) ||
  +             (sp.getName() != null && !sp.getName().equals(tp.getName())))
  +         {
  +            updateCurrentConversationId(target.getConversationIdParameter().getInitialConversationId());
  +         }      
  +      }
      }
   
      /**
       * Add the conversation id to a URL, if necessary
       */
  -   public String encodeConversationId(String url) 
  +   public String encodeConversationId(String url, String viewId) 
      {
  +      Page page = Pages.instance().getPage(viewId);
  +      String paramName = page.getConversationIdParameter().getParameterName();
  +      
         //DONT BREAK, icefaces uses this
  -      if ( Seam.isSessionInvalid() || containsParameter(url, conversationIdParameter) )
  +      if ( Seam.isSessionInvalid() || containsParameter(url, paramName) )
         {
            return url;
         }
  @@ -817,10 +867,10 @@
         {
            if ( isNestedConversation() )
            {
  -            return new StringBuilder( url.length() + conversationIdParameter.length() + 5 )
  +            return new StringBuilder( url.length() + paramName.length() + 5 )
                     .append(url)
                     .append( url.contains("?") ? '&' : '?' )
  -                  .append(conversationIdParameter)
  +                  .append(paramName)
                     .append('=')
                     .append( encode( getParentConversationId() ) )
                     .append('&')
  @@ -835,12 +885,12 @@
         }
         else
         {
  -         StringBuilder builder = new StringBuilder( url.length() + conversationIdParameter.length() + 5 )
  +         StringBuilder builder = new StringBuilder( url.length() + paramName.length() + 5 )
                  .append(url)
                  .append( url.contains("?") ? '&' : '?' )
  -               .append(conversationIdParameter)
  +               .append(paramName)
                  .append('=')
  -               .append( encode( getCurrentConversationId() ) );
  +               .append( encode( page.getConversationIdParameter().getParameterValue() ) );
            if ( isNestedConversation() && !isReallyLongRunningConversation() )
            {
               builder.append('&')
  @@ -980,8 +1030,8 @@
               );
         if (includeConversationId)
         {
  -         url = encodeConversationId(url);
  -         beforeRedirect();
  +         beforeRedirect(viewId);
  +         url = encodeConversationId(url, viewId);
         }
         url = Pages.instance().encodeScheme(viewId, context, url);            
         if ( log.isDebugEnabled() )
  @@ -1012,14 +1062,13 @@
       * @param url the requested URL
       * @return the resulting URL with the conversationId appended
       */
  -   public String appendConversationIdFromRedirectFilter(String url)
  +   public String appendConversationIdFromRedirectFilter(String url, String viewId)
      {
         boolean appendConversationId = !controllingRedirect;
         if (appendConversationId)
         {
  -         
  -         url = encodeConversationId(url);
  -         beforeRedirect();
  +         beforeRedirect(viewId);         
  +         url = encodeConversationId(url, viewId);
         }
         return url;
      }
  
  
  
  1.103     +36 -2     jboss-seam/src/main/org/jboss/seam/core/Pages.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Pages.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Pages.java,v
  retrieving revision 1.102
  retrieving revision 1.103
  diff -u -b -r1.102 -r1.103
  --- Pages.java	25 Feb 2007 22:38:21 -0000	1.102
  +++ Pages.java	8 Mar 2007 07:34:14 -0000	1.103
  @@ -39,6 +39,8 @@
   import org.jboss.seam.log.Logging;
   import org.jboss.seam.pages.Action;
   import org.jboss.seam.pages.ConversationControl;
  +import org.jboss.seam.pages.ConversationIdParameter;
  +import org.jboss.seam.pages.ELConversationIdParameter;
   import org.jboss.seam.pages.Input;
   import org.jboss.seam.pages.Navigation;
   import org.jboss.seam.pages.Output;
  @@ -48,6 +50,7 @@
   import org.jboss.seam.pages.RedirectNavigationHandler;
   import org.jboss.seam.pages.RenderNavigationHandler;
   import org.jboss.seam.pages.Rule;
  +import org.jboss.seam.pages.SyntheticConversationIdParameter;
   import org.jboss.seam.pages.TaskControl;
   import org.jboss.seam.security.Identity;
   import org.jboss.seam.security.NotLoggedInException;
  @@ -73,6 +76,7 @@
      private Map<String, List<Page>> pageStacksByViewId = Collections.synchronizedMap( new HashMap<String, List<Page>>() );   
      private String noConversationViewId;
      private String loginViewId;
  +   private Map<String, ConversationIdParameter> conversations = Collections.synchronizedMap( new HashMap<String, ConversationIdParameter>() );
    
      private SortedSet<String> wildcardViewIds = new TreeSet<String>( 
            new Comparator<String>() {
  @@ -766,7 +770,14 @@
         {
            loginViewId = root.attributeValue("login-view-id");
         }
  -      List<Element> elements = root.elements("page");
  +      
  +      List<Element> elements = root.elements("conversation");
  +      for (Element conversation : elements)
  +      {
  +         parseConversation(conversation, conversation.attributeValue("name"));
  +      }
  +      
  +      elements = root.elements("page");
         for (Element page: elements)
         {
            parse( page, page.attributeValue("view-id") );
  @@ -796,6 +807,25 @@
         }
      }
      
  +   private void parseConversation(Element element, String name)
  +   {
  +      if (name == null)
  +      {
  +         throw new IllegalStateException("Must specify name for <conversation/> declaration");
  +      }
  +      
  +      if (conversations.containsKey(name))
  +      {
  +         throw new IllegalStateException("<conversation/> declaration already exists for [" + name + "]");
  +      }
  +      
  +      ELConversationIdParameter param = new ELConversationIdParameter(name, 
  +               element.attributeValue("parameter-name"), 
  +               element.attributeValue("parameter-value"));
  +      
  +      conversations.put(name, param);
  +   }
  +   
      /**
       * Parse a page element and add a Page to the map
       */
  @@ -812,6 +842,7 @@
         }
         Page page = new Page(viewId);
         pagesByViewId.put(viewId, page);
  +      
         parsePage(page, element, viewId);
         parseConversationControl( element, page.getConversationControl() );
         parseTaskControl(element, page.getTaskControl());
  @@ -839,7 +870,7 @@
      /**
       * Parse the attributes of page
       */
  -   private static Page parsePage(Page page, Element element, String viewId)
  +   private Page parsePage(Page page, Element element, String viewId)
      {
         
         page.setSwitchEnabled( !"disabled".equals( element.attributeValue("switch") ) );
  @@ -863,6 +894,9 @@
         page.setLoginRequired( "true".equals( element.attributeValue("login-required") ) );
         page.setScheme( element.attributeValue("scheme") );
         
  +      ConversationIdParameter param = conversations.get( element.attributeValue("conversation") );
  +      if (param != null) page.setConversationIdParameter(param);
  +      
         Action action = parseAction(element, "action");
         if (action!=null) page.getActions().add(action);
         List<Element> childElements = element.elements("action");
  
  
  



More information about the jboss-cvs-commits mailing list