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 <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
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<String[]> data;
raimund@2286:     private HashMap<String, String> 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<String[]>();
raimund@2286:         metaData = new HashMap<String, String>();
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:         }
sascha@3085:         else if ("date".equals(fieldName)) {
raimund@2286:             value = metaData.get("date");
raimund@2286:         }
sascha@3085:         else if ("calculation".equals(fieldName)) {
raimund@2286:             value = metaData.get("calculation");
raimund@2286:         }
sascha@3085:         else if ("range".equals(fieldName)) {
raimund@2286:             value = data.get(index)[0];
raimund@2286:         }
sascha@3085:         else if ("W".equals(fieldName)) {
raimund@2286:             value = data.get(index)[1];
raimund@2286:         }
sascha@3085:         else if ("Q".equals(fieldName)) {
raimund@2286:             value = data.get(index)[2];
raimund@2286:         }
sascha@3085:         else if ("delta".equals(fieldName)) {
raimund@2286:             value = data.get(index)[3];
raimund@2286:         }
sascha@3085:         else if ("gaugename".equals(fieldName)) {
raimund@2286:             value = data.get(index)[4];
raimund@2286:         }
raimund@2286:         return value;
raimund@2286:     }
raimund@2286: }
sascha@3083: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :