comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWQKmsArtifact.java @ 3812:f788d2d901d6

merged flys-artifacts/pre2.6-2011-12-05
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:14:53 +0200
parents 64ffc371afe7
children a202a9e048a5
comparison
equal deleted inserted replaced
3808:5fab0fe3c445 3812:f788d2d901d6
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 int col = Integer.valueOf(parts[2]);
91 int wst = Integer.valueOf(parts[3]);
92
93 addStringData("col_pos", parts[2]);
94 addStringData("wst_id", parts[3]);
95
96 String wkmsName = WKmsFactory.getWKmsName(col, wst);
97
98 String name;
99 if (parts[0].equals(HEIGHTMARKS_POINTS)) {
100 name = HEIGHTMARKS_POINTS;
101 }
102 else {
103 name = STATIC_WQKMS;
104 }
105
106 Facet facet = new WQKmsFacet(
107 name,
108 Resources.getMsg(
109 callMeta,
110 wkmsName,
111 wkmsName));
112 fs.add(facet);
113 facets.put(state.getID(), fs);
114 }
115 }
116
117 spawnState();
118 super.setup(identifier, factory, context, callMeta, data);
119 }
120
121
122 /**
123 * Initialize the static state with output.
124 * @return static state
125 * @TODO merge with StaticWKmsArtifact implementation.
126 */
127 protected State spawnState() {
128 state = new StaticState(STATIC_STATE_NAME);
129 List<Facet> fs = facets.get(STATIC_STATE_NAME);
130 DefaultOutput output = new DefaultOutput(
131 "general",
132 "general",
133 "image/png",
134 fs,
135 "chart");
136
137 state.getOutputs().add(output);
138 return state;
139 }
140
141
142 /**
143 * Called via setup.
144 *
145 * @param artifact The master-artifact.
146 */
147 @Override
148 protected void initialize(
149 Artifact artifact,
150 Object context,
151 CallMeta meta)
152 {
153 logger.debug("StaticWQKmsArtifact.initialize");
154 WINFOArtifact winfo = (WINFOArtifact) artifact;
155 // TODO: The river is of no interest, so far.
156 addData("river", winfo.getData("river"));
157 }
158
159
160 /**
161 * Get a list containing the one and only State.
162 * @param context ignored.
163 * @return list with one and only state.
164 */
165 @Override
166 protected List<State> getStates(Object context) {
167 ArrayList<State> states = new ArrayList<State>();
168 states.add(getState());
169 return states;
170 }
171
172
173 /**
174 * Get the "current" state (there is but one).
175 * @param cc ignored.
176 * @return the "current" (only possible) state.
177 */
178 @Override
179 public State getCurrentState(Object cc) {
180 return getState();
181 }
182
183
184 /**
185 * Get the only possible state.
186 * @return the state.
187 */
188 protected State getState() {
189 return getState(null, null);
190 }
191
192
193 /**
194 * Get the state.
195 * @param context ignored.
196 * @param stateID ignored.
197 * @return the state.
198 */
199 @Override
200 protected State getState(Object context, String stateID) {
201 return (state != null)
202 ? state
203 : spawnState();
204 }
205
206
207 /**
208 * Get WQKms from factory.
209 * @param TODO idx param is not needed
210 * @return WQKms according to parameterization (can be null);
211 */
212 public WQKms getWQKms(int idx) {
213 logger.debug("StaticWQKmsArtifact.getWQKms");
214
215 return WQKmsFactory.getWQKms(
216 Integer.valueOf(getDataAsString("col_pos")),
217 Integer.valueOf(getDataAsString("wst_id")));
218 }
219
220
221 /**
222 * Determines Facets initial disposition regarding activity (think of
223 * selection in Client ThemeList GUI). This will be checked one time
224 * when the facet enters a collections describe document.
225 *
226 * @param facetName name of the facet.
227 * @param index index of the facet.
228 *
229 * @return Always 0. Static Data will enter plots inactive.
230 */
231 @Override
232 public int getInitialFacetActivity(
233 String outputName,
234 String facetName,
235 int index)
236 {
237 return 0;
238 }
239 }
240 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org