Mercurial > dive4elements > river
changeset 7077:0a337f0005c2 generator-refactoring
Extended init() of OutGenerator to take name of the out to serve.
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/collections/D4EArtifactCollection.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/collections/D4EArtifactCollection.java Fri Sep 20 16:34:09 2013 +0200 @@ -330,7 +330,7 @@ // XXX NOTE: the outGen is not able to process its generate() operation, // because it has no OutputStream set! - outGen.init(XMLUtils.newDocument(), null, getContext()); + outGen.init(out, XMLUtils.newDocument(), null, getContext()); prepareMasterArtifact(outGen); try { @@ -382,16 +382,12 @@ // If type contains 'chartinfo' use a generator that // just allow access to width, height etc. - OutGenerator generator = null; - if (type != null - && type.length() > 0 - && type.indexOf("chartinfo") > 0) - { - generator = RiverContext.getOutGenerator(context, type, subtype); - } - else { - generator = RiverContext.getOutGenerator(context, name, subtype); - } + + String key = type != null && !type.isEmpty() && type.indexOf("chartinfo") > 0 + ? type + : name; + + OutGenerator generator = RiverContext.getOutGenerator(context, key, subtype); if (generator == null) { log.error("There is no generator specified for output: " + name); @@ -417,7 +413,7 @@ } } - generator.init(format, out, context); + generator.init(key, format, out, context); generator.setSettings(settings); generator.setCollection(this); prepareMasterArtifact(generator);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ATExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ATExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -45,7 +45,8 @@ protected WQ data; protected CallContext context; protected OutputStream out; - protected D4EArtifact master; + protected D4EArtifact master; + protected String outName; protected D4EArtifactCollection collection; @@ -59,7 +60,8 @@ } @Override - public void init(Document request, OutputStream out, CallContext context) { + public void init(String outName, Document request, OutputStream out, CallContext context) { + this.outName = outName; this.context = context; this.out = out; }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/AbstractExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/AbstractExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -66,6 +66,9 @@ /** XPath that points to the desired export facet. */ public static final String XPATH_FACET = "/art:action/@art:type"; + /** The out name to serve. */ + protected String outName; + /** The document of the incoming out() request. */ protected Document request; @@ -122,9 +125,15 @@ @Override - public void init(Document request, OutputStream out, CallContext context) { + public void init( + String outName, + Document request, + OutputStream out, + CallContext context + ) { logger.debug("AbstractExporter.init"); + this.outName = outName; this.request = request; this.out = out; this.context = context;
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator.java Fri Sep 20 16:34:09 2013 +0200 @@ -137,6 +137,8 @@ /** List of annotations to insert in plot. */ protected List<RiverAnnotation> annotations = new ArrayList<RiverAnnotation>(); + protected String outName; + /** * A mini interface that allows to walk over the YAXIS enums defined in * subclasses. @@ -684,9 +686,10 @@ @Override - public void init(Document request, OutputStream out, CallContext context) { + public void init(String outName, Document request, OutputStream out, CallContext context) { logger.debug("ChartGenerator.init"); + this.outName = outName; this.request = request; this.out = out; this.context = context;
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartGenerator2.java Fri Sep 20 16:34:09 2013 +0200 @@ -128,6 +128,8 @@ protected abstract List<AxisSection> buildYAxisSections(); + protected String outName; + /** * Default constructor that initializes internal data structures. */ @@ -307,9 +309,10 @@ @Override - public void init(Document request, OutputStream out, CallContext context) { + public void init(String outName, Document request, OutputStream out, CallContext context) { logger.debug("ChartGenerator2.init"); + this.outName = outName; this.request = request; this.out = out; this.context = context;
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartInfoGenerator.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartInfoGenerator.java Fri Sep 20 16:34:09 2013 +0200 @@ -82,10 +82,10 @@ * @param out * @param context */ - public void init(Document request, OutputStream out, CallContext context) { + public void init(String outName, Document request, OutputStream out, CallContext context) { this.out = out; - generator.init(request, out, context); + generator.init(outName, request, out, context); }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ChartInfoGenerator2.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ChartInfoGenerator2.java Fri Sep 20 16:34:09 2013 +0200 @@ -82,10 +82,10 @@ * @param out * @param context */ - public void init(Document request, OutputStream out, CallContext context) { + public void init(String outName, Document request, OutputStream out, CallContext context) { this.out = out; - generator.init(request, out, context); + generator.init(outName, request, out, context); }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ComputedDischargeCurveExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -82,15 +82,10 @@ protected boolean isCalculated; protected Date validSince; - public void init(Document request, OutputStream out, CallContext context) { - logger.debug("ComputedDischargeCurveExporter.init"); - - super.init(request, out, context); - - this.data = new ArrayList<WQKms>(); + public ComputedDischargeCurveExporter() { + data = new ArrayList<WQKms>(); } - @Override protected void addData(Object d) { if (d instanceof CalculationResult) {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/DurationCurveExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/DurationCurveExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -73,16 +73,10 @@ /** The storage that contains all WQKms objects for the different facets. */ protected List<WQDay> data; - - public void init(Document request, OutputStream out, CallContext context) { - logger.debug("DurationCurveExporter.init"); - - super.init(request, out, context); - - this.data = new ArrayList<WQDay>(); + public DurationCurveExporter() { + data = new ArrayList<WQDay>(); } - @Override protected void addData(Object d) { if (d instanceof CalculationResult) {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/FlowVelocityExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/FlowVelocityExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -58,13 +58,10 @@ protected List<FlowVelocityData[]> data; - - public void init(Document request, OutputStream out, CallContext cc) { - super.init(request, out, cc); + public FlowVelocityExporter() { data = new ArrayList<FlowVelocityData[]>(); } - @Override protected void addData(Object d) { if (d instanceof CalculationResult) {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/HistoricalDischargeCurveExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/HistoricalDischargeCurveExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -77,14 +77,10 @@ protected List<WQTimerange[]> data; - - public void init(Document request, OutputStream out, CallContext cc) { - super.init(request, out, cc); - + public HistoricalDischargeCurveExporter() { data = new ArrayList<WQTimerange[]>(); } - @Override protected void addData(Object d) { logger.debug("Add data of class: " + d.getClass());
--- a/artifacts/src/main/java/org/dive4elements/river/exports/MapGenerator.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/MapGenerator.java Fri Sep 20 16:34:09 2013 +0200 @@ -65,15 +65,18 @@ protected String srid; + protected String outName; + @Override public void setup(Element config) { logger.debug("MapGenerator.setup"); } @Override - public void init(Document request, OutputStream out, CallContext context) { + public void init(String outName, Document request, OutputStream out, CallContext context) { logger.debug("MapGenerator.init"); + this.outName = outName; this.request = request; this.out = out; this.context = context;
--- a/artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/MiddleBedHeightExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -64,13 +64,10 @@ protected List<MiddleBedHeightData[]> data; - - public void init(Document request, OutputStream out, CallContext cc) { - super.init(request, out, cc); + public MiddleBedHeightExporter() { data = new ArrayList<MiddleBedHeightData[]>(); } - @Override protected void addData(Object d) { if (d instanceof CalculationResult) {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/OutGenerator.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/OutGenerator.java Fri Sep 20 16:34:09 2013 +0200 @@ -38,12 +38,13 @@ * Initializes the OutGenerator with meta information which are necessary * for the output generation. * + * @param outName The name of the out to serve. * @param request The incomding request document. * @param out The output stream. * @param context The CallContext that provides further information and * objects used for the output generation. */ - void init(Document request, OutputStream out, CallContext context); + void init(String outName, Document request, OutputStream out, CallContext context); /** * This method is used to tell the OutGenerator which artifact is the master
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ReferenceCurveExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ReferenceCurveExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -91,17 +91,10 @@ protected boolean endAtGauge = false; - - @Override - public void init(Document request, OutputStream out, CallContext context) { - logger.debug("ReferenceCurveExporter.init"); - - super.init(request, out, context); - + public ReferenceCurveExporter() { this.data = new ArrayList<WWQQ[]>(); } - /** * Genereate data in csv format. */
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ReportGenerator.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ReportGenerator.java Fri Sep 20 16:34:09 2013 +0200 @@ -37,6 +37,7 @@ protected Document result; protected OutputStream out; protected CallContext context; + protected String outName; public ReportGenerator() { } @@ -47,8 +48,9 @@ } @Override - public void init(Document request, OutputStream out, CallContext context) { + public void init(String outName, Document request, OutputStream out, CallContext context) { logger.debug("init"); + this.outName = outName; this.out = out; this.context = context; result = null;
--- a/artifacts/src/main/java/org/dive4elements/river/exports/ShapeExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/ShapeExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -30,6 +30,7 @@ private D4EArtifactCollection collection; private String facet; private File dir; + private String outName; @Override public void setup(Element config) { @@ -37,7 +38,8 @@ } @Override - public void init(Document request, OutputStream out, CallContext context) { + public void init(String outName, Document request, OutputStream out, CallContext context) { + this.outName = outName; this.request = request; this.out = out; this.context = context;
--- a/artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/WDifferencesExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -68,16 +68,10 @@ /** The storage that contains all WKms objects for the different facets. */ protected List<WKms[]> data; - - public void init(Document request, OutputStream out, CallContext context) { - logger.debug("WDifferencesExporter.init"); - - super.init(request, out, context); - - this.data = new ArrayList<WKms[]>(); + public WDifferencesExporter() { + data = new ArrayList<WKms[]>(); } - /** * Genereate data in csv format. */
--- a/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/WaterlevelExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -145,15 +145,10 @@ /** The storage that contains official fixings if available.*/ protected List<WQKms> officalFixings; - public void init(Document request, OutputStream out, CallContext context) { - logger.debug("WaterlevelExporter.init"); - - super.init(request, out, context); - + public WaterlevelExporter() { data = new ArrayList<WQKms[]>(); } - @Override public void generate() throws IOException
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/DeltaWtExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/DeltaWtExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -101,10 +101,7 @@ protected List<KMIndex<QWD[]>> referenceEvents; - @Override - public void init(Document request, OutputStream out, CallContext context) { - log.debug("DeltaWtExporter.init"); - super.init(request, out, context); + public DeltaWtExporter() { analysisPeriods = new ArrayList<KMIndex<AnalysisPeriod []>>(); referenceEvents = new ArrayList<KMIndex<QWD[]>>(); }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixChartGenerator.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixChartGenerator.java Fri Sep 20 16:34:09 2013 +0200 @@ -33,8 +33,8 @@ "/art:action/art:attributes/art:currentKm/@art:km"; @Override - public void init(Document request, OutputStream out, CallContext context) { - super.init(request, out, context); + public void init(String outName, Document request, OutputStream out, CallContext context) { + super.init(outName, request, out, context); Double currentKm = getCurrentKmFromRequest(request);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixDeltaWtGenerator.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/FixDeltaWtGenerator.java Fri Sep 20 16:34:09 2013 +0200 @@ -462,8 +462,8 @@ @Override - public void init(Document request, OutputStream out, CallContext context) { - super.init(request, out, context); + public void init(String outName, Document request, OutputStream out, CallContext context) { + super.init(outName, request, out, context); Double currentKm = FixChartGenerator.getCurrentKmFromRequest(request);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/fixings/ParametersExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/fixings/ParametersExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -40,10 +40,7 @@ protected List<Parameters> parametersList; - @Override - public void init(Document request, OutputStream out, CallContext context) { - log.debug("ParametersExporter.init"); - super.init(request, out, context); + public ParametersExporter() { parametersList = new ArrayList<Parameters>(); }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedDifferenceExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -70,10 +70,7 @@ private BedDifferencesResult[] results; - @Override - public void init(Document request, OutputStream out, CallContext context) { - logger.debug("init"); - super.init(request, out, context); + public BedDifferenceExporter() { results = new BedDifferencesResult[0]; }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/BedQualityExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -56,10 +56,7 @@ private BedQualityResult[] results; - @Override - public void init(Document request, OutputStream out, CallContext context) { - logger.debug("BedQualityExporter.init"); - super.init(request, out, context); + public BedQualityExporter() { results = new BedQualityResult[0]; }
--- a/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/minfo/SedimentLoadExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -78,17 +78,9 @@ /** Empty constructor. */ public SedimentLoadExporter() { - } - - /** Trivial init. */ - @Override - public void init(Document request, OutputStream out, CallContext context) { - super.init(request, out, context); - logger.debug("init"); results = new SedimentLoadResult[0]; } - /** Process all stored data and write csv. */ @Override protected void writeCSVData(CSVWriter writer) throws IOException {
--- a/artifacts/src/main/java/org/dive4elements/river/exports/sq/SQOverviewGenerator.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/sq/SQOverviewGenerator.java Fri Sep 20 16:34:09 2013 +0200 @@ -62,6 +62,8 @@ protected List<JFreeChart> charts; + protected String outName; + @Override public void setup(Element config) { logger.debug("SQOverviewGenerator.setup"); @@ -80,6 +82,8 @@ ) { logger.debug("doOut()"); + // TODO: Why not using outName for this. + String name = artifactAndFacet.getData(context).toString(); if(name != null) { logger.debug("name: " + name); @@ -99,7 +103,7 @@ try { Document cAttr = getAttribute(context, collectionAttribute, name); - g.init(request, out, context); + g.init(name, request, out, context); helper.doOut(g, name, name, cAttr, context); JFreeChart chart = g.generateChart(); @@ -116,7 +120,8 @@ } @Override - public void init(Document request, OutputStream out, CallContext context) { + public void init(String outName, Document request, OutputStream out, CallContext context) { + this.outName = outName; this.request = request; this.out = out; this.context = context; @@ -158,6 +163,7 @@ if (i > 1) { vertPos = (size[1] / 3) * (i / 2); } + // TODO: Dispose Graphics object! result.createGraphics().drawImage(img, horPos, vertPos, null); } ImageIO.write(result, "png", out);
--- a/artifacts/src/main/java/org/dive4elements/river/exports/sq/SQRelationExporter.java Fri Sep 20 15:44:39 2013 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/exports/sq/SQRelationExporter.java Fri Sep 20 16:34:09 2013 +0200 @@ -117,13 +117,10 @@ protected List<SQResult []> data; - - public void init(Document request, OutputStream out, CallContext cc) { - super.init(request, out, cc); + public SQRelationExporter() { data = new ArrayList<SQResult []>(); } - @Override protected void addData(Object d) { if (d instanceof CalculationResult) {