raimund@2286: package de.intevation.flys.artifacts.model;
raimund@2286:
raimund@2286: import java.util.ArrayList;
raimund@2286: import java.util.HashMap;
raimund@2286:
raimund@2286: import org.apache.log4j.Logger;
raimund@2286:
raimund@2286: import net.sf.jasperreports.engine.JRDataSource;
raimund@2286: import net.sf.jasperreports.engine.JRException;
raimund@2286: import net.sf.jasperreports.engine.JRField;
raimund@2286:
raimund@2286:
raimund@2286: /**
raimund@2286: * @author Raimund Renkert
raimund@2286: */
raimund@2286: public class WQTJRDataSource implements JRDataSource
raimund@2286: {
raimund@2286: /** The logger used in this exporter.*/
raimund@2286: private static Logger logger = Logger.getLogger(WQTJRDataSource.class);
raimund@2286:
raimund@2286: /**
raimund@2286: *
raimund@2286: */
raimund@2286: private ArrayList data;
raimund@2286: private HashMap metaData;
raimund@2286:
raimund@2286: private int index = -1;
raimund@2286:
raimund@2286: /**
raimund@2286: *
raimund@2286: */
raimund@2286: public WQTJRDataSource()
raimund@2286: {
raimund@2286: data = new ArrayList();
raimund@2286: metaData = new HashMap();
raimund@2286: }
raimund@2286:
raimund@2286:
raimund@2286: /**
raimund@2286: *
raimund@2286: */
raimund@2286: public void addData(String[] data) {
raimund@2286: this.data.add(data);
raimund@2286: }
raimund@2286:
raimund@2286:
raimund@2286: /**
raimund@2286: *
raimund@2286: */
raimund@2286: public void addMetaData(String key, String value) {
raimund@2286: this.metaData.put(key, value);
raimund@2286: }
raimund@2286:
raimund@2286:
raimund@2286: /**
raimund@2286: *
raimund@2286: */
raimund@2286: public boolean next() throws JRException
raimund@2286: {
raimund@2286: index++;
raimund@2286:
raimund@2286: return (index < data.size());
raimund@2286: }
raimund@2286:
raimund@2286:
raimund@2286: /**
raimund@2286: *
raimund@2286: */
raimund@2286: public Object getFieldValue(JRField field) throws JRException
raimund@2286: {
raimund@2286: Object value = "";
raimund@2286: String fieldName = field.getName();
raimund@2286: if ("river".equals(fieldName)) {
raimund@2286: value = metaData.get("river");
raimund@2286: }
raimund@2286: if ("date".equals(fieldName)) {
raimund@2286: value = metaData.get("date");
raimund@2286: }
raimund@2286: if ("calculation".equals(fieldName)) {
raimund@2286: value = metaData.get("calculation");
raimund@2286: }
raimund@2286: if ("range".equals(fieldName)) {
raimund@2286: value = data.get(index)[0];
raimund@2286: }
raimund@2286: if ("W".equals(fieldName)) {
raimund@2286: value = data.get(index)[1];
raimund@2286: }
raimund@2286: if ("Q".equals(fieldName)) {
raimund@2286: value = data.get(index)[2];
raimund@2286: }
raimund@2286: if ("delta".equals(fieldName)) {
raimund@2286: value = data.get(index)[3];
raimund@2286: }
raimund@2286: if ("gaugename".equals(fieldName)) {
raimund@2286: value = data.get(index)[4];
raimund@2286: }
raimund@2286: return value;
raimund@2286: }
raimund@2286: }