/*
 * $Id: DataResponse.java 220 2007-07-16 10:32:15Z sugimotokenichi $
 * Copyright (C) 2004-2006 SUGIMOTO Ken-ichi
 * 作成日: 2006/05/15
 */
package feat2.impl;

import java.util.Map;

import feat2.ApplicationException;
import feat2.CommandContext;
import feat2.Data;
import feat2.Processor;
import feat2.Response;
import feat2.config.DataConfig;

/**
 * DATAレスポンスの実装。
 * @author SUGIMOTO Ken-ichi
 */
public class DataResponse implements Response {

    private DataConfig config;
    private Data data;


    public DataResponse(Data data, DataConfig config) {
        this.data = data;
        this.config = config;
    }


    public String output(CommandContext ctx) throws ApplicationException {

        try {

            Map inputValues = Processor.processInputs(config, ctx);

            if ( Processor.processValidations(data, inputValues, config, ctx) ) {

                Processor.processInjection(data, inputValues);
                data.output(ctx);

            }

            else {

                return config.getErrorResponse().getValue();

            }

        }
        catch (Exception ex) {
            throw new ApplicationException(ex);
        }

        return null;

    }


}
