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

http://dive4elements.wald.intevation.org