package it.mice.voila.runtime.springmvc.bean;

import it.mice.voila.runtime.springmvc.csrf.SecuritySessionBean;
import it.mice.voila.runtime.springmvc.util.SpringMvcUtil;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Stack;

/**
 * Created by IntelliJ IDEA.
 * User: zzy9v4
 * Date: Aug 4, 2006
 * Time: 11:15:38 PM
 * To change this template use File | Settings | File Templates.
 */
public class ChooseInfoBean implements Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public static final String CHOOSE_INFO_BEAN_FORM = ChooseInfoBean.class.getName() + ".chooseInfoBeanForm";
    
    public static final String POPUP_INPUT_PARAMETER_PREFIX = "popup.i.parm";
    public static final String POPUP_OUTPUT_PARAMETER_PREFIX = "popup.o.parm";
    public static final String POPUP_URL_NAME = "popup.url";
    public static final String POPUP_TITLE_NAME = "popup.title";
    public static final String POPUP_JSCRIPT_NAME = "popup.jscript";

    private String chooseLastForwardName;
    private String chooseReturnPath;
    private HashMap<String, String> chooseOutputParmMap = new HashMap<String, String>();
    private String chooseTitle;
    private SecuritySessionBean securitySessionBean;
    
    public SecuritySessionBean getSecuritySessionBean() {
		return securitySessionBean;
	}

	public void setSecuritySessionBean(SecuritySessionBean securitySessionBean) {
		this.securitySessionBean = securitySessionBean;
	}

	public String getChooseLastForwardName() {
        return chooseLastForwardName;
    }

    public void setChooseLastForwardName(String chooseLastForwardName) {
        this.chooseLastForwardName = chooseLastForwardName;
    }

    public String getChooseReturnPath() {
        return chooseReturnPath;
    }

    public void setChooseReturnPath(String chooseReturnPath) {
        this.chooseReturnPath = chooseReturnPath;
    }

    public HashMap<String, String> getChooseOutputParmMap() {
        return chooseOutputParmMap;
    }

    public void setChooseOutputParmMap(HashMap<String, String> chooseOutputParmMap) {
        this.chooseOutputParmMap = chooseOutputParmMap;
    }

    public String getChooseTitle() {
        return chooseTitle;
    }

    public void setChooseTitle(String chooseTitle) {
        this.chooseTitle = chooseTitle;
    }
    
	public static ChooseInfoBean newInstance() {
		ChooseInfoBean chooseInfoBean = new ChooseInfoBean();
		Stack<ChooseInfoBean> stack = getStack(true);
		stack.push(chooseInfoBean);
		return chooseInfoBean;
    }

    @SuppressWarnings("unchecked")
	private static Stack<ChooseInfoBean> getStack(boolean createNew) {
		Stack<ChooseInfoBean> stack = (Stack<ChooseInfoBean>)SpringMvcUtil.getSession().getAttribute(ChooseInfoBean.CHOOSE_INFO_BEAN_FORM);
		if (stack == null && createNew) {
			stack = new Stack<ChooseInfoBean>();
			SpringMvcUtil.getSession().setAttribute(ChooseInfoBean.CHOOSE_INFO_BEAN_FORM, stack);
		}
		return stack;
	}

	public static ChooseInfoBean getCurrent() {
		Stack<ChooseInfoBean> stack = getStack(false);
		if (stack != null && !stack.empty()) {
			return stack.peek();
		}
		return null;
	}

	public static ChooseInfoBean popCurrent() {
		Stack<ChooseInfoBean> stack = getStack(false);
		if (stack != null && !stack.empty()) {
			return stack.pop();
		}
		return null;
	}
}
