view flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java @ 4206:6b0683f5c530

Documentation added, cosmetics.
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Mon, 22 Oct 2012 07:34:45 +0200
parents 8d3e8cb54e4c
children 79878efbdf07
line wrap: on
line source
package de.intevation.flys.artifacts;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

import org.w3c.dom.Document;

import de.intevation.artifactdatabase.state.DefaultOutput;
import de.intevation.artifactdatabase.state.Facet;
import de.intevation.artifactdatabase.data.DefaultStateData;

import de.intevation.artifacts.ArtifactFactory;
import de.intevation.artifacts.CallMeta;

import de.intevation.artifacts.common.ArtifactNamespaceContext;
import de.intevation.artifacts.common.utils.XMLUtils;

import de.intevation.flys.artifacts.model.GaugeDischargeCurveFacet;
import de.intevation.flys.artifacts.resources.Resources;
import de.intevation.flys.artifacts.states.StaticState;

import de.intevation.flys.model.Gauge;
import de.intevation.flys.utils.FLYSUtils;


/**
 * Artifact to calculate a discharge curve from a gauge overview info
 *
 * @author <a href="mailto:bjoern.ricks@intevation.de">Björn Ricks</a>
 */
public class GaugeDischargeCurveArtifact
extends      AbstractStaticStateArtifact
{

    private static final Logger logger =
        Logger.getLogger(GaugeDischargeCurveArtifact.class);

    public static final String XPATH_RIVER = "/art:action/art:river/@art:name";
    public static final String XPATH_GAUGE = "/art:action/art:gauge/@art:reference";
    public static final String NAME = "gaugedischargecurve";
    public static final String STATIC_STATE_NAME = "state.gaugedischargecurve.static";
    public static final String UIPROVIDER = "gauge_discharge_curve";

    /**
     * Setup initializes the data by extracting the river and gauge from
     * the XML Document.
     */
    @Override
    public void setup(
        String          identifier,
        ArtifactFactory factory,
        Object          context,
        CallMeta        callmeta,
        Document        data)
    {
        logger.debug("GaugeDischargeCurveArtifact.setup");

        if (logger.isDebugEnabled()) {
            logger.debug("GaugeDischargeCurveArtifact.setup" + XMLUtils.toString(data));
        }
        String gaugeref = XMLUtils.xpathString(data, XPATH_GAUGE,
                ArtifactNamespaceContext.INSTANCE);
        String rivername = XMLUtils.xpathString(data, XPATH_RIVER,
                ArtifactNamespaceContext.INSTANCE);

        addData("river", new DefaultStateData("river",
                    Resources.getMsg(callmeta,
                        "facet.gauge_discharge_curve.river",
                        "Name of the river"),
                    "String", rivername));
        addData("reference_gauge", new DefaultStateData("reference_gauge",
                    Resources.getMsg(callmeta,
                        "facet.gauge_discharge_curve.reference_gauge",
                        "Gauge official number"),
                    "Double", gaugeref));

        Gauge gauge = FLYSUtils.getReferenceGauge(this);
        String gaugename = "";
        if (gauge != null) {
            gaugename = gauge.getName();
        }

        addData("gauge_name", new DefaultStateData("gauge_name",
                    Resources.getMsg(callmeta,
                        "facet.gauge_discharge_curve.gauge_name",
                        "Name of the gauge"),
                    "String", gaugename));

        String description = Resources.format(callmeta,
                "facet.gauge_discharge_curve.description",
                "Discharge curve on gauge",
                rivername,
                gaugename);

        Facet gfacet = new GaugeDischargeCurveFacet(description);

        List<Facet> fs = new ArrayList<Facet>(1);
        fs.add(gfacet);

        addFacets(STATIC_STATE_NAME, fs);

        super.setup(identifier, factory, context, callmeta, data);
    }

    @Override
    public String getName() {
        return NAME;
    }

    @Override
    protected void initStaticState() {
        StaticState state = new StaticState(STATIC_STATE_NAME);
        List<Facet> fs = facets.get(STATIC_STATE_NAME);
        DefaultOutput output = new DefaultOutput(
            "discharge_curve",
            "output.discharge_curve", "image/png",
            fs,
            "chart");

        state.addOutput(output);
        state.setUIProvider(UIPROVIDER);
        setStaticState(state);
    }
}

http://dive4elements.wald.intevation.org