view flys-artifacts/src/main/java/de/intevation/flys/artifacts/GaugeDischargeCurveArtifact.java @ 3981:6bcc50e2cc7d

More code for S(Q) relation.
author Sascha L. Teichmann <teichmann@intevation.de>
date Fri, 28 Sep 2012 16:41:08 +0200
parents 4e1b3b4ef132
children a4930c43b806
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.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.states.StaticState;
import de.intevation.flys.artifacts.StaticFLYSArtifact;
import de.intevation.flys.artifacts.model.GaugeDischargeCurveFacet;

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/@name";
    public static final String XPATH_GAUGE = "/art:action/art:gauge/@reference";
    public static final String NAME = "gaugedischargecurve";
    public static final String STATIC_STATE_NAME = "state.gaugedischargecurve.static";

    /**
     * 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("GaugeDischargeCurveState.setup" + XMLUtils.toString(data));
        }
        String gaugeref = XMLUtils.xpathString(data, XPATH_GAUGE,
                ArtifactNamespaceContext.INSTANCE);
        String rivername = XMLUtils.xpathString(data, XPATH_RIVER,
                ArtifactNamespaceContext.INSTANCE);

        addStringData("river", rivername);
        addStringData("reference_gauge", gaugeref);

        Gauge gauge = FLYSUtils.getReferenceGauge(this);

        Facet gfacet = new GaugeDischargeCurveFacet(rivername, gauge);

        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);
        setStaticState(state);
    }
}

http://dive4elements.wald.intevation.org