/**
 * 
 */
package org.ajax4jsf.portlet.seam;

import java.util.Map;

import org.ajax4jsf.portlet.application.PortletViewState;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.Manager;

/**
 * @author asmirnov
 * 
 */
public class ConversationIdRetriver {

	public ConversationIdRetriver() {
		// Attempt to load Manager class.
		Manager.class.getName();
	}

	public void setConversationIdParameter(PortletViewState state) {
		if (Contexts.isEventContextActive()) {
			Manager manager = Manager.instance();
			if (manager.isLongRunningConversation()) {
				state.setConversationIdParameter(manager.getConversationIdParameter());
				state.setConversationId( manager.getCurrentConversationId() );
			} else {
				state.setConversationIdParameter(null);
				state.setConversationId(null);
			}
		}
	}

}
