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 Raimund Renkert
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 data;
raimund@2310: private HashMap 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();
raimund@2310: metaData = new HashMap();
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: }
raimund@2310: if ("date".equals(fieldName)) {
raimund@2310: value = metaData.get("date");
raimund@2310: }
raimund@2310: if ("calculation".equals(fieldName)) {
raimund@2310: value = metaData.get("calculation");
raimund@2310: }
raimund@2310: if ("reference".equals(fieldName)) {
raimund@2310: value = metaData.get("reference");
raimund@2310: }
raimund@2310: if ("location".equals(fieldName)) {
raimund@2310: value = metaData.get("location");
raimund@2310: }
raimund@2310: if ("km1".equals(fieldName)) {
raimund@2310: value = data.get(index)[0];
raimund@2310: }
raimund@2310: if ("location1".equals(fieldName)) {
raimund@2310: value = data.get(index)[1];
raimund@2310: }
raimund@2310: if ("W1".equals(fieldName)) {
raimund@2310: value = data.get(index)[2];
raimund@2310: }
raimund@2310: if ("Q1".equals(fieldName)) {
raimund@2310: value = data.get(index)[3];
raimund@2310: }
raimund@2310: if ("km2".equals(fieldName)) {
raimund@2310: value = data.get(index)[4];
raimund@2310: }
raimund@2310: if ("location2".equals(fieldName)) {
raimund@2310: value = data.get(index)[5];
raimund@2310: }
raimund@2310: if ("W2".equals(fieldName)) {
raimund@2310: value = data.get(index)[6];
raimund@2310: }
raimund@2310: if ("Q2".equals(fieldName)) {
raimund@2310: value = data.get(index)[7];
raimund@2310: }
raimund@2631: if ("Wcm1".equals(fieldName)) {
raimund@2631: value = data.get(index)[8];
raimund@2631: }
raimund@2631: if("Wcm2".equals(fieldName)) {
raimund@2631: value = data.get(index)[9];
raimund@2631: }
raimund@2310: return value;
raimund@2310: }
raimund@2310: }