annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MultiIntArrayState.java @ 5240:9c024718bffb

WaterlevelParser: Use Wst-structures directly (instead of Waterlevel*).
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Tue, 12 Mar 2013 10:55:14 +0100
parents 4bd3d8bbb60c
children
rev   line source
2696
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
1 package de.intevation.flys.artifacts.states;
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
2
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
3 import org.w3c.dom.Element;
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
4
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
5 import org.apache.log4j.Logger;
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
6
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
7 import de.intevation.artifacts.Artifact;
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
8 import de.intevation.artifacts.CallContext;
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
9
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
11 import de.intevation.artifacts.common.model.KVP;
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
12
2705
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
13 import de.intevation.flys.artifacts.FLYSArtifact;
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
14 import de.intevation.flys.artifacts.resources.Resources;
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
15 import de.intevation.flys.utils.FLYSUtils;
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
16
2696
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
17
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
18 /**
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
19 * State that holds minimun and maximum (for validation).
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
20 *
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
21 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
22 */
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
23 public abstract class MultiIntArrayState extends DefaultState {
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
24
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
25 private static final Logger logger =
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
26 Logger.getLogger(MultiIntArrayState.class);
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
27
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
28
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
29 @Override
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
30 protected void appendItems(
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
31 Artifact artifact,
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32 ElementCreator creator,
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 String name,
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 CallContext context,
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 Element select
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
36 ) {
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37 try {
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
38 creator.addAttr(select, "type", "intoptions", true);
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
39
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40 for (KVP kvp: getOptions(artifact, name)) {
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
41 Element item = creator.create("item");
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
42 creator.addAttr(item, "label", kvp.getValue().toString(), true);
2708
282db12a5bdf Adapted the dynamic DESCRIBE creation of MultiIntArrayState to be able to use default mechanisms in FLYS client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2705
diff changeset
43 creator.addAttr(item, "value", kvp.getKey().toString(), true);
2696
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
44
2708
282db12a5bdf Adapted the dynamic DESCRIBE creation of MultiIntArrayState to be able to use default mechanisms in FLYS client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2705
diff changeset
45 select.appendChild(item);
2696
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
46 }
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
47 }
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
48 catch (IllegalArgumentException iae) {
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
49 logger.warn("Illegal argument", iae);
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
50 }
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
51 }
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
52
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
53
2705
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
54 @Override
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
55 protected Element createStaticData(
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
56 FLYSArtifact flys,
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
57 ElementCreator creator,
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
58 CallContext cc,
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
59 String name,
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
60 String value,
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
61 String type
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
62 ) {
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
63 Element data = creator.create("data");
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
64 creator.addAttr(data, "name", name, true);
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
65 creator.addAttr(data, "type", type, true);
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
66 creator.addAttr(data, "label",
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
67 Resources.getMsg(cc.getMeta(), name, name), true);
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
68
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
69 int[] values = FLYSUtils.intArrayFromString(value);
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
70
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
71 for (int val: values) {
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
72 try {
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
73 Element item = creator.create("item");
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
74 creator.addAttr(item, "value", String.valueOf(val), true);
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
75 creator.addAttr(item, "label", getLabelFor(cc, name, val), true);
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
76
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
77 data.appendChild(item);
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
78 }
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
79 catch (IllegalArgumentException iae) {
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
80 logger.warn("Cannot append item: " + val, iae);
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
81 }
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
82 }
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
83
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
84 return data;
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
85 }
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
86
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
87
2696
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
88 protected abstract KVP<Integer, String>[] getOptions(
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
89 Artifact artifact,
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
90 String parameterName
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
91 )
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
92 throws IllegalArgumentException;
2705
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
93
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
94
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
95 protected abstract String getLabelFor(
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
96 CallContext cc,
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
97 String parameterName,
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
98 int value)
71f072d8b3d8 Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2696
diff changeset
99 throws IllegalArgumentException;
2696
1bc35de0b786 Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
100 }
3083
4bd3d8bbb60c Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 2708
diff changeset
101 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org