gernotbelger@8854: /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde gernotbelger@8854: * Software engineering by Intevation GmbH gernotbelger@8854: * gernotbelger@8854: * This file is Free Software under the GNU AGPL (>=v3) gernotbelger@8854: * and comes with ABSOLUTELY NO WARRANTY! Check out the gernotbelger@8854: * documentation coming with Dive4Elements River for details. gernotbelger@8854: */ gernotbelger@8854: gernotbelger@8854: package org.dive4elements.river.artifacts.sinfo; gernotbelger@8854: gernotbelger@8854: import java.util.ArrayList; gernotbelger@8854: import java.util.Collection; gernotbelger@8854: gernotbelger@8854: import org.apache.log4j.Logger; gernotbelger@8854: import org.dive4elements.artifacts.Artifact; gernotbelger@8854: import org.dive4elements.artifacts.CallContext; gernotbelger@8854: import org.dive4elements.artifacts.CallMeta; gernotbelger@8854: import org.dive4elements.artifacts.common.utils.XMLUtils; gernotbelger@8854: import org.dive4elements.river.artifacts.resources.Resources; gernotbelger@8854: import org.dive4elements.river.artifacts.states.DefaultState; gernotbelger@8854: import org.w3c.dom.Element; gernotbelger@8854: gernotbelger@8854: /** gernotbelger@8854: * @author Gernot Belger gernotbelger@8854: */ gernotbelger@8854: public class CalculationSelectSinfo extends DefaultState { gernotbelger@8854: gernotbelger@8854: private static final long serialVersionUID = 1L; gernotbelger@8854: gernotbelger@8854: /** The log that is used in this class. */ gernotbelger@8854: private static Logger log = Logger.getLogger(CalculationSelectSinfo.class); gernotbelger@8854: gernotbelger@8854: public CalculationSelectSinfo() { gernotbelger@8854: } gernotbelger@8854: gernotbelger@8854: gernotbelger@8854: @Override gernotbelger@8854: protected Element[] createItems( gernotbelger@8854: XMLUtils.ElementCreator cr, gernotbelger@8854: Artifact artifact, gernotbelger@8854: String name, gernotbelger@8854: CallContext context) gernotbelger@8854: { gernotbelger@8854: final CallMeta meta = context.getMeta(); gernotbelger@8854: gernotbelger@8854: final Collection calcs = new ArrayList<>(SinfoCalcMode.values().length); gernotbelger@8854: gernotbelger@8854: for (final SinfoCalcMode calcMode : SinfoCalcMode.values()) { gernotbelger@8854: final String calc = calcMode.name(); gernotbelger@8854: gernotbelger@8854: final String label = Resources.getMsg(meta, calc, calc); gernotbelger@8854: gernotbelger@8854: final Element element = createItem( gernotbelger@8854: cr, new String[] { gernotbelger@8854: label, gernotbelger@8854: calc gernotbelger@8854: }); gernotbelger@8854: calcs.add(element); gernotbelger@8854: } gernotbelger@8854: gernotbelger@8854: return calcs.toArray(new Element[calcs.size()]); gernotbelger@8854: } gernotbelger@8854: gernotbelger@8854: @Override gernotbelger@8854: public boolean validate(Artifact artifact) gernotbelger@8854: throws IllegalArgumentException gernotbelger@8854: { gernotbelger@8854: log.debug("CalculationSelect.validate"); gernotbelger@8854: gernotbelger@8854: final SINFOArtifact sinfo = (SINFOArtifact) artifact; gernotbelger@8854: /* throws an exception if calculation mode is invalid */ gernotbelger@8854: sinfo.getCalculationMode(); gernotbelger@8854: return true; gernotbelger@8854: } gernotbelger@8854: } gernotbelger@8854: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :