comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/CalculationSelect.java @ 3318:dbe2f85bf160

merged flys-artifacts/2.8
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:35 +0200
parents d548e2e13524
children 75a90d9d2024
comparison
equal deleted inserted replaced
2987:98c7a46ec5ae 3318:dbe2f85bf160
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 /** Constant value for the historical discharge curve calculation. */
58 public static final String CALCULATION_HISTORICAL_DISCHARGE_CURVE =
59 "calc.historical.discharge.curve";
60
61 /** An array that holds all available calculation modes. */
62 public static final String[] CALCULATIONS = {
63 CALCULATION_SURFACE_CURVE,
64 CALCULATION_FLOOD_MAP,
65 CALCULATION_DISCHARGE_CURVE,
66 CALCULATION_HISTORICAL_DISCHARGE_CURVE,
67 CALCULATION_DURATION_CURVE,
68 CALCULATION_DISCHARGE_LONGITUDINAL_CURVE,
69 CALCULATION_W_DIFFERENCES,
70 CALCULATION_REFERENCE_CURVE };
71
72
73 /** Error message that is thrown if no mode has been chosen. */
74 public static final String ERROR_NO_CALCULATION_MODE =
75 "error_feed_no_calculation_mode";
76
77 /** Error message that is thrown if an invalid calculation mode has been
78 * chosen. */
79 public static final String ERROR_INVALID_CALCULATION_MODE =
80 "error_feed_invalid_calculation_mode";
81
82
83 public CalculationSelect() {
84 }
85
86
87 @Override
88 protected Element[] createItems(
89 XMLUtils.ElementCreator cr,
90 Artifact artifact,
91 String name,
92 CallContext context)
93 {
94 CallMeta meta = context.getMeta();
95 Element[] calcs = new Element[CALCULATIONS.length];
96
97 for (int i = 0; i < CALCULATIONS.length; ++i) {
98 String calc = CALCULATIONS[i];
99 calcs[i] = createItem(
100 cr, new String[] {
101 Resources.getMsg(meta, calc, calc),
102 calc
103 });
104 }
105
106 return calcs;
107 }
108
109
110 @Override
111 public boolean validate(Artifact artifact)
112 throws IllegalArgumentException
113 {
114 logger.debug("CalculationSelect.validate");
115 FLYSArtifact flys = (FLYSArtifact) artifact;
116
117 StateData data = getData(flys, FIELD_MODE);
118 String calc = (data != null) ? (String) data.getValue() : null;
119
120 if (calc == null) {
121 throw new IllegalArgumentException(ERROR_NO_CALCULATION_MODE);
122 }
123
124 calc = calc.trim().toLowerCase();
125
126 for (String mode: CALCULATIONS) {
127 if (mode.equals(calc)) {
128 return true;
129 }
130 }
131
132 throw new IllegalArgumentException(ERROR_INVALID_CALCULATION_MODE);
133 }
134 }
135 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org