Mercurial > dive4elements > river
view flys-artifacts/src/main/java/de/intevation/flys/artifacts/HYKArtifact.java @ 2135:77cdc344ef77
'New Chart' for discharge longitudinal section curve.
flys-artifacts/trunk@3711 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Raimund Renkert <raimund.renkert@intevation.de> |
---|---|
date | Wed, 18 Jan 2012 16:21:30 +0000 |
parents | e50a928187cd |
children | 923256599afe |
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.artifacts.Artifact; 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.DefaultState; import de.intevation.artifactdatabase.state.Facet; /** * Artifact describing the area between two WKms. */ public class HYKArtifact extends StaticFLYSArtifact { /** Access ids of doc. */ public static final String XPATH_IDS = "/art:action/art:ids/@value"; /** Name of Artifact. */ public static final String HYK_ARTIFACT_NAME = "hyk"; /** Name of data item keeping the km of cs master. */ public static final String HYK_KM = "hyk_artifact.data.km"; /** Own logger. */ private static final Logger logger = Logger.getLogger(HYKArtifact.class); /** Return given name. */ @Override public String getName() { return HYK_ARTIFACT_NAME; } /** Store ids, do super.setup. */ @Override public void setup( String identifier, ArtifactFactory factory, Object context, CallMeta callMeta, Document data) { logger.info("HYKArtifact.setup"); super.setup(identifier, factory, context, callMeta, data); String ids = XMLUtils.xpathString( data, XPATH_IDS, ArtifactNamespaceContext.INSTANCE); addStringData("ids", ids); } /** Set km as Data. */ public void setKm(double km) { addStringData(HYK_KM, Double.toString(km)); } /** * Get a DataItem casted to double (0 if fails). * TODO move to FlysArtifact. */ public double getDataAsDouble(String dataName) { String val = getDataAsString(dataName); if (val == null) { logger.warn("Data not available."); return 0d; } try { return Double.valueOf(val); } catch (NumberFormatException e) { logger.warn("Could not get data " + dataName + " as double", e); return 0; } } /** Get km from state data. */ public double getKm() { return getDataAsDouble(HYK_KM); } /** Do not copy data from daddyfact. */ @Override protected void initialize( Artifact artifact, Object context, CallMeta callMeta) { logger.debug("HYKArtifact.initialize"); WINFOArtifact winfo = (WINFOArtifact) artifact; importData(winfo, "river"); List<Facet> fs = new ArrayList<Facet>(); DefaultState state = (DefaultState) getCurrentState(context); state.computeInit(this, hash(), context, callMeta, fs); if (!fs.isEmpty()) { logger.debug("Facets to add in HYKArtifact.initialize ."); facets.put(getCurrentStateId(), fs); } else { logger.debug("No facets to add in HYKArtifact.initialize (" + state.getID() + ")."); } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :