/*
 * Copyright (c) 2007 NTT DATA Corporation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package jp.terasoluna.rich.functionsample.informationcontrol.service;

import java.util.Date;

import jp.terasoluna.fw.web.rich.context.support.
        RequestContextSupport;
import jp.terasoluna.rich.functionsample.common.bean.DummyIOData;
import jp.terasoluna.rich.functionsample.common.context.support.RequestContextSupportImpl;
import jp.terasoluna.rich.functionsample.informationcontrol.bean.InformationControlResultData;

/**
 * 制御情報取得サービスの実装クラス
 *
 */
public class InformationControlServiceImpl
        implements InformationControlService
        <DummyIOData, InformationControlResultData> {
    
    /**
     * 制御情報を扱うクラス
     */
    protected RequestContextSupport ctxSupport = null;
    
    /**
     * ユーザ情報を選択
     *
     * @param params ログオン情報
     * @return 制御情報
     */
    public InformationControlResultData getContextData(DummyIOData params) {
        
        //結果オブジェクト生成
        InformationControlResultData result =
            new InformationControlResultData();
        
        //リクエスト名取得、設定
        result.setRequestName(ctxSupport.getRequestName());

        //ユーザId取得、設定
        result.setUserId((String) ctxSupport.getProperty(
                RequestContextSupportImpl.USERID_KEY));
        
        //パスワード取得、設定
        result.setPassword(ctxSupport.getPropertyString(
                RequestContextSupportImpl.PASSWORD_KEY));
        
        //アクセス時刻取得、設定
        result.setAccessDate(ctxSupport.getProperty(
                RequestContextSupportImpl.ACCESS_DATE_KEY, Date.class));
        
        return result;
    }

    /**
     * 制御情報を扱うクラスを設定する。
     * @param ctxSupport 制御情報を扱うクラス
     */
    public void setCtxSupport(RequestContextSupport ctxSupport) {
        this.ctxSupport = ctxSupport;
    }
}
