/*
 * MosP - Mind Open Source Project         http://www.mosp.jp/
 * Copyright (C) 1987-2009 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.part;

import java.sql.SQLException;
import java.util.List;

import jp.mosp.common.dao.MosPConfDao;
import jp.mosp.common.dto.MosPConfDto;

/**
 * 設定テーブルに関するPartクラス
 * @author yoshida
 * 	@version	0.0.1
 */
public class MosPConfPart extends BasePart {

	/**
	 * コンストラクタ
	 */
	public MosPConfPart() {
		super();
	}

	/**
	 * コンストラクタ
	 * @param partInfo
	 */
	public MosPConfPart(PartInfo partInfo) {
		super(partInfo);
	}

	/**
	 * CM_CONFテーブル用のDAO取得
	 * @return	初期化済みMosPConfDaoインスタンス
	 * @throws Exception
	 */
	private MosPConfDao getMosPConfDao() throws Exception {
		return (MosPConfDao)getPreparedDao(MosPConfDao.class.getCanonicalName());
	}

	/**
	 * 設定リスト取得(MOSP_CONF)
	 * @param confId 設定区分
	 * @return 設定リスト
	 * @throws Exception
	 */
	public String[][] getConfArray(String confId) throws Exception {
		// データの取得
		List<MosPConfDto> list = getMosPConfDao().findForCondition(confId);
		// データの整形
		String[][] array = new String[list.size()][2];
		for (int i = 0; i < list.size(); i++) {
			MosPConfDto dto = list.get(i);
			array[i][0] = dto.getConfCode();
			array[i][1] = dto.getConfValue();
		}
		return array;
	}

	/**
	 * 設定値取得(MOSP_CONF)
	 * @param confId   設定区分
	 * @param confCode 設定コード
	 * @return 設定値
	 * @throws Exception
	 */
	public String getConfValue(String confId, String confCode) throws Exception {
		// データの取得
		MosPConfDto dto = getMosPConfDao().findForKey(confId, confCode);
		if (dto == null) {
			return "";
		}
		return dto.getConfValue();
	}

	/**
	 * 設定リスト取得(MOSP_CONF)
	 * @param confId 設定区分
	 * @return 設定リスト
	 * @throws NoSuchFieldException 
	 * @throws IllegalAccessException 
	 * @throws SQLException 
	 */
	public List<MosPConfDto> getConfList(String confId) throws Exception {
		// データの取得
		return getMosPConfDao().findForCondition(confId);
	}

}
