/*
 * MosP - Mind Open Source Project    http://www.mosp.jp/
 * Copyright (C) MIND Co., Ltd.       http://www.e-mind.co.jp/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package jp.mosp.common;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import jp.mosp.common.common.MospConst;
import jp.mosp.common.dto.CmUserDto;
import jp.mosp.common.vo.ExclusiveVo;

/**
 * @author yoshida
 *
 */
public class SessionListener implements HttpSessionListener {
	
	public void sessionCreated(HttpSessionEvent se) {
		// セッション作成時は何もしない
	}
	
	public void sessionDestroyed(HttpSessionEvent se) {
		HttpSession session = se.getSession();
		ServletContext ctx = session.getServletContext();
		CmUserDto user = (CmUserDto)session.getAttribute(MospConst.ATT_USER);
		if (user == null) {
			return;
		}
		// 排他情報の削除
		List<?> listExclusive = (List<?>)ctx.getAttribute(CommonConst.ATT_EXCLUSIVE);
		ExclusiveVo exclusiveVo;
		if (listExclusive == null) {
			return;
		}
		for (int i = listExclusive.size() - 1; i >= 0; i--) {
			exclusiveVo = (ExclusiveVo)listExclusive.get(i);
			if (exclusiveVo.getUserId().equals(user.getUserId())) {
				// 自分の排他データを削除
				listExclusive.remove(i);
			}
		}
	}
	
}
