/*
 * 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.tutorial.service.blogic;

import java.util.ArrayList;
import java.util.List;
import jp.terasoluna.rich.tutorial.service.bean.UserBean;
import jp.terasoluna.rich.tutorial.service.bean.ResultData;
import jp.terasoluna.fw.service.rich.BLogic;

/**
 * 入力クラスを結果クラスに格納するBLogicクラス
 *
 */
public class SimpleBLogic implements BLogic<UserBean, ResultData> {

    /**
     * 入力クラスを結果クラスに格納する<br>
     * １．UserBeanクラスの属性の値をResultDataクラスに格納する。<br>
     * ２．総件数をResultDataクラスに設定する。<br>
     * ３．ResultDataクラスを返却する。
     *
     * @param params 入力クラス
     * @return 結果クラス
     */
    public ResultData execute(UserBean params) {
        ResultData result = new ResultData();
        List<UserBean> userBeanList = new ArrayList<UserBean>();
        UserBean userBean = new UserBean();
        userBean.setId(params.getId());
        userBean.setName(params.getName());
        userBean.setAge(params.getAge());
        userBean.setBirth(params.getBirth());
        userBeanList.add(userBean);
        result.setUserBean(userBeanList);
        result.setTotalCount(userBeanList.size());
        return result;
    }
}
