com.pureinfo.srm.reports.impl.STSimpleBase.java Source code

Java tutorial

Introduction

Here is the source code for com.pureinfo.srm.reports.impl.STSimpleBase.java

Source

/**
 * PureInfo Quake
 * @(#)StatisticableBase.java   1.0 2005-9-14
 * 
 * Copyright(c) 2004-2005, PureInfo Information Technology Corp. Ltd. 
 * All rights reserved, see the license file.
 * 
 * www.pureinfo.com.cn
 */

package com.pureinfo.srm.reports.impl;

import java.io.File;
import java.io.IOException;
import java.util.Date;

import org.apache.log4j.Logger;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;

import com.pureinfo.force.exception.PureException;
import com.pureinfo.srm.SRMConstants;
import com.pureinfo.srm.SRMExceptionTypes;
import com.pureinfo.srm.reports.IChartBuilder;
import com.pureinfo.srm.reports.IStatisticable;
import com.pureinfo.srm.reports.ReportConfigHelper;

/**
 * <P>
 * Created on 2005-9-14 21:12:06 <BR>
 * Last modified on 2005-9-14
 * </P>
 * 
 * @author Freeman.Hu
 * @version 1.0, 2005-9-14
 * @since Quake 1.0
 */
public abstract class STSimpleBase implements IStatisticable {
    //logger
    private final static Logger logger = Logger.getLogger(STSimpleBase.class.getName());

    public final static int TYPE_NUMBER = 0;

    public final static int TYPE_PERCENT = 1;

    //parameteters
    protected Date m_startDate;

    protected Date m_endDate;

    protected int m_nClassify = SRMConstants.DEFAULT_NO_CLASSIFY;

    public void setStartDate(Date startDate) {
        m_startDate = startDate;
    }

    public void setEndDate(Date endDate) {
        m_endDate = endDate;
    }

    public void setClassify(int _nClassify) {
        m_nClassify = _nClassify;
    }

    protected abstract IChartBuilder getChartBuilder() throws PureException;

    /**
     * @throws PureException
     * @see com.pureinfo.srm.reports.IStatisticable#statistic()
     */
    public final String statistic() throws PureException {
        IChartBuilder builder = getChartBuilder();
        JFreeChart chart = builder.buildChart();
        setChartInfo(builder.getChartInfo());
        String sFileName = ReportConfigHelper.makeImageFileName("png");
        try {
            String sPath = ReportConfigHelper.getImageLocalPath();
            File file = new File(sPath, sFileName);
            if (logger.isDebugEnabled()) {
                logger.debug("to save report chart as " + file.getAbsolutePath());
            }
            ChartUtilities.saveChartAsPNG(file, chart, m_chartInfo.getChartSize().x, m_chartInfo.getChartSize().y);
            return sFileName;
        } catch (IOException ex) {
            throw new PureException(SRMExceptionTypes.REPORT_SAVE_CHART, sFileName, ex);
        }
    }

    private ChartBuilderBase.ChartInfo m_chartInfo;

    public ChartBuilderBase.ChartInfo getChartInfo() {
        return m_chartInfo;
    }

    public void setChartInfo(ChartBuilderBase.ChartInfo _chartInfo) {
        m_chartInfo = _chartInfo;
    }
}