ingo@127: package de.intevation.flys.artifacts.states; ingo@127: ingo@127: import org.apache.log4j.Logger; ingo@127: ingo@127: import org.w3c.dom.Element; ingo@127: ingo@313: import de.intevation.artifacts.Artifact; ingo@127: import de.intevation.artifacts.CallContext; ingo@141: import de.intevation.artifacts.CallMeta; ingo@127: ingo@127: import de.intevation.artifacts.common.utils.XMLUtils; ingo@127: ingo@323: import de.intevation.artifactdatabase.data.StateData; ingo@127: ingo@624: import de.intevation.flys.artifacts.FLYSArtifact; ingo@141: import de.intevation.flys.artifacts.resources.Resources; ingo@141: ingo@127: /** ingo@127: * @author Ingo Weinzierl ingo@127: */ ingo@127: public class CalculationSelect extends DefaultState { ingo@127: felix@1148: /** The logger that is used in this class. */ ingo@127: private static Logger logger = Logger.getLogger(CalculationSelect.class); ingo@127: ingo@127: ingo@624: public static final String FIELD_MODE = "calculation_mode"; ingo@624: felix@1148: /** Constant value for the reference line calculation. */ ingo@157: public static final String CALCULATION_SURFACE_CURVE = ingo@157: "calc.surface.curve"; ingo@141: felix@1148: /** Constant value for the differences calculation. */ ingo@157: public static final String CALCULATION_DURATION_CURVE = ingo@157: "calc.duration.curve"; ingo@141: felix@1148: /** Constant value for the flood map calculation. */ ingo@141: public static final String CALCULATION_FLOOD_MAP = ingo@141: "calc.flood.map"; ingo@141: felix@1148: /** Constant value for the profile calculation. */ ingo@157: public static final String CALCULATION_DISCHARGE_LONGITUDINAL_CURVE = ingo@157: "calc.discharge.longitudinal.section"; ingo@141: felix@1148: /** Constant value for the state discharge curve calculation. */ ingo@157: public static final String CALCULATION_DISCHARGE_CURVE = ingo@157: "calc.discharge.curve"; ingo@141: felix@1152: /** Constant value for the state w differences calculation. */ felix@1152: public static final String CALCULATION_W_DIFFERENCES = felix@1152: "calc.w.differences"; felix@1152: sascha@1960: /** Constant value for the state reference curve calculation. */ sascha@1960: public static final String CALCULATION_REFERENCE_CURVE = sascha@1960: "calc.reference.curve"; sascha@1960: ingo@2118: /** Constant value for the historical discharge curve calculation. */ ingo@2118: public static final String CALCULATION_HISTORICAL_DISCHARGE_CURVE = ingo@2118: "calc.historical.discharge.curve"; ingo@2118: felix@1152: /** An array that holds all available calculation modes. */ ingo@141: public static final String[] CALCULATIONS = { ingo@157: CALCULATION_SURFACE_CURVE, ingo@141: CALCULATION_FLOOD_MAP, ingo@157: CALCULATION_DISCHARGE_CURVE, ingo@2118: CALCULATION_HISTORICAL_DISCHARGE_CURVE, ingo@157: CALCULATION_DURATION_CURVE, felix@1152: CALCULATION_DISCHARGE_LONGITUDINAL_CURVE, sascha@1960: CALCULATION_W_DIFFERENCES, sascha@1960: CALCULATION_REFERENCE_CURVE }; ingo@141: ingo@141: felix@1148: /** Error message that is thrown if no mode has been chosen. */ ingo@323: public static final String ERROR_NO_CALCULATION_MODE = ingo@323: "error_feed_no_calculation_mode"; ingo@323: ingo@323: /** Error message that is thrown if an invalid calculation mode has been felix@1148: * chosen. */ ingo@323: public static final String ERROR_INVALID_CALCULATION_MODE = ingo@323: "error_feed_invalid_calculation_mode"; ingo@323: sascha@742: sascha@660: public CalculationSelect() { sascha@660: } ingo@323: sascha@660: sascha@660: @Override ingo@127: protected Element[] createItems( ingo@127: XMLUtils.ElementCreator cr, ingo@313: Artifact artifact, ingo@127: String name, ingo@127: CallContext context) ingo@127: { ingo@141: CallMeta meta = context.getMeta(); ingo@141: Element[] calcs = new Element[CALCULATIONS.length]; ingo@127: ingo@141: int i = 0; ingo@141: ingo@141: for (String calc: CALCULATIONS) { ingo@141: calcs[i++] = createItem( ingo@141: cr, new String[] { ingo@141: Resources.getMsg(meta, calc, calc), ingo@141: calc ingo@141: }); ingo@141: } ingo@141: ingo@141: return calcs; ingo@127: } ingo@127: ingo@127: ingo@323: @Override sascha@1050: public boolean validate(Artifact artifact) ingo@323: throws IllegalArgumentException ingo@323: { ingo@323: logger.debug("CalculationSelect.validate"); ingo@624: FLYSArtifact flys = (FLYSArtifact) artifact; ingo@323: ingo@624: StateData data = getData(flys, FIELD_MODE); felix@1148: String calc = (data != null) ? (String) data.getValue() : null; ingo@323: ingo@323: if (calc == null) { ingo@323: throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); ingo@323: } ingo@323: ingo@323: calc = calc.trim().toLowerCase(); ingo@323: ingo@323: for (String mode: CALCULATIONS) { ingo@323: if (mode.equals(calc)) { ingo@323: return true; ingo@323: } ingo@323: } ingo@323: ingo@323: throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE); ingo@323: } ingo@127: } ingo@127: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :