raimund@2310: package de.intevation.flys.artifacts.model;
raimund@2310: 
raimund@2310: import java.util.ArrayList;
raimund@2310: import java.util.HashMap;
raimund@2310: 
raimund@2310: import org.apache.log4j.Logger;
raimund@2310: 
raimund@2310: import net.sf.jasperreports.engine.JRDataSource;
raimund@2310: import net.sf.jasperreports.engine.JRException;
raimund@2310: import net.sf.jasperreports.engine.JRField;
raimund@2310: 
raimund@2310: 
raimund@2310: /**
raimund@2310:  * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
raimund@2310:  */
raimund@2310: public class WWQQJRDataSource implements JRDataSource
raimund@2310: {
raimund@2310:     /** The logger used in this exporter.*/
raimund@2310:     private static Logger logger = Logger.getLogger(WWQQJRDataSource.class);
raimund@2310: 
raimund@2310:     /**
raimund@2310:      *
raimund@2310:      */
raimund@2310:     private ArrayList<String[]> data;
raimund@2310:     private HashMap<String, String> metaData;
raimund@2310: 
raimund@2310:     private int index = -1;
raimund@2310: 
raimund@2310:     /**
raimund@2310:      *
raimund@2310:      */
raimund@2310:     public WWQQJRDataSource()
raimund@2310:     {
raimund@2310:         data = new ArrayList<String[]>();
raimund@2310:         metaData = new HashMap<String, String>();
raimund@2310:     }
raimund@2310: 
raimund@2310: 
raimund@2310:     /**
raimund@2310:      *
raimund@2310:      */
raimund@2310:     public void addData(String[] data) {
raimund@2310:         this.data.add(data);
raimund@2310:     }
raimund@2310: 
raimund@2310: 
raimund@2310:     /**
raimund@2310:      *
raimund@2310:      */
raimund@2310:     public void addMetaData(String key, String value) {
raimund@2310:         this.metaData.put(key, value);
raimund@2310:     }
raimund@2310: 
raimund@2310: 
raimund@2310:     /**
raimund@2310:      *
raimund@2310:      */
raimund@2310:     public boolean next() throws JRException
raimund@2310:     {
raimund@2310:         index++;
raimund@2310: 
raimund@2310:         return (index < data.size());
raimund@2310:     }
raimund@2310: 
raimund@2310: 
raimund@2310:     /**
raimund@2310:      *
raimund@2310:      */
raimund@2310:     public Object getFieldValue(JRField field) throws JRException
raimund@2310:     {
raimund@2310:         Object value = "";
raimund@2310:         String fieldName = field.getName();
raimund@2310:         if ("river".equals(fieldName)) {
raimund@2310:             value = metaData.get("river");
raimund@2310:         }
sascha@3085:         else if ("date".equals(fieldName)) {
raimund@2310:             value = metaData.get("date");
raimund@2310:         }
sascha@3085:         else if ("calculation".equals(fieldName)) {
raimund@2310:             value = metaData.get("calculation");
raimund@2310:         }
sascha@3085:         else if ("reference".equals(fieldName)) {
raimund@2310:             value = metaData.get("reference");
raimund@2310:         }
sascha@3085:         else if ("location".equals(fieldName)) {
raimund@2310:             value = metaData.get("location");
raimund@2310:         }
sascha@3085:         else if ("km1".equals(fieldName)) {
raimund@2310:             value = data.get(index)[0];
raimund@2310:         }
sascha@3085:         else if ("location1".equals(fieldName)) {
raimund@2310:             value = data.get(index)[1];
raimund@2310:         }
sascha@3085:         else if ("W1".equals(fieldName)) {
raimund@2310:             value = data.get(index)[2];
raimund@2310:         }
sascha@3085:         else if ("Q1".equals(fieldName)) {
raimund@2310:             value = data.get(index)[3];
raimund@2310:         }
sascha@3085:         else if ("km2".equals(fieldName)) {
raimund@2310:             value = data.get(index)[4];
raimund@2310:         }
sascha@3085:         else if ("location2".equals(fieldName)) {
raimund@2310:             value = data.get(index)[5];
raimund@2310:         }
sascha@3085:         else if ("W2".equals(fieldName)) {
raimund@2310:             value = data.get(index)[6];
raimund@2310:         }
sascha@3085:         else if ("Q2".equals(fieldName)) {
raimund@2310:             value = data.get(index)[7];
raimund@2310:         }
sascha@3085:         else if ("Wcm1".equals(fieldName)) {
raimund@2631:             value = data.get(index)[8];
raimund@2631:         }
sascha@3085:         else if ("Wcm2".equals(fieldName)) {
raimund@2631:             value = data.get(index)[9];
raimund@2631:         }
raimund@2310:         return value;
raimund@2310:     }
raimund@2310: }
sascha@3083: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :