changeset 4446:05a54b4d579d

Remove AbstractFixGenerator and use new KMIndexProcessor instead Don't use same base class for minfo and fixings artifacts. Instead use the new KMIndexProcessor to generate the same output for the same data types and facets.
author Björn Ricks <bjoern.ricks@intevation.de>
date Wed, 07 Nov 2012 14:34:13 +0100
parents 0eca080fc162
children a5993b69439b
files flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/AbstractFixGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixLongitudinalSectionGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDiffHeightYearGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDifferenceEpochGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDifferenceYearGenerator.java flys-artifacts/src/main/java/de/intevation/flys/exports/process/KMIndexProcessor.java
diffstat 6 files changed, 200 insertions(+), 148 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/AbstractFixGenerator.java	Wed Nov 07 14:22:54 2012 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,107 +0,0 @@
-package de.intevation.flys.exports.fixings;
-
-import org.apache.log4j.Logger;
-import org.jfree.data.xy.XYSeries;
-import org.jfree.data.xy.XYSeriesCollection;
-import org.w3c.dom.Document;
-
-import de.intevation.artifactdatabase.state.ArtifactAndFacet;
-import de.intevation.flys.artifacts.model.fixings.AnalysisPeriod;
-import de.intevation.flys.artifacts.model.fixings.QWD;
-import de.intevation.flys.jfree.StyledXYSeries;
-import de.intevation.flys.utils.KMIndex;
-
-public abstract class AbstractFixGenerator extends FixChartGenerator {
-
-    public static final String I18N_DW_YAXIS_LABEL_DEFAULT  =
-            "delta W [cm]";
-
-    public static final String I18N_DW_YAXIS_LABEL =
-            "chart.fixings.longitudinalsection.yaxis.label";
-
-    private final static Logger logger =
-            Logger.getLogger(AbstractFixGenerator.class);
-
-    @SuppressWarnings("unchecked")
-    protected void doSectorAverageOut(ArtifactAndFacet aaf, Document doc, boolean visible, int idx) {
-        logger.debug("doSectorAverageOut" + aaf.getFacet().getIndex());
-
-        int index = aaf.getFacet().getIndex();
-        int sectorNdx = index & 3;
-
-        KMIndex<AnalysisPeriod> kms =
-                (KMIndex<AnalysisPeriod>)aaf.getData(context);
-
-        if(kms == null) {
-            return;
-        }
-
-        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
-
-        for (KMIndex.Entry<AnalysisPeriod> entry: kms) {
-            double km = entry.getKm();
-            AnalysisPeriod ap = entry.getValue();
-            QWD qwd = ap.getQSectorAverages()[sectorNdx];
-            if (qwd == null) {
-                continue;
-            }
-            double deltaW = qwd.getDeltaW();
-            series.add(km, deltaW);
-        }
-
-        addAxisSeries(series, idx, visible);
-
-    }
-
-    @SuppressWarnings("unchecked")
-    protected void doAnalysisEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible, int idx) {
-        logger.debug("doAnalysisEventsOut");
-
-        KMIndex<QWD> kms =
-                (KMIndex<QWD>)aaf.getData(context);
-
-        if(kms == null) {
-            return;
-        }
-
-        XYSeriesCollection col = new XYSeriesCollection();
-
-        StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc);
-
-        for (KMIndex.Entry<QWD> entry: kms) {
-            double km = entry.getKm();
-            QWD qwd = entry.getValue();
-
-            series.add(km, qwd.getDeltaW());
-        }
-        col.addSeries(series);
-
-        addAxisDataset(col, idx, visible);
-    }
-
-    @SuppressWarnings("unchecked")
-    protected void doReferenceEventsOut(ArtifactAndFacet aaf, Document doc, boolean visible, int idx) {
-        logger.debug("doReferenceEventOut");
-
-        KMIndex<QWD> kms =
-                (KMIndex<QWD>)aaf.getData(context);
-
-        if(kms == null) {
-            return;
-        }
-
-        XYSeriesCollection col = new XYSeriesCollection();
-
-        StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc);
-
-        for (KMIndex.Entry<QWD> entry: kms) {
-            double km = entry.getKm();
-            QWD qwd = entry.getValue();
-
-            series.add(km, qwd.getDeltaW());
-        }
-        col.addSeries(series);
-
-        addAxisDataset(col, idx, visible);
-    }
-}
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixLongitudinalSectionGenerator.java	Wed Nov 07 14:22:54 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/fixings/FixLongitudinalSectionGenerator.java	Wed Nov 07 14:34:13 2012 +0100
@@ -14,13 +14,15 @@
 import de.intevation.flys.artifacts.model.fixings.AnalysisPeriod;
 import de.intevation.flys.artifacts.model.fixings.QWD;
 import de.intevation.flys.exports.ChartGenerator;
+import de.intevation.flys.exports.process.KMIndexProcessor;
+import de.intevation.flys.exports.process.Processor;
 import de.intevation.flys.jfree.FLYSAnnotation;
 import de.intevation.flys.jfree.StyledAreaSeriesCollection;
 import de.intevation.flys.jfree.StyledXYSeries;
 import de.intevation.flys.utils.KMIndex;
 
 public class FixLongitudinalSectionGenerator
-extends AbstractFixGenerator
+extends FixChartGenerator
 implements FacetTypes
 {
     private static Logger logger =
@@ -41,6 +43,11 @@
     public static final String I18N_XAXIS_LABEL_DEFAULT  =
             "[km]";
 
+    public static final String I18N_DW_YAXIS_LABEL_DEFAULT  =
+            "delta W [cm]";
+
+    public static final String I18N_DW_YAXIS_LABEL =
+            "chart.fixings.longitudinalsection.yaxis.label";
 
     public static enum YAXIS {
         dW(0);
@@ -55,17 +62,12 @@
         String name = aaf.getFacetName();
         logger.debug("FixLongitudinalSectionGenerator: doOut: " + name);
 
+        Processor processor = new KMIndexProcessor();
         if (name.contains(FIX_SECTOR_AVERAGE_LS_DEVIATION)) {
             doSectorAverageDeviationOut(aaf, doc, visible);
         }
-        else if (name.contains(FIX_SECTOR_AVERAGE_LS)) {
-            doSectorAverageOut(aaf, doc, visible, YAXIS.dW.idx);
-        }
-        else if (name.equals(FIX_REFERENCE_EVENTS_LS)) {
-            doReferenceEventsOut(aaf, doc, visible, YAXIS.dW.idx);
-        }
-        else if (name.equals(FIX_ANALYSIS_EVENTS_LS)) {
-            doAnalysisEventsOut(aaf, doc, visible, YAXIS.dW.idx);
+        else if (processor.canHandle(name)) {
+            processor.doOut(this, aaf, doc, visible, YAXIS.dW.idx);
         }
         else if (name.equals(FIX_DEVIATION_LS)) {
             doReferenceDeviationOut(aaf, doc, visible);
@@ -84,7 +86,6 @@
         }
         else {
             logger.warn("Unknown facet name " + name);
-            return;
         }
     }
 
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDiffHeightYearGenerator.java	Wed Nov 07 14:22:54 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDiffHeightYearGenerator.java	Wed Nov 07 14:34:13 2012 +0100
@@ -9,13 +9,15 @@
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.minfo.BedDiffYearResult;
 import de.intevation.flys.exports.StyledSeriesBuilder;
-import de.intevation.flys.exports.fixings.AbstractFixGenerator;
+import de.intevation.flys.exports.fixings.FixChartGenerator;
+import de.intevation.flys.exports.process.KMIndexProcessor;
+import de.intevation.flys.exports.process.Processor;
 import de.intevation.flys.jfree.FLYSAnnotation;
 import de.intevation.flys.jfree.StyledXYSeries;
 
 
 public class BedDiffHeightYearGenerator
-extends AbstractFixGenerator
+extends FixChartGenerator
 implements FacetTypes
 {
     public enum YAXIS {
@@ -38,6 +40,10 @@
     public static final String I18N_CHART_TITLE_DEFAULT = "Sohlenhöhen Differenz";
     public static final String I18N_XAXIS_LABEL_DEFAULT = "Fluss-Km";
     public static final String I18N_YAXIS_LABEL_DEFAULT = "delta S [cm / Jahr]";
+    public static final String I18N_DW_YAXIS_LABEL_DEFAULT  =
+            "delta W [cm]";
+    public static final String I18N_DW_YAXIS_LABEL =
+            "chart.fixings.longitudinalsection.yaxis.label";
 
     @Override
     protected YAxisWalker getYAxisWalker() {
@@ -73,20 +79,12 @@
             return;
         }
 
+        Processor processor = new KMIndexProcessor();
         if (name.equals(BED_DIFFERENCE_HEIGHT_YEAR)) {
             doBedDifferenceYearOut(
                 (BedDiffYearResult) bundle.getData(context),
                 bundle, attr, visible);
         }
-        else if (name.contains(FIX_SECTOR_AVERAGE_LS)) {
-            doSectorAverageOut( bundle, attr, visible, YAXIS.dW.idx);
-        }
-        else if (name.equals(FIX_REFERENCE_EVENTS_LS)) {
-            doReferenceEventsOut( bundle, attr, visible, YAXIS.dW.idx);
-        }
-        else if (name.equals(FIX_ANALYSIS_EVENTS_LS)) {
-            doAnalysisEventsOut( bundle, attr, visible, YAXIS.dW.idx);
-        }
         else if (name.equals(LONGITUDINAL_ANNOTATION)) {
             doAnnotations(
                 (FLYSAnnotation) bundle.getData(context),
@@ -94,6 +92,12 @@
                  attr,
                  visible);
         }
+        else if (processor.canHandle(name)) {
+            processor.doOut(this, bundle, attr, visible, YAXIS.dW.idx);
+        }
+        else {
+            logger.warn("Unknown facet name " + name);
+        }
     }
 
     @Override
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDifferenceEpochGenerator.java	Wed Nov 07 14:22:54 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDifferenceEpochGenerator.java	Wed Nov 07 14:34:13 2012 +0100
@@ -9,13 +9,15 @@
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.minfo.BedDiffEpochResult;
 import de.intevation.flys.exports.StyledSeriesBuilder;
-import de.intevation.flys.exports.fixings.AbstractFixGenerator;
+import de.intevation.flys.exports.fixings.FixChartGenerator;
+import de.intevation.flys.exports.process.KMIndexProcessor;
+import de.intevation.flys.exports.process.Processor;
 import de.intevation.flys.jfree.FLYSAnnotation;
 import de.intevation.flys.jfree.StyledXYSeries;
 
 
 public class BedDifferenceEpochGenerator
-extends AbstractFixGenerator
+extends FixChartGenerator
 implements FacetTypes
 {
     public enum YAXIS {
@@ -40,6 +42,11 @@
     public static final String I18N_XAXIS_LABEL_DEFAULT = "Fluss-Km";
     public static final String I18N_YAXIS_LABEL_DEFAULT = "delta S [m]";
     public static final String I18N_SECOND_YAXIS_LABEL_DEFAULT = "Höhe [m]";
+    public static final String I18N_DW_YAXIS_LABEL_DEFAULT  =
+            "delta W [cm]";
+    public static final String I18N_DW_YAXIS_LABEL =
+            "chart.fixings.longitudinalsection.yaxis.label";
+
 
     @Override
     protected YAxisWalker getYAxisWalker() {
@@ -75,6 +82,7 @@
             return;
         }
 
+        Processor processor = new KMIndexProcessor();
         if (name.equals(BED_DIFFERENCE_EPOCH)) {
             doBedDifferenceEpochOut(
                 (BedDiffEpochResult) bundle.getData(context),
@@ -88,14 +96,8 @@
             doBedDifferenceHeightsOut((BedDiffEpochResult)bundle.getData(context),
                 bundle, attr, visible, 1);
         }
-        else if (name.contains(FIX_SECTOR_AVERAGE_LS)) {
-            doSectorAverageOut( bundle, attr, visible, YAXIS.dW.idx);
-        }
-        else if (name.equals(FIX_REFERENCE_EVENTS_LS)) {
-            doReferenceEventsOut( bundle, attr, visible, YAXIS.dW.idx);
-        }
-        else if (name.equals(FIX_ANALYSIS_EVENTS_LS)) {
-            doAnalysisEventsOut( bundle, attr, visible, YAXIS.dW.idx);
+        else if (processor.canHandle(name)) {
+            processor.doOut(this, bundle, attr, visible, YAXIS.dW.idx);
         }
         else if (name.equals(LONGITUDINAL_ANNOTATION)) {
             doAnnotations(
@@ -104,6 +106,9 @@
                  attr,
                  visible);
         }
+        else {
+            logger.warn("Unknown facet name " + name);
+        }
     }
 
     @Override
--- a/flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDifferenceYearGenerator.java	Wed Nov 07 14:22:54 2012 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/minfo/BedDifferenceYearGenerator.java	Wed Nov 07 14:34:13 2012 +0100
@@ -9,13 +9,15 @@
 import de.intevation.flys.artifacts.model.FacetTypes;
 import de.intevation.flys.artifacts.model.minfo.BedDiffYearResult;
 import de.intevation.flys.exports.StyledSeriesBuilder;
-import de.intevation.flys.exports.fixings.AbstractFixGenerator;
+import de.intevation.flys.exports.fixings.FixChartGenerator;
+import de.intevation.flys.exports.process.KMIndexProcessor;
+import de.intevation.flys.exports.process.Processor;
 import de.intevation.flys.jfree.FLYSAnnotation;
 import de.intevation.flys.jfree.StyledXYSeries;
 
 
 public class BedDifferenceYearGenerator
-extends AbstractFixGenerator
+extends FixChartGenerator
 implements FacetTypes
 {
     public enum YAXIS {
@@ -42,6 +44,10 @@
     public static final String I18N_YAXIS_LABEL_DEFAULT = "delta S [m]";
     public static final String I18N_SECOND_YAXIS_LABEL_DEFAULT = "Morph. Breite [m]";
     public static final String I18N_THIRD_YAXIS_LABEL_DEFAULT = "Höhe [m]";
+    public static final String I18N_DW_YAXIS_LABEL_DEFAULT  =
+            "delta W [cm]";
+    public static final String I18N_DW_YAXIS_LABEL =
+            "chart.fixings.longitudinalsection.yaxis.label";
 
     @Override
     protected YAxisWalker getYAxisWalker() {
@@ -77,6 +83,7 @@
             return;
         }
 
+        Processor processor = new KMIndexProcessor();
         if (name.equals(BED_DIFFERENCE_YEAR)) {
             doBedDifferenceYearOut(
                 (BedDiffYearResult) bundle.getData(context),
@@ -97,14 +104,8 @@
                 (BedDiffYearResult)bundle.getData(context),
                 bundle, attr, visible, 1);
         } 
-        else if (name.contains(FIX_SECTOR_AVERAGE_LS)) {
-            doSectorAverageOut( bundle, attr, visible, YAXIS.dW.idx);
-        }
-        else if (name.equals(FIX_REFERENCE_EVENTS_LS)) {
-            doReferenceEventsOut( bundle, attr, visible, YAXIS.dW.idx);
-        }
-        else if (name.equals(FIX_ANALYSIS_EVENTS_LS)) {
-            doAnalysisEventsOut( bundle, attr, visible, YAXIS.dW.idx);
+        else if (processor.canHandle(name)) {
+            processor.doOut(this, bundle, attr, visible, YAXIS.dW.idx);
         }
         else if (name.equals(LONGITUDINAL_ANNOTATION)) {
             doAnnotations(
@@ -113,6 +114,12 @@
                  attr,
                  visible);
         }
+        else if (processor.canHandle(name)) {
+            processor.doOut(this, bundle, attr, visible, YAXIS.dW.idx);
+        }
+        else {
+            logger.warn("Unknown facet name " + name);
+        }
     }
 
     private void doBedDifferenceHeightsOut(
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/exports/process/KMIndexProcessor.java	Wed Nov 07 14:34:13 2012 +0100
@@ -0,0 +1,142 @@
+package de.intevation.flys.exports.process;
+
+import org.apache.log4j.Logger;
+import org.jfree.data.xy.XYSeries;
+import org.jfree.data.xy.XYSeriesCollection;
+import org.w3c.dom.Document;
+
+import de.intevation.artifactdatabase.state.ArtifactAndFacet;
+import de.intevation.artifacts.CallContext;
+import de.intevation.flys.artifacts.model.FacetTypes;
+import de.intevation.flys.artifacts.model.fixings.AnalysisPeriod;
+import de.intevation.flys.artifacts.model.fixings.QWD;
+import de.intevation.flys.exports.XYChartGenerator;
+import de.intevation.flys.jfree.StyledXYSeries;
+import de.intevation.flys.utils.KMIndex;
+
+public class KMIndexProcessor implements Processor {
+
+    private static final Logger logger = Logger.getLogger(KMIndexProcessor.class);
+
+    @Override
+    public void doOut(XYChartGenerator generator, ArtifactAndFacet aandf,
+            Document theme, boolean visible, int index) {
+        String facettype = aandf.getFacetName();
+         if (facettype.contains(FacetTypes.FIX_SECTOR_AVERAGE_LS)) {
+            doSectorAverageOut(generator, aandf, theme, visible, index);
+        }
+        else if (facettype.equals(FacetTypes.FIX_REFERENCE_EVENTS_LS)) {
+            doReferenceEventsOut(generator, aandf, theme, visible, index);
+        }
+        else if (facettype.equals(FacetTypes.FIX_ANALYSIS_EVENTS_LS)) {
+            doAnalysisEventsOut(generator, aandf, theme, visible, index);
+        }
+
+    }
+
+    @Override
+    public boolean canHandle(String facettype) {
+        if (facettype == null) {
+            return false;
+        }
+
+        if (facettype.equals(FacetTypes.FIX_SECTOR_AVERAGE_LS)
+                || facettype.equals(FacetTypes.FIX_REFERENCE_EVENTS_LS)
+                || facettype.equals(FacetTypes.FIX_ANALYSIS_EVENTS_LS))
+        {
+            return true;
+        }
+        return false;
+    }
+
+    private void doSectorAverageOut(XYChartGenerator generator, ArtifactAndFacet aaf,
+            Document doc, boolean visible, int idx) {
+        logger.debug("doSectorAverageOut" + aaf.getFacet().getIndex());
+
+        CallContext context = generator.getCallContext();
+        int index = aaf.getFacet().getIndex();
+        int sectorNdx = index & 3;
+
+        @SuppressWarnings("unchecked")
+        KMIndex<AnalysisPeriod> kms =
+                (KMIndex<AnalysisPeriod>)aaf.getData(context);
+
+        if(kms == null) {
+            return;
+        }
+
+        XYSeries series = new StyledXYSeries(aaf.getFacetDescription(), doc);
+
+        for (KMIndex.Entry<AnalysisPeriod> entry: kms) {
+            double km = entry.getKm();
+            AnalysisPeriod ap = entry.getValue();
+            QWD qwd = ap.getQSectorAverages()[sectorNdx];
+            if (qwd == null) {
+                continue;
+            }
+            double deltaW = qwd.getDeltaW();
+            series.add(km, deltaW);
+        }
+
+        generator.addAxisSeries(series, idx, visible);
+    }
+
+    private void doReferenceEventsOut(XYChartGenerator generator, 
+            ArtifactAndFacet aaf, Document doc, boolean visible, int idx) {
+        logger.debug("doReferenceEventOut");
+
+        CallContext context = generator.getCallContext();
+
+        @SuppressWarnings("unchecked")
+        KMIndex<QWD> kms =
+                (KMIndex<QWD>)aaf.getData(context);
+
+        if(kms == null) {
+            return;
+        }
+
+        XYSeriesCollection col = new XYSeriesCollection();
+
+        StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false,
+                doc);
+
+        for (KMIndex.Entry<QWD> entry: kms) {
+            double km = entry.getKm();
+            QWD qwd = entry.getValue();
+
+            series.add(km, qwd.getDeltaW());
+        }
+        col.addSeries(series);
+
+        generator.addAxisDataset(col, idx, visible);
+    }
+
+    private void doAnalysisEventsOut(XYChartGenerator generator, 
+            ArtifactAndFacet aaf, Document doc, boolean visible, int idx) {
+        logger.debug("doAnalysisEventsOut");
+
+        CallContext context = generator.getCallContext();
+
+        @SuppressWarnings("unchecked")
+        KMIndex<QWD> kms =
+                (KMIndex<QWD>)aaf.getData(context);
+
+        if(kms == null) {
+            return;
+        }
+
+        XYSeriesCollection col = new XYSeriesCollection();
+
+        StyledXYSeries series = new StyledXYSeries(aaf.getFacetDescription(), false, doc);
+
+        for (KMIndex.Entry<QWD> entry: kms) {
+            double km = entry.getKm();
+            QWD qwd = entry.getValue();
+
+            series.add(km, qwd.getDeltaW());
+        }
+        col.addSeries(series);
+
+        generator.addAxisDataset(col, idx, visible);
+    }
+}

http://dive4elements.wald.intevation.org