package WEB-INF.classes.wenrgise.common.webtier.action;

import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import wenrgise.common.exception.EnrgiseApplicationException;
import wenrgise.common.exception.EnrgiseSystemException;
import wenrgise.common.webtier.action.BaseAction;
import wenrgise.common.webtier.form.BaseForm;
import wenrgise.ejb.common.session.UserSession;

public class ExitAction extends BaseAction {
  public ActionForward executeImpl(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws EnrgiseApplicationException, EnrgiseSystemException, IllegalAccessException, InvocationTargetException, InstantiationException, ClassNotFoundException, ServletException, IOException {
    System.out.println("I am in Exit Action ---->");
    BaseForm oBaseForm = (BaseForm)form;
    String sFormBean = mapping.getAttribute();
    String sScreenName = oBaseForm.getScreenName();
    if (oBaseForm.isHeaderDataChanged() || oBaseForm.isDetailDataChanged())
      throw new EnrgiseApplicationException("wenrgise.common.datashouldbesaved", "M"); 
    String sFormName = form.getClass().getName();
    UserSession oUser = getUserSessionBean(request);
    if (oUser != null)
      oUser.removeAllIfExists(sFormName, sScreenName); 
    HttpSession session = request.getSession();
    session.removeAttribute(sFormBean);
    return mapping.findForward("success");
  }
}
