Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/CalculationSelect.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/CalculationSelect.java@eb5564662e19 |
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 CalculationSelect extends DefaultState { | |
22 | |
23 /** The logger that is used in this class. */ | |
24 private static Logger logger = Logger.getLogger(CalculationSelect.class); | |
25 | |
26 /** Name of data item. */ | |
27 public static final String FIELD_MODE = "calculation_mode"; | |
28 | |
29 /** Constant value for the reference line calculation. */ | |
30 public static final String CALCULATION_SURFACE_CURVE = | |
31 "calc.surface.curve"; | |
32 | |
33 /** Constant value for the differences calculation. */ | |
34 public static final String CALCULATION_DURATION_CURVE = | |
35 "calc.duration.curve"; | |
36 | |
37 /** Constant value for the flood map calculation. */ | |
38 public static final String CALCULATION_FLOOD_MAP = | |
39 "calc.flood.map"; | |
40 | |
41 /** Constant value for the profile calculation. */ | |
42 public static final String CALCULATION_DISCHARGE_LONGITUDINAL_CURVE = | |
43 "calc.discharge.longitudinal.section"; | |
44 | |
45 /** Constant value for the state discharge curve calculation. */ | |
46 public static final String CALCULATION_DISCHARGE_CURVE = | |
47 "calc.discharge.curve"; | |
48 | |
49 /** Constant value for the state w differences calculation. */ | |
50 public static final String CALCULATION_W_DIFFERENCES = | |
51 "calc.w.differences"; | |
52 | |
53 /** Constant value for the state reference curve calculation. */ | |
54 public static final String CALCULATION_REFERENCE_CURVE = | |
55 "calc.reference.curve"; | |
56 | |
57 /** Constant value for the historical discharge curve calculation. */ | |
58 public static final String CALCULATION_HISTORICAL_DISCHARGE_CURVE = | |
59 "calc.historical.discharge.curve"; | |
60 | |
61 /** Constant value for the extreme W curve calculation. */ | |
62 public static final String CALCULATION_EXTREME = | |
63 "calc.extreme.curve"; | |
64 | |
65 /** An array that holds all available calculation modes. */ | |
66 public static final String[] CALCULATIONS = { | |
67 CALCULATION_SURFACE_CURVE, | |
68 CALCULATION_FLOOD_MAP, | |
69 CALCULATION_DISCHARGE_CURVE, | |
70 CALCULATION_HISTORICAL_DISCHARGE_CURVE, | |
71 CALCULATION_DURATION_CURVE, | |
72 CALCULATION_DISCHARGE_LONGITUDINAL_CURVE, | |
73 CALCULATION_W_DIFFERENCES, | |
74 CALCULATION_REFERENCE_CURVE, | |
75 CALCULATION_EXTREME}; | |
76 | |
77 | |
78 /** Error message that is thrown if no mode has been chosen. */ | |
79 public static final String ERROR_NO_CALCULATION_MODE = | |
80 "error_feed_no_calculation_mode"; | |
81 | |
82 /** Error message that is thrown if an invalid calculation mode has been | |
83 * chosen. */ | |
84 public static final String ERROR_INVALID_CALCULATION_MODE = | |
85 "error_feed_invalid_calculation_mode"; | |
86 | |
87 | |
88 public CalculationSelect() { | |
89 } | |
90 | |
91 | |
92 /** Create choices (i18ned). */ | |
93 @Override | |
94 protected Element[] createItems( | |
95 XMLUtils.ElementCreator cr, | |
96 Artifact artifact, | |
97 String name, | |
98 CallContext context) | |
99 { | |
100 CallMeta meta = context.getMeta(); | |
101 Element[] calcs = new Element[CALCULATIONS.length]; | |
102 | |
103 for (int i = 0; i < CALCULATIONS.length; ++i) { | |
104 String calc = CALCULATIONS[i]; | |
105 calcs[i] = createItem( | |
106 cr, new String[] { | |
107 Resources.getMsg(meta, calc, calc), | |
108 calc | |
109 }); | |
110 } | |
111 | |
112 return calcs; | |
113 } | |
114 | |
115 | |
116 /** Validate the chosen calculation. */ | |
117 @Override | |
118 public boolean validate(Artifact artifact) | |
119 throws IllegalArgumentException | |
120 { | |
121 logger.debug("CalculationSelect.validate"); | |
122 FLYSArtifact flys = (FLYSArtifact) artifact; | |
123 | |
124 StateData data = getData(flys, FIELD_MODE); | |
125 String calc = (data != null) ? (String) data.getValue() : null; | |
126 | |
127 if (calc == null) { | |
128 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); | |
129 } | |
130 | |
131 calc = calc.trim().toLowerCase(); | |
132 | |
133 for (String mode: CALCULATIONS) { | |
134 if (mode.equals(calc)) { | |
135 return true; | |
136 } | |
137 } | |
138 | |
139 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE); | |
140 } | |
141 } | |
142 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |