comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWQKmsArtifact.java @ 1825:02cd002205a3

Added 'static' wqkms data access. flys-artifacts/trunk@3154 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 03 Nov 2011 13:22:55 +0000
parents
children 64ffc371afe7
comparison
equal deleted inserted replaced
1824:982956bde69e 1825:02cd002205a3
1 package de.intevation.flys.artifacts;
2
3 import java.util.ArrayList;
4 import java.util.List;
5
6 import org.apache.log4j.Logger;
7
8 import org.w3c.dom.Document;
9
10 import de.intevation.artifactdatabase.state.Facet;
11 import de.intevation.artifactdatabase.state.DefaultOutput;
12 import de.intevation.artifactdatabase.state.State;
13
14 import de.intevation.artifacts.Artifact;
15 import de.intevation.artifacts.ArtifactFactory;
16 import de.intevation.artifacts.ArtifactNamespaceContext;
17 import de.intevation.artifacts.CallMeta;
18
19 import de.intevation.flys.artifacts.model.FacetTypes;
20 import de.intevation.flys.artifacts.model.WQKms;
21 import de.intevation.flys.artifacts.model.WQKmsFacet;
22 import de.intevation.flys.artifacts.model.WKmsFactory;
23 import de.intevation.flys.artifacts.model.WQKmsFactory;
24
25 import de.intevation.flys.artifacts.states.StaticState;
26 import de.intevation.flys.artifacts.resources.Resources;
27
28 import de.intevation.artifacts.common.utils.XMLUtils;
29
30 /**
31 * Artifact to access additional "waterlevel/discharge"-type of data, like
32 * fixation measurements.
33 *
34 * This artifact neglects (Static)FLYSArtifacts capabilities of interaction
35 * with the StateEngine by overriding the getState*-methods.
36 */
37 public class StaticWQKmsArtifact
38 extends StaticFLYSArtifact
39 implements FacetTypes
40 {
41 /** The logger for this class. */
42 private static Logger logger =
43 Logger.getLogger(StaticWQKmsArtifact.class);
44
45 /** XPath to access initial parameter. */
46 public static final String XPATH_DATA =
47 "/art:action/art:ids/@value";
48
49 public static final String STATIC_STATE_NAME =
50 "state.additional_wqkms.static";
51
52 /** One and only state to be in. */
53 protected transient State state = null;
54
55
56 /**
57 * Trivial Constructor.
58 */
59 public StaticWQKmsArtifact() {
60 logger.debug("StaticWQKmsArtifact.StaticWQKmsArtifact");
61 }
62
63
64 /**
65 * Gets called from factory, to set things up.
66 */
67 @Override
68 public void setup(
69 String identifier,
70 ArtifactFactory factory,
71 Object context,
72 CallMeta callMeta,
73 Document data)
74 {
75 logger.debug("StaticWQKmsArtifact.setup");
76
77 state = new StaticState(STATIC_STATE_NAME);
78
79 List<Facet> fs = new ArrayList<Facet>();
80 logger.debug(XMLUtils.toString(data));
81 String code = XMLUtils.xpathString(
82 data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE);
83
84 // TODO Go for JSON, one day.
85 //ex.: flood_protection-wstv-114-12
86 if (code != null) {
87 String [] parts = code.split("-");
88
89 if (parts.length >= 4) {
90 try {
91 int col = Integer.valueOf(parts[2]);
92 int wst = Integer.valueOf(parts[3]);
93
94 addStringData("col_pos", parts[2]);
95 addStringData("wst_id", parts[3]);
96
97 String wkmsName = WKmsFactory.getWKmsName(col, wst);
98
99 String name;
100 if (parts[0].equals(HEIGHTMARKS_POINTS)) {
101 name = HEIGHTMARKS_POINTS;
102 }
103 else {
104 name = STATIC_WQKMS;
105 }
106
107 Facet facet = new WQKmsFacet(
108 name,
109 Resources.getMsg(
110 callMeta,
111 wkmsName,
112 wkmsName));
113 fs.add(facet);
114 facets.put(state.getID(), fs);
115 }
116 catch (Exception e) {}
117 }
118 }
119
120 spawnState();
121 super.setup(identifier, factory, context, callMeta, data);
122 }
123
124
125 /**
126 * Initialize the static state with output.
127 * @return static state
128 */
129 protected State spawnState() {
130 state = new StaticState(STATIC_STATE_NAME);
131 List<Facet> fs = facets.get(STATIC_STATE_NAME);
132 DefaultOutput output1 = new DefaultOutput(
133 "w_differences",
134 "w_differences.longitudinal_section", "image/png",
135 fs,
136 "chart");
137 DefaultOutput output2 = new DefaultOutput(
138 "longitudinal_section",
139 "longitudinal_section.longitudinal_section", "image/png",
140 fs,
141 "chart");
142
143 state.getOutputs().add(output1);
144 state.getOutputs().add(output2);
145 return state;
146 }
147
148
149 /**
150 * Called via setup.
151 *
152 * @param artifact The master-artifact.
153 */
154 @Override
155 protected void initialize(
156 Artifact artifact,
157 Object context,
158 CallMeta meta)
159 {
160 logger.debug("StaticWQKmsArtifact.initialize");
161 WINFOArtifact winfo = (WINFOArtifact) artifact;
162 // TODO: The river is of no interest, so far.
163 addData("river", winfo.getData("river"));
164 }
165
166
167 /**
168 * Get a list containing the one and only State.
169 * @param context ignored.
170 * @return list with one and only state.
171 */
172 @Override
173 protected List<State> getStates(Object context) {
174 ArrayList<State> states = new ArrayList<State>();
175 states.add(getState());
176 return states;
177 }
178
179
180 /**
181 * Get the "current" state (there is but one).
182 * @param cc ignored.
183 * @return the "current" (only possible) state.
184 */
185 @Override
186 public State getCurrentState(Object cc) {
187 return getState();
188 }
189
190
191 /**
192 * Get the only possible state.
193 * @return the state.
194 */
195 protected State getState() {
196 return getState(null, null);
197 }
198
199
200 /**
201 * Get the state.
202 * @param context ignored.
203 * @param stateID ignored.
204 * @return the state.
205 */
206 @Override
207 protected State getState(Object context, String stateID) {
208 return (state != null)
209 ? state
210 : spawnState();
211 }
212
213
214 /**
215 * Get WQKms from factory.
216 * @param TODO idx param is not needed
217 * @return WQKms according to parameterization (can be null);
218 */
219 public WQKms getWQKms(int idx) {
220 logger.debug("StaticWQKmsArtifact.getWQKms");
221
222 return WQKmsFactory.getWQKms(
223 Integer.valueOf(getDataAsString("col_pos")),
224 Integer.valueOf(getDataAsString("wst_id")));
225 }
226
227
228 /**
229 * Determines Facets initial disposition regarding activity (think of
230 * selection in Client ThemeList GUI). This will be checked one time
231 * when the facet enters a collections describe document.
232 *
233 * @param facetName name of the facet.
234 * @param index index of the facet.
235 *
236 * @return Always 0. Static Data will enter plots inactive.
237 */
238 @Override
239 public int getInitialFacetActivity(
240 String outputName,
241 String facetName,
242 int index)
243 {
244 return 0;
245 }
246 }
247 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org