//===========================================================================
// package
//===========================================================================
package jp.gr.java_conf.bugslife.action;

//===========================================================================
// import
//===========================================================================
import java.io.IOException;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import org.apache.commons.logging.*;
import org.apache.struts.action.*;
import org.apache.struts.util.*;
import org.apache.commons.beanutils.*;

import jp.gr.java_conf.bugslife.form.*;
import jp.gr.java_conf.bugslife.selections.*;
import jp.gr.java_conf.bugslife.user.*;
import jp.gr.java_conf.bugslife.util.Converter;
/**
 *<PRE>
 * 
 * LogoffActionクラス
 *
 *</PRE>
 * @version	0.0
 * @author	鰐川 正寛
 */
public final class LogoffAction extends BaseAction 
{
//===========================================================================
// attributes
//===========================================================================
	/**
	 * Log
	 */
	private Log log = LogFactory.getLog(this.getClass().getName());
//===========================================================================
// methods
//===========================================================================
	/**
	 * exevute
	 *
	 * @param mapping The ActionMapping used to select this instance
	 * @param actionForm The optional ActionForm bean for this request (if any)
	 * @param request The HTTP request we are processing
	 * @param response The HTTP response we are creating
	 *
	 * @exception Exception if business logic throws an exception
	 */
	public ActionForward doAction(ActionMapping mapping,
				 ActionForm form,
				 HttpServletRequest request,
				 HttpServletResponse response)
				throws Exception {
		
		/*  初期処理
		 */
		HttpSession session = getSession(request);	//sessioの取得
		UserInfo logonUser = (UserInfo)getAttribute(session,"UserInfo");	//ログインユーザの取得
		ActionForward forward = null;
		LogoffForm myForm = (LogoffForm)form;	//formの取得
		
		Date now = new Date();
		
		//最終ログオフ日時の更新
		logonUser.setLastLogoffDate(now);
		logonUser.update(logonUser.getUno());
		
		myForm.setLogoffDateString(Converter.getDateString(now));
		
		//セッション無効化
		session.invalidate();
		System.gc();		//GCの明示的な呼び出し
		
		// Forward control to the specified success URI
		return (mapping.findForward("success"));
	}
}
