raimund@2176: package de.intevation.flys.artifacts.model;
raimund@2176:
raimund@2176: import java.util.ArrayList;
raimund@2176: import java.util.HashMap;
raimund@2176:
raimund@2176: import org.apache.log4j.Logger;
raimund@2176:
raimund@2176: import net.sf.jasperreports.engine.JRDataSource;
raimund@2176: import net.sf.jasperreports.engine.JRException;
raimund@2176: import net.sf.jasperreports.engine.JRField;
raimund@2176:
raimund@2176:
raimund@2176: /**
raimund@2176: * @author Raimund Renkert
raimund@2176: */
raimund@2176: public class WKmsJRDataSource implements JRDataSource
raimund@2176: {
raimund@2176: /** The logger used in this exporter.*/
raimund@2176: private static Logger logger = Logger.getLogger(WKmsJRDataSource.class);
raimund@2176:
raimund@2176: /**
raimund@2176: *
raimund@2176: */
raimund@2176: private ArrayList data;
raimund@2176: private HashMap metaData;
raimund@2176:
raimund@2176: private int index = -1;
raimund@2176:
raimund@2176: /**
raimund@2176: *
raimund@2176: */
raimund@2176: public WKmsJRDataSource()
raimund@2176: {
raimund@2176: data = new ArrayList();
raimund@2176: metaData = new HashMap();
raimund@2176: }
raimund@2176:
raimund@2176:
raimund@2176: /**
raimund@2176: *
raimund@2176: */
raimund@2176: public void addData(String[] data) {
raimund@2176: this.data.add(data);
raimund@2176: }
raimund@2176:
raimund@2176:
raimund@2176: /**
raimund@2176: *
raimund@2176: */
raimund@2176: public void addMetaData(String key, String value) {
raimund@2176: this.metaData.put(key, value);
raimund@2176: }
raimund@2176:
raimund@2176:
raimund@2176: /**
raimund@2176: *
raimund@2176: */
raimund@2176: public boolean next() throws JRException
raimund@2176: {
raimund@2176: index++;
raimund@2176:
raimund@2176: return (index < data.size());
raimund@2176: }
raimund@2176:
raimund@2176:
raimund@2176: /**
raimund@2176: *
raimund@2176: */
raimund@2176: public Object getFieldValue(JRField field) throws JRException
raimund@2176: {
raimund@2176: Object value = "";
raimund@2176: String fieldName = field.getName();
raimund@2176: if ("river".equals(fieldName)) {
raimund@2176: value = metaData.get("river");
raimund@2176: }
raimund@2176: if ("date".equals(fieldName)) {
raimund@2176: value = metaData.get("date");
raimund@2176: }
raimund@2176: if ("range".equals(fieldName)) {
raimund@2176: value = metaData.get("range");
raimund@2176: }
raimund@2176: if ("gauge".equals(fieldName)) {
raimund@2176: value = metaData.get("gauge");
raimund@2176: }
raimund@2176: if ("calculation".equals(fieldName)) {
raimund@2176: value = metaData.get("calculation");
raimund@2176: }
raimund@2180: if ("differences".equals(fieldName)) {
raimund@2180: value = metaData.get("differences");
raimund@2180: }
raimund@2176: if ("km".equals(fieldName)) {
raimund@2176: value = data.get(index)[0];
raimund@2176: }
raimund@2176: if ("W".equals(fieldName)) {
raimund@2176: value = data.get(index)[1];
raimund@2176: }
raimund@2176: if ("Q".equals(fieldName)) {
raimund@2176: value = data.get(index)[2];
raimund@2176: }
raimund@2176: if ("description".equals(fieldName)) {
raimund@2176: value = data.get(index)[3];
raimund@2176: }
raimund@2176: if ("location".equals(fieldName)) {
raimund@2176: value = data.get(index)[4];
raimund@2176: }
raimund@2176: if ("gaugename".equals(fieldName)) {
raimund@2176: value = data.get(index)[5];
raimund@2176: }
raimund@2178: if ("day".equals(fieldName)) {
raimund@2178: value = data.get(index)[6];
raimund@2178: }
raimund@2176: return value;
raimund@2176: }
raimund@2176: }
sascha@3083: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :