Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements. See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership. The ASF licenses this file
   * to you 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.apache.webbeans.jsf;
 
 
Conversation related phase listener.

Version:
$Rev: 987758 $ $Date: 2010-08-21 15:49:53 +0200 (Sa, 21 Aug 2010) $
 
 public class WebBeansPhaseListener implements PhaseListener
 {
     private static final long serialVersionUID = 1L;

    
Logger instanc
 
     private final WebBeansLogger logger = WebBeansLogger.getLogger(WebBeansPhaseListener.class);
    
    
 
     public void afterPhase(PhaseEvent phaseEvent)
     {
         if (phaseEvent.getPhaseId().equals(.) ||
                 phaseEvent.getFacesContext().getResponseComplete())
         {
             if(!JSFUtil.isOwbApplication())
             {
                 return;
             }
             
             ConversationManager conversationManager = ConversationManager.getInstance();
             Conversation conversation = conversationManager.getConversationBeanReference();
 
             if (conversation.isTransient())
             {
                 .debug("Destroying the conversation context with cid : [{0}]"conversation.getId());
                 ContextFactory.destroyConversationContext();                                                    
             }
             else
             {
                 //Conversation must be used by one thread at a time
                 ConversationImpl owbConversation = (ConversationImpl)conversation;
                 owbConversation.updateTimeOut();
                 //Other threads can now access propogated conversation.
                 owbConversation.setInUsed(false);                
             }            
         }
     }

    
 
     public void beforePhase(PhaseEvent phaseEvent)
     {
         if (phaseEvent.getPhaseId().equals(.) && JSFUtil.isOwbApplication())
         {
             //It looks for cid parameter in the JSF request.
             //If request contains cid, then it must restore conversation
             //Otherwise create NonexistentException
             ConversationManager conversationManager = ConversationManager.getInstance();
             Conversation conversation = conversationManager.getConversationBeanReference();
             String cid = JSFUtil.getConversationId();
 
             if (conversation.isTransient())
             {
                 .debug("Creating a new transitional conversation with cid : [{0}]"conversation.getId());
                 ContextFactory.initConversationContext(null);
 
                 //Not restore, throw exception
                 if(cid != null && !cid.equals(""))
                {
                    throw new NonexistentConversationException("Propogated conversation with cid=" + cid + " is not restored. It creates a new transient conversation.");
                }
            }
            else
            {
                .debug("Restoring conversation with cid : [{0}]"conversation.getId());
                //Conversation must be used by one thread at a time
                ConversationImpl owbConversation = (ConversationImpl)conversation;
                if(!owbConversation.getInUsed().compareAndSet(falsetrue))
                {
                    ContextFactory.initConversationContext(null);
                    //Throw Busy exception
                    throw new BusyConversationException("Propogated conversation with cid=" + cid + " is used by other request. It creates a new transient conversation");
                }
                else
                {
                    ConversationContext conversationContext = conversationManager.getConversationContext(conversation);
                    ContextFactory.initConversationContext(conversationContext);
                }
            }
        }
    }
    public PhaseId getPhaseId()
    {
        return .;
    }
New to GrepCode? Check out our FAQ X