view flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WKmsJRDataSource.java @ 4255:670e98f5a441

Fixed leak while merging facets. The ThemeList that is used by OutputHelper to sort the Facets for an Output now uses a list to store the ManagedFacets. The correct order is made up by sorting the List using Collections.sort() function of the Java JDK. Therfore, the ManagedFacet class implements the Comparable interface. The return value of its compareTo(other) method depends on the value of the 'position' field.
author Ingo Weinzierl <weinzierl.ingo@googlemail.com>
date Thu, 25 Oct 2012 14:01:46 +0200
parents 3e5f45a9e052
children
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 WKmsJRDataSource implements JRDataSource
{
    /** The logger used in this exporter.*/
    private static Logger logger = Logger.getLogger(WKmsJRDataSource.class);

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

    private int index = -1;

    /**
     *
     */
    public WKmsJRDataSource()
    {
        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");
        }
        else if ("date".equals(fieldName)) {
            value = metaData.get("date");
        }
        else if ("range".equals(fieldName)) {
            value = metaData.get("range");
        }
        else if ("gauge".equals(fieldName)) {
            value = metaData.get("gauge");
        }
        else if ("calculation".equals(fieldName)) {
            value = metaData.get("calculation");
        }
        else if ("differences".equals(fieldName)) {
            value = metaData.get("differences");
        }
        else if ("km".equals(fieldName)) {
            value = data.get(index)[0];
        }
        else if ("W".equals(fieldName)) {
            value = data.get(index)[1];
        }
        else if ("Q".equals(fieldName)) {
            value = data.get(index)[2];
        }
        else if ("description".equals(fieldName)) {
            value = data.get(index)[3];
        }
        else if ("location".equals(fieldName)) {
            value = data.get(index)[4];
        }
        else if ("gaugename".equals(fieldName)) {
            value = data.get(index)[5];
        }
        else if ("day".equals(fieldName)) {
            value = data.get(index)[6];
        }
        return value;
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org