teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts; felix@3573: felix@3573: import java.util.ArrayList; felix@3573: import java.util.List; felix@3573: felix@3573: import org.apache.log4j.Logger; felix@3573: felix@3573: import org.w3c.dom.Document; felix@3573: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; felix@3573: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.ArtifactFactory; teichmann@5831: import org.dive4elements.artifacts.CallMeta; teichmann@5831: import org.dive4elements.artifacts.CallContext; felix@3573: teichmann@5831: import org.dive4elements.river.artifacts.model.GaugeFinder; teichmann@5831: import org.dive4elements.river.artifacts.model.GaugeFinderFactory; teichmann@5831: import org.dive4elements.river.artifacts.model.GaugeRange; teichmann@5831: import org.dive4elements.river.artifacts.model.NamedDouble; felix@3573: teichmann@5831: import org.dive4elements.river.artifacts.services.FixingsKMChartService; felix@3573: teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.resources.Resources; felix@3573: felix@3573: felix@3573: /** felix@3573: * Artifact to produce sector markers. felix@3573: */ felix@3573: public class QSectorArtifact teichmann@5867: extends StaticD4EArtifact felix@3573: { felix@3573: /** The logger for this class. */ felix@3573: private static Logger logger = Logger.getLogger(QSectorArtifact.class); felix@3573: felix@3573: /** The name of the artifact. */ felix@3573: public static final String ARTIFACT_NAME = "qsector"; felix@3573: felix@3573: felix@3573: /** felix@3573: * Trivial Constructor. felix@3573: */ felix@3573: public QSectorArtifact() { felix@3573: logger.debug("QSectorArtifact.QSectorArtifact()"); felix@3573: } felix@3573: felix@3573: felix@3573: /** felix@3573: * Gets called from factory, to set things up. felix@3573: */ felix@3573: @Override felix@3573: public void setup( felix@3573: String identifier, felix@3573: ArtifactFactory factory, felix@3573: Object context, felix@3573: CallMeta callMeta, felix@3573: Document data) felix@3573: { felix@3573: logger.debug("QSectorArtifact.setup"); felix@3573: super.setup(identifier, factory, context, callMeta, data); felix@3573: initialize(null, context, callMeta); felix@3573: } felix@3573: felix@3573: felix@3573: /** Return the name of this artifact. */ felix@3573: public String getName() { felix@3573: return ARTIFACT_NAME; felix@3573: } felix@3573: felix@3573: felix@3573: /** Get list of NamedDouble s (QSectors). */ felix@3576: public Object getQSectors(double km, CallContext context) { felix@3573: felix@3573: String river = getDataAsString("river"); felix@3573: List qsectors = new ArrayList(); felix@3573: felix@3573: GaugeFinderFactory ggf = GaugeFinderFactory.getInstance(); felix@3573: GaugeFinder gf = ggf.getGaugeFinder(river); felix@3573: felix@3573: if (gf == null) { felix@3573: logger.warn("No gauge finder found for river '" + river + "'"); felix@3573: return null; felix@3573: } felix@3573: felix@3573: GaugeRange gr = gf.find(km); felix@3573: if (gr == null) { felix@3573: logger.debug("No gauge range found for km " felix@3573: + km + " on river " + river + "."); felix@3573: return null; felix@3573: } felix@3573: felix@3573: if (logger.isDebugEnabled()) { felix@3573: logger.debug(gr); felix@3573: } felix@3573: felix@3573: for (int i = 0; i < FixingsKMChartService.I18N_Q_SECTOR_BOARDERS.length; ++i) { felix@3573: String key = FixingsKMChartService.I18N_Q_SECTOR_BOARDERS[i]; felix@3573: String def = FixingsKMChartService.DEFAULT_Q_SECTOR_BORDERS[i]; felix@3576: String label = Resources.getMsg(context.getMeta(), key, def); felix@3573: felix@3573: qsectors.add(new NamedDouble(label, gr.getSectorBorder(i))); felix@3573: } felix@3573: felix@3573: return qsectors; felix@3573: } felix@3573: felix@3573: felix@3573: /** Setup state and facet. */ felix@3573: @Override felix@3573: protected void initialize(Artifact artifact, Object context, CallMeta meta) { felix@3573: logger.debug("QSectorArtifact.initialize"); felix@3573: List fs = new ArrayList(); felix@3573: teichmann@5867: D4EArtifact flys = (D4EArtifact) artifact; felix@3573: importData(flys, "river"); felix@3573: felix@3573: DefaultState state = (DefaultState) getCurrentState(context); felix@3573: state.computeInit(this, hash(), context, meta, fs); felix@3573: if (!fs.isEmpty()) { felix@3573: logger.debug("Facets to add in QSectorArtifact.initialize ."); bjoern@4497: addFacets(getCurrentStateId(), fs); felix@3573: } felix@3573: else { felix@3573: logger.debug("No facets to add in QSectorArtifact.initialize (" felix@3573: + state.getID() + ")."); felix@3573: } felix@3573: } felix@3573: } felix@3573: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :