Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java @ 1723:690037105542
Added new Artifact and Facet to access 'static' data via WKmsFactory.
flys-artifacts/trunk@3005 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Tue, 18 Oct 2011 12:56:12 +0000 |
parents | |
children | d9afb16d1fd4 |
comparison
equal
deleted
inserted
replaced
1722:fb4fb1c67c35 | 1723:690037105542 |
---|---|
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.WKms; | |
20 import de.intevation.flys.artifacts.model.WKmsFacet; | |
21 import de.intevation.flys.artifacts.model.WstValueTable; | |
22 import de.intevation.flys.artifacts.model.WstValueTableFactory; | |
23 import de.intevation.flys.artifacts.model.WKmsFactory; | |
24 | |
25 import de.intevation.flys.artifacts.states.StaticState; | |
26 import de.intevation.flys.artifacts.resources.Resources; | |
27 | |
28 import de.intevation.flys.utils.FLYSUtils; | |
29 import de.intevation.artifacts.common.utils.XMLUtils; | |
30 | |
31 | |
32 /** | |
33 * Artifact to access additional "waterlevel"-type of data, like the height | |
34 * of protective measures (dikes). | |
35 * | |
36 * This artifact neglects (Static)FLYSArtifacts capabilities of interaction | |
37 * with the StateEngine by overriding the getState*-methods. | |
38 */ | |
39 public class StaticWKmsArtifact | |
40 extends StaticFLYSArtifact | |
41 { | |
42 /** The logger for this class. */ | |
43 private static Logger logger = | |
44 Logger.getLogger(StaticWKmsArtifact.class); | |
45 | |
46 /** XPath to access initial parameter. */ | |
47 public static final String XPATH_DATA = | |
48 "/art:action/art:ids/@value"; | |
49 | |
50 /** One and only state to be in. */ | |
51 protected transient State state = null; | |
52 | |
53 protected int col_pos; | |
54 | |
55 protected int wst_id; | |
56 | |
57 | |
58 /** | |
59 * Trivial Constructor. | |
60 */ | |
61 public StaticWKmsArtifact() { | |
62 logger.debug("StaticWKmsArtifact.StaticWKmsArtifact"); | |
63 } | |
64 | |
65 | |
66 /** | |
67 * Gets called from factory, to set things up. | |
68 */ | |
69 @Override | |
70 public void setup( | |
71 String identifier, | |
72 ArtifactFactory factory, | |
73 Object context, | |
74 CallMeta callMeta, | |
75 Document data) | |
76 { | |
77 logger.debug("StaticWKmsArtifact.setup"); | |
78 | |
79 state = new StaticState( | |
80 "state.additional_wkms.static", | |
81 "state.additional_wkms.static"); | |
82 List<Facet> fs = new ArrayList<Facet>(); | |
83 logger.debug(XMLUtils.toString(data)); | |
84 String code = XMLUtils.xpathString( | |
85 data, XPATH_DATA, ArtifactNamespaceContext.INSTANCE); | |
86 | |
87 logger.debug("makes: " + code); | |
88 | |
89 //ex.: flood_protection-wstv-114-12 | |
90 if (code != null) { | |
91 String [] parts = code.split("-"); | |
92 int col = Integer.valueOf(parts[2]); | |
93 int wst = Integer.valueOf(parts[3]); | |
94 // These shall be put in data (addData) | |
95 this.col_pos = col; | |
96 this.wst_id = wst; | |
97 // addDataAsString? | |
98 } | |
99 | |
100 // Will get col_id and wst_id | |
101 | |
102 Facet facet = new WKmsFacet(Resources.getMsg(callMeta, | |
103 "facet.discharge_curves.mainvalues.w", | |
104 "facet.discharge_curves.mainvalues.w")); | |
105 fs.add(facet); | |
106 facets.put(state.getID(), fs); | |
107 | |
108 spawnState(); | |
109 super.setup(identifier, factory, context, callMeta, data); | |
110 } | |
111 | |
112 | |
113 /** | |
114 * Initialize the static state with output. | |
115 */ | |
116 protected State spawnState() { | |
117 state = new StaticState( | |
118 "state.additional_wkms.static", | |
119 "state.additional_wkms.static"); | |
120 List<Facet> fs = (List<Facet>) facets.get("state.additional_wkms.static"); | |
121 DefaultOutput output = new DefaultOutput( | |
122 "w_differences", | |
123 "w_differences.longitudinal_section", "image/png", | |
124 fs, | |
125 "chart"); | |
126 // TODO: also add longitudinal_section output? | |
127 | |
128 state.getOutputs().add(output); | |
129 return state; | |
130 } | |
131 | |
132 | |
133 /** | |
134 * Called via setup. | |
135 */ | |
136 @Override | |
137 protected void initialize(Artifact artifact, Object context, CallMeta meta) { | |
138 logger.debug("StaticWKmsArtifact.initialize"); | |
139 WINFOArtifact winfo = (WINFOArtifact) artifact; | |
140 // TODO: The river is of no interest, so far. | |
141 addData("river", winfo.getData("river")); | |
142 } | |
143 | |
144 | |
145 /** | |
146 * Get a list containing the one and only State. | |
147 * @param context ignored. | |
148 * @return list with one and only state. | |
149 */ | |
150 @Override | |
151 protected List<State> getStates(Object context) { | |
152 ArrayList<State> states = new ArrayList<State>(); | |
153 states.add(getState()); | |
154 return states; | |
155 } | |
156 | |
157 | |
158 /** | |
159 * Get the "current" state (there is but one). | |
160 * @param cc ignored. | |
161 * @return the "current" (only possible) state. | |
162 */ | |
163 @Override | |
164 public State getCurrentState(Object cc) { | |
165 return getState(); | |
166 } | |
167 | |
168 | |
169 /** | |
170 * Get the only possible state. | |
171 * @return the state. | |
172 */ | |
173 protected State getState() { | |
174 return getState(null, null); | |
175 } | |
176 | |
177 | |
178 /** | |
179 * Get the state. | |
180 * @param context ignored. | |
181 * @param stateID ignored. | |
182 * @return the state. | |
183 */ | |
184 @Override | |
185 protected State getState(Object context, String stateID) { | |
186 if (state != null) | |
187 return state; | |
188 else | |
189 return spawnState(); | |
190 } | |
191 | |
192 | |
193 /** | |
194 * Get WKms from factory. | |
195 * @param TODO idx param is not needed | |
196 * @return WKms according to parameterization (can be null); | |
197 */ | |
198 public WKms getWKms(int idx) { | |
199 logger.debug("StaticWKmsArtifact.getWKms"); | |
200 | |
201 // TODO KIND is not needed. | |
202 return WKmsFactory.getWKms( | |
203 WKmsFactory.KIND_PROTECTION, | |
204 this.col_pos, | |
205 this.wst_id); | |
206 } | |
207 } | |
208 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |