/*
 * 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.kintai.system.vo;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.MosPMenuConst;
import jp.mosp.common.MosPVo;
import jp.mosp.common.common.MospException;
import jp.mosp.common.dto.MCodeDto;
import jp.mosp.common.utils.StringUtil;

/**
 * @author yoshida
 *
 */
public class LeaveEarlyReasonCardVo extends MosPVo {
	
	private static final long	serialVersionUID			= -7620328907056255240L;
	
	// パラメータ名
	/**
	 * txtLeaveEarlyReason
	 */
	public static final String	PRM_TXT_LEAVE_EARLY_REASON	= "txtLeaveEarlyReason";
	
	// フィールド
	private String[]			aryLeaveEarlyReason;
	private String[]			aryTxtLeaveEarlyReason;
	
	// フィールド名及び制限
	/**
	 * 
	 */
	public String				NAM_LEAVE_EARLY_REASON;
	/**
	 * 
	 */
	public int					LEN_LEAVE_EARLY_REASON;
	

	/**
	 * コンストラクタ
	 */
	public LeaveEarlyReasonCardVo() {
		super();
		setViewPath(getClassName());
		aryLeaveEarlyReason = new String[0];
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.TTL_LEAVE_EARLY_REASON;
		createAryMenu(CMD_MENU_SYSTEM2, MosPMenuConst.getMenuReasonMaster());
	}
	
	@Override
	protected void setFieldsName() {
		NAM_LEAVE_EARLY_REASON = CommonConst.NAM_LEAVE_EARLY + CommonConst.NAM_REASON;
		LEN_LEAVE_EARLY_REASON = 15;
	}
	
	/**
	 * パラメータ設定
	 */
	@Override
	public void setParams(HttpServletRequest request) {
		aryTxtLeaveEarlyReason = request.getParameterValues(PRM_TXT_LEAVE_EARLY_REASON);
	}
	
	/**
	 * フィールド設定
	 * @param listLeave		早退理由リスト
	 */
	@Override
	public void setFields(List<?> listLeave) {
		// 配列の初期化
		aryLeaveEarlyReason = StringUtil.getBlankArrayOneDimension(10);
		// データの設定
		int i = 0;
		Iterator<?> it = listLeave.iterator();
		while (it.hasNext()) {
			MCodeDto dto = (MCodeDto)it.next();
			aryLeaveEarlyReason[i] = escapeHTML(dto.getTName());
			i++;
		}
	}
	
	/**
	 * フィールドの妥当性確認
	 * @throws MospException MosP例外処理が発生した場合
	 */
	public void validate() throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		for (int i = 0; i < aryTxtLeaveEarlyReason.length; i++) {
			// 文字列長確認
			checkLength(aryTxtLeaveEarlyReason[i], LEN_LEAVE_EARLY_REASON, NAM_LEAVE_EARLY_REASON,
					PRM_TXT_LEAVE_EARLY_REASON + i);
		}
		// 妥当性確認終了時処理
		endValidation();
	}
	
	// アクセサメソッド
	/**
	 * @return aryLeaveEarlyReason
	 */
	public String[] getAryLeaveEarlyReason() {
		return aryLeaveEarlyReason.clone();
	}
	
	/**
	 * @return aryTxtLeaveEarlyReason
	 */
	public String[] getAryTxtLeaveEarlyReason() {
		return aryTxtLeaveEarlyReason.clone();
	}
	
	/**
	 * @param aryLeaveEarlyReason セットする aryLeaveEarlyReason
	 */
	public void setAryLeaveEarlyReason(String[] aryLeaveEarlyReason) {
		this.aryLeaveEarlyReason = aryLeaveEarlyReason.clone();
	}
	
	/**
	 * @param aryTxtLeaveEarlyReason セットする aryTxtLeaveEarlyReason
	 */
	public void setAryTxtLeaveEarlyReason(String[] aryTxtLeaveEarlyReason) {
		this.aryTxtLeaveEarlyReason = aryTxtLeaveEarlyReason.clone();
	}
	
}
