view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WQTJRDataSource.java @ 2608:938e2f6c0c9a

Refactored the code of the fixings filter building to be useful in more cases. flys-artifacts/trunk@4190 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Tue, 03 Apr 2012 13:46:16 +0000
parents 89ca1e8572e4
children 4bd3d8bbb60c
line wrap: on
line source
package de.intevation.flys.artifacts.model;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.log4j.Logger;

import net.sf.jasperreports.engine.JRDataSource;
import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRField;


/**
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class WQTJRDataSource implements JRDataSource
{
    /** The logger used in this exporter.*/
    private static Logger logger = Logger.getLogger(WQTJRDataSource.class);

    /**
     *
     */
    private ArrayList<String[]> data;
    private HashMap<String, String> metaData;

    private int index = -1;

    /**
     *
     */
    public WQTJRDataSource()
    {
        data = new ArrayList<String[]>();
        metaData = new HashMap<String, String>();
    }


    /**
     *
     */
    public void addData(String[] data) {
        this.data.add(data);
    }


    /**
     *
     */
    public void addMetaData(String key, String value) {
        this.metaData.put(key, value);
    }


    /**
     *
     */
    public boolean next() throws JRException
    {
        index++;

        return (index < data.size());
    }


    /**
     *
     */
    public Object getFieldValue(JRField field) throws JRException
    {
        Object value = "";
        String fieldName = field.getName();
        if ("river".equals(fieldName)) {
            value = metaData.get("river");
        }
        if ("date".equals(fieldName)) {
            value = metaData.get("date");
        }
        if ("calculation".equals(fieldName)) {
            value = metaData.get("calculation");
        }
        if ("range".equals(fieldName)) {
            value = data.get(index)[0];
        }
        if ("W".equals(fieldName)) {
            value = data.get(index)[1];
        }
        if ("Q".equals(fieldName)) {
            value = data.get(index)[2];
        }
        if ("delta".equals(fieldName)) {
            value = data.get(index)[3];
        }
        if ("gaugename".equals(fieldName)) {
            value = data.get(index)[4];
        }
        return value;
    }
}

http://dive4elements.wald.intevation.org