Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java @ 3814:8083f6384023
merged flys-artifacts/pre2.6-2012-01-04
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:56 +0200 |
parents | be06dbc2ed1d |
children | 4d57d456e261 |
comparison
equal
deleted
inserted
replaced
1491:2a00f4849738 | 3814:8083f6384023 |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 import org.w3c.dom.Element; | |
6 | |
7 import de.intevation.artifacts.Artifact; | |
8 import de.intevation.artifacts.CallContext; | |
9 import de.intevation.artifacts.CallMeta; | |
10 | |
11 import de.intevation.artifacts.common.utils.XMLUtils; | |
12 | |
13 import de.intevation.artifactdatabase.data.StateData; | |
14 | |
15 import de.intevation.flys.artifacts.FLYSArtifact; | |
16 import de.intevation.flys.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 | |
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 /** An array that holds all available calculation modes. */ | |
58 public static final String[] CALCULATIONS = { | |
59 CALCULATION_SURFACE_CURVE, | |
60 CALCULATION_FLOOD_MAP, | |
61 CALCULATION_DISCHARGE_CURVE, | |
62 CALCULATION_DURATION_CURVE, | |
63 CALCULATION_DISCHARGE_LONGITUDINAL_CURVE, | |
64 CALCULATION_W_DIFFERENCES, | |
65 CALCULATION_REFERENCE_CURVE }; | |
66 | |
67 | |
68 /** Error message that is thrown if no mode has been chosen. */ | |
69 public static final String ERROR_NO_CALCULATION_MODE = | |
70 "error_feed_no_calculation_mode"; | |
71 | |
72 /** Error message that is thrown if an invalid calculation mode has been | |
73 * chosen. */ | |
74 public static final String ERROR_INVALID_CALCULATION_MODE = | |
75 "error_feed_invalid_calculation_mode"; | |
76 | |
77 | |
78 public CalculationSelect() { | |
79 } | |
80 | |
81 | |
82 @Override | |
83 protected Element[] createItems( | |
84 XMLUtils.ElementCreator cr, | |
85 Artifact artifact, | |
86 String name, | |
87 CallContext context) | |
88 { | |
89 CallMeta meta = context.getMeta(); | |
90 Element[] calcs = new Element[CALCULATIONS.length]; | |
91 | |
92 int i = 0; | |
93 | |
94 for (String calc: CALCULATIONS) { | |
95 calcs[i++] = createItem( | |
96 cr, new String[] { | |
97 Resources.getMsg(meta, calc, calc), | |
98 calc | |
99 }); | |
100 } | |
101 | |
102 return calcs; | |
103 } | |
104 | |
105 | |
106 @Override | |
107 public boolean validate(Artifact artifact) | |
108 throws IllegalArgumentException | |
109 { | |
110 logger.debug("CalculationSelect.validate"); | |
111 FLYSArtifact flys = (FLYSArtifact) artifact; | |
112 | |
113 StateData data = getData(flys, FIELD_MODE); | |
114 String calc = (data != null) ? (String) data.getValue() : null; | |
115 | |
116 if (calc == null) { | |
117 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE); | |
118 } | |
119 | |
120 calc = calc.trim().toLowerCase(); | |
121 | |
122 for (String mode: CALCULATIONS) { | |
123 if (mode.equals(calc)) { | |
124 return true; | |
125 } | |
126 } | |
127 | |
128 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE); | |
129 } | |
130 } | |
131 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |