Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java @ 322:448d0dc64357
The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
flys-artifacts/trunk@1716 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 18 Apr 2011 12:36:08 +0000 |
parents | a8e7c351bdf1 |
children | ed3325a0232a |
comparison
equal
deleted
inserted
replaced
321:9581b88f2920 | 322:448d0dc64357 |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | |
3 import java.util.Map; | |
2 | 4 |
3 import org.apache.log4j.Logger; | 5 import org.apache.log4j.Logger; |
4 | 6 |
5 import org.w3c.dom.Element; | 7 import org.w3c.dom.Element; |
6 | 8 |
21 import de.intevation.flys.artifacts.resources.Resources; | 23 import de.intevation.flys.artifacts.resources.Resources; |
22 | 24 |
23 /** | 25 /** |
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
25 */ | 27 */ |
26 public class WQSelect extends DefaultState { | 28 public class WQSelect extends RangeState { |
27 | 29 |
28 /** The logger used in this class.*/ | 30 /** The logger used in this class.*/ |
29 private static Logger logger = Logger.getLogger(WQSelect.class); | 31 private static Logger logger = Logger.getLogger(WQSelect.class); |
30 | 32 |
31 | 33 |
32 /** The default step width for Qs.*/ | 34 /** The default step width for Qs.*/ |
33 public static final String DEFAULT_STEP_Q = "50"; | 35 public static final String DEFAULT_STEP_Q = "50"; |
34 | 36 |
35 /** The default step width for Qs.*/ | 37 /** The default step width for Qs.*/ |
36 public static final String DEFAULT_STEP_W = "30"; | 38 public static final String DEFAULT_STEP_W = "30"; |
39 | |
40 /** The name of the 'mode' field. */ | |
41 public static final String WQ_MODE = "wq_mode"; | |
42 | |
43 /** The name of the 'from' field. */ | |
44 public static final String WQ_FROM = "wq_from"; | |
45 | |
46 /** The name of the 'to' field. */ | |
47 public static final String WQ_TO = "wq_to"; | |
48 | |
49 /** The name of the 'step' field. */ | |
50 public static final String WQ_STEP = "wq_step"; | |
37 | 51 |
38 /** | 52 /** |
39 * The default constructor that initializes an empty State object. | 53 * The default constructor that initializes an empty State object. |
40 */ | 54 */ |
41 public WQSelect() { | 55 public WQSelect() { |
170 double minQ = minmaxQ != null ? minmaxQ[0] : Double.MIN_VALUE; | 184 double minQ = minmaxQ != null ? minmaxQ[0] : Double.MIN_VALUE; |
171 double maxQ = minmaxQ != null ? minmaxQ[1] : Double.MAX_VALUE; | 185 double maxQ = minmaxQ != null ? minmaxQ[1] : Double.MAX_VALUE; |
172 | 186 |
173 return new double[] { minQ, maxQ }; | 187 return new double[] { minQ, maxQ }; |
174 } | 188 } |
189 | |
190 | |
191 @Override | |
192 public boolean validate(Artifact artifact, CallContext context) | |
193 throws IllegalArgumentException | |
194 { | |
195 logger.debug("WQSelect.validate"); | |
196 | |
197 Map<String, StateData> data = getData(); | |
198 | |
199 String mode = (String) data.get(WQ_MODE).getValue(); | |
200 logger.debug("WQ Mode: " + mode); | |
201 | |
202 String fromStr = (String) data.get(WQ_FROM).getValue(); | |
203 String toStr = (String) data.get(WQ_TO).getValue(); | |
204 String stepStr = (String) data.get(WQ_STEP).getValue(); | |
205 | |
206 double from = Double.parseDouble(fromStr); | |
207 double to = Double.parseDouble(toStr); | |
208 double step = Double.parseDouble(stepStr); | |
209 | |
210 try { | |
211 if (mode != null && mode.trim().toLowerCase().equals("w")) { | |
212 return validateW(artifact, context, from, to, step); | |
213 } | |
214 else if (mode != null && mode.trim().toLowerCase().equals("q")) { | |
215 return validateQ(artifact, context, from, to, step); | |
216 } | |
217 else { | |
218 throw new IllegalArgumentException("error_feed_invalid_wq_mode"); | |
219 } | |
220 } | |
221 catch (NumberFormatException nfe) { | |
222 throw new IllegalArgumentException("error_feed_number_format"); | |
223 } | |
224 } | |
225 | |
226 | |
227 /** | |
228 * Validates the inserted W values. | |
229 * | |
230 * @param artifact The owner artifact. | |
231 * @param context The CallContext | |
232 * @param from The lower value of the W range. | |
233 * @param to The upper value of the W range. | |
234 * @param step The step width. | |
235 * | |
236 * @return true, if everything was fine, otherwise an exception is thrown. | |
237 */ | |
238 protected boolean validateW( | |
239 Artifact artifact, | |
240 CallContext context, | |
241 double from, | |
242 double to, | |
243 double step) | |
244 throws IllegalArgumentException | |
245 { | |
246 logger.debug("WQSelect.validateW"); | |
247 | |
248 double[] minmaxW = determineMinMaxW(artifact); | |
249 | |
250 return validateRange(minmaxW[0], minmaxW[1], from, to, step); | |
251 } | |
252 | |
253 | |
254 /** | |
255 * Validates the inserted Q values. | |
256 * | |
257 * @param artifact The owner artifact. | |
258 * @param context The CallContext | |
259 * @param from The lower value of the Q range. | |
260 * @param to The upper value of the Q range. | |
261 * @param step The step width. | |
262 * | |
263 * @return true, if everything was fine, otherwise an exception is thrown. | |
264 */ | |
265 protected boolean validateQ( | |
266 Artifact artifact, | |
267 CallContext context, | |
268 double from, | |
269 double to, | |
270 double step) | |
271 throws IllegalArgumentException | |
272 { | |
273 logger.debug("WQSelect.validateQ"); | |
274 | |
275 double[] minmaxQ = determineMinMaxQ(artifact); | |
276 | |
277 return validateRange(minmaxQ[0], minmaxQ[1], from, to, step); | |
278 } | |
175 } | 279 } |
176 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 280 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |