comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/CalculationSelectMinfo.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelectMinfo.java@edaa2297aea3
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.states;
2
3 import org.apache.log4j.Logger;
4
5 import org.w3c.dom.Element;
6
7 import org.dive4elements.artifacts.Artifact;
8 import org.dive4elements.artifacts.CallContext;
9 import org.dive4elements.artifacts.CallMeta;
10
11 import org.dive4elements.artifacts.common.utils.XMLUtils;
12
13 import org.dive4elements.artifactdatabase.data.StateData;
14
15 import org.dive4elements.river.artifacts.FLYSArtifact;
16 import org.dive4elements.river.artifacts.resources.Resources;
17
18 /**
19 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
20 */
21 public class CalculationSelectMinfo extends DefaultState {
22
23 /** The logger that is used in this class. */
24 private static Logger logger = Logger.getLogger(CalculationSelectMinfo.class);
25
26
27 public static final String FIELD_MODE = "calculation_mode";
28
29 public static final String CALC_BED_MIDDLE = "calc.bed.middle";
30 public static final String CALC_BED_DIFF = "calc.bed.diff";
31 public static final String CALC_BED_QUALITY = "calc.bed.quality";
32 public static final String CALC_SEDIMENT_LOAD = "calc.sediment.load";
33 public static final String CALC_FLOW_VELOCITY = "calc.flow.velocity";
34 public static final String CALC_SQ_RELATION = "calc.sq.relation";
35
36 /** An array that holds all available calculation modes. */
37 public static final String[] CALCULATIONS = {
38 CALC_BED_MIDDLE,
39 CALC_BED_DIFF,
40 CALC_BED_QUALITY,
41 CALC_SEDIMENT_LOAD,
42 CALC_FLOW_VELOCITY,
43 CALC_SQ_RELATION
44 };
45
46
47 /** Error message that is thrown if no mode has been chosen. */
48 public static final String ERROR_NO_CALCULATION_MODE =
49 "error_feed_no_calculation_mode";
50
51 /** Error message that is thrown if an invalid calculation mode has been
52 * chosen. */
53 public static final String ERROR_INVALID_CALCULATION_MODE =
54 "error_feed_invalid_calculation_mode";
55
56
57 public CalculationSelectMinfo() {
58 }
59
60
61 @Override
62 protected Element[] createItems(
63 XMLUtils.ElementCreator cr,
64 Artifact artifact,
65 String name,
66 CallContext context)
67 {
68 CallMeta meta = context.getMeta();
69 Element[] calcs = new Element[CALCULATIONS.length];
70
71 for (int i = 0; i < CALCULATIONS.length; ++i) {
72 String calc = CALCULATIONS[i];
73 calcs[i] = createItem(
74 cr, new String[] {
75 Resources.getMsg(meta, calc, calc),
76 calc
77 });
78 }
79
80 return calcs;
81 }
82
83
84 @Override
85 public boolean validate(Artifact artifact)
86 throws IllegalArgumentException
87 {
88 logger.debug("CalculationSelect.validate");
89 FLYSArtifact flys = (FLYSArtifact) artifact;
90
91 StateData data = getData(flys, FIELD_MODE);
92 String calc = (data != null) ? (String) data.getValue() : null;
93
94 if (calc == null) {
95 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE);
96 }
97
98 calc = calc.trim().toLowerCase();
99
100 for (String mode: CALCULATIONS) {
101 if (mode.equals(calc)) {
102 return true;
103 }
104 }
105
106 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE);
107 }
108 }
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org