bjoern@3936: package de.intevation.flys.artifacts;
bjoern@3936:
bjoern@3936: import java.util.ArrayList;
bjoern@3936: import java.util.List;
bjoern@3936:
bjoern@3936: import org.apache.log4j.Logger;
bjoern@3936:
bjoern@3936: import org.w3c.dom.Document;
bjoern@3936:
bjoern@3936: import de.intevation.artifactdatabase.state.DefaultOutput;
bjoern@3936: import de.intevation.artifactdatabase.state.Facet;
bjoern@3936:
bjoern@3936: import de.intevation.artifacts.ArtifactFactory;
bjoern@3936: import de.intevation.artifacts.CallMeta;
bjoern@3936:
bjoern@3936: import de.intevation.artifacts.common.ArtifactNamespaceContext;
bjoern@3936: import de.intevation.artifacts.common.utils.XMLUtils;
bjoern@3936:
bjoern@3936: import de.intevation.flys.artifacts.states.StaticState;
bjoern@3936: import de.intevation.flys.artifacts.model.GaugeDischargeCurveFacet;
bjoern@3936:
bjoern@3936:
bjoern@3936: /**
bjoern@3936: * Artifact to calculate a discharge curve from a gauge overview info
bjoern@3936: *
bjoern@3936: * @author Björn Ricks
bjoern@3936: */
bjoern@3936: public class GaugeDischargeCurveArtifact
bjoern@3936: extends AbstractStaticStateArtifact
bjoern@3936: {
bjoern@3936:
bjoern@3936: private static final Logger logger =
bjoern@3936: Logger.getLogger(GaugeDischargeCurveArtifact.class);
bjoern@3936:
bjoern@3936: public static final String XPATH_RIVER = "/art:action/art:river/@name";
bjoern@3936: public static final String XPATH_GAUGE = "/art:action/art:gauge/@reference";
bjoern@3936: public static final String NAME = "gaugedischargecurve";
bjoern@3936: public static final String STATIC_STATE_NAME = "state.gaugedischargecurve.static";
bjoern@3936:
bjoern@3936: /**
bjoern@3936: * Setup initializes the data by extracting the river and gauge from
bjoern@3936: * the XML Document.
bjoern@3936: */
bjoern@3936: @Override
bjoern@3936: public void setup(
bjoern@3936: String identifier,
bjoern@3936: ArtifactFactory factory,
bjoern@3936: Object context,
bjoern@3936: CallMeta callmeta,
bjoern@3936: Document data)
bjoern@3936: {
bjoern@3936: logger.debug("GaugeDischargeCurveArtifact.setup");
bjoern@3936:
bjoern@3936: if (logger.isDebugEnabled()) {
bjoern@3936: logger.debug("GaugeDischargeCurveState.setup" + XMLUtils.toString(data));
bjoern@3936: }
bjoern@3936: String gaugeref = XMLUtils.xpathString(data, XPATH_GAUGE,
bjoern@3936: ArtifactNamespaceContext.INSTANCE);
bjoern@3936: String rivername = XMLUtils.xpathString(data, XPATH_RIVER,
bjoern@3936: ArtifactNamespaceContext.INSTANCE);
bjoern@3936:
bjoern@3936: addStringData("river", rivername);
bjoern@3936: addStringData("reference_gauge", gaugeref);
bjoern@3936:
teichmann@3986: Facet gfacet = new GaugeDischargeCurveFacet();
bjoern@3936:
bjoern@3936: List fs = new ArrayList(1);
bjoern@3936: fs.add(gfacet);
bjoern@3936:
bjoern@3936: addFacets(STATIC_STATE_NAME, fs);
bjoern@3936:
bjoern@3936: super.setup(identifier, factory, context, callmeta, data);
bjoern@3936: }
bjoern@3936:
bjoern@3936: @Override
bjoern@3936: public String getName() {
bjoern@3936: return NAME;
bjoern@3936: }
bjoern@3936:
bjoern@3936: @Override
bjoern@3936: protected void initStaticState() {
bjoern@3936: StaticState state = new StaticState(STATIC_STATE_NAME);
bjoern@3936: List fs = facets.get(STATIC_STATE_NAME);
bjoern@3936: DefaultOutput output = new DefaultOutput(
bjoern@3936: "discharge_curve",
bjoern@3936: "output.discharge_curve", "image/png",
bjoern@3936: fs,
bjoern@3936: "chart");
bjoern@3936:
bjoern@3936: state.addOutput(output);
bjoern@3936: setStaticState(state);
bjoern@3936: }
bjoern@3936: }