Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/ChartArtifact.java @ 3318:dbe2f85bf160
merged flys-artifacts/2.8
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:35 +0200 |
parents | 2f922be407ea |
children | b1912514e0f5 |
comparison
equal
deleted
inserted
replaced
2987:98c7a46ec5ae | 3318:dbe2f85bf160 |
---|---|
1 package de.intevation.flys.artifacts; | |
2 | |
3 import org.apache.log4j.Logger; | |
4 | |
5 import java.util.List; | |
6 | |
7 import org.w3c.dom.Document; | |
8 import org.w3c.dom.Element; | |
9 | |
10 import de.intevation.artifacts.Artifact; | |
11 | |
12 import de.intevation.artifacts.ArtifactFactory; | |
13 import de.intevation.artifacts.CallMeta; | |
14 import de.intevation.artifacts.CallContext; | |
15 | |
16 import de.intevation.artifacts.common.utils.XMLUtils; | |
17 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
18 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
19 | |
20 import de.intevation.artifactdatabase.ProtocolUtils; | |
21 import de.intevation.artifactdatabase.state.Facet; | |
22 import de.intevation.artifactdatabase.state.State; | |
23 import de.intevation.artifactdatabase.state.StateEngine; | |
24 import de.intevation.artifactdatabase.state.Output; | |
25 | |
26 import de.intevation.flys.utils.FLYSUtils; | |
27 | |
28 import de.intevation.flys.artifacts.states.DefaultState; | |
29 import de.intevation.flys.artifacts.context.FLYSContext; | |
30 import de.intevation.flys.artifacts.resources.Resources; | |
31 | |
32 | |
33 public class ChartArtifact extends FLYSArtifact { | |
34 | |
35 private static final Logger logger = | |
36 Logger.getLogger(ChartArtifact.class); | |
37 | |
38 @Override | |
39 public void setup( | |
40 String identifier, | |
41 ArtifactFactory factory, | |
42 Object context, | |
43 CallMeta callmeta, | |
44 Document data) | |
45 { | |
46 logger.debug("ChartArtifact.setup"); | |
47 this.identifier = identifier; | |
48 name = "new_chart"; | |
49 | |
50 List<State> states = getStates(context); | |
51 | |
52 setCurrentState(states.get(0)); | |
53 } | |
54 | |
55 @Override | |
56 protected void appendBackgroundActivity( | |
57 ElementCreator cr, | |
58 Element root, | |
59 CallContext context | |
60 ) { | |
61 Element inBackground = cr.create("background-processing"); | |
62 root.appendChild(inBackground); | |
63 | |
64 cr.addAttr( | |
65 inBackground, | |
66 "value", | |
67 String.valueOf(context.isInBackground()), | |
68 true); | |
69 } | |
70 | |
71 | |
72 /** | |
73 * Append output mode nodes to a document. | |
74 */ | |
75 @Override | |
76 protected void appendOutputModes( | |
77 Document doc, | |
78 Element outs, | |
79 CallContext context, | |
80 String uuid) | |
81 { | |
82 List<String> stateIds = getPreviousStateIds(); | |
83 | |
84 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
85 doc, | |
86 ArtifactNamespaceContext.NAMESPACE_URI, | |
87 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
88 | |
89 FLYSContext flysContext = FLYSUtils.getFlysContext(context); | |
90 StateEngine engine = (StateEngine) flysContext.get( | |
91 FLYSContext.STATE_ENGINE_KEY); | |
92 | |
93 for (String stateId: stateIds) { | |
94 logger.debug("Append output modes for state: " + stateId); | |
95 DefaultState state = (DefaultState) engine.getState(stateId); | |
96 | |
97 List<Output> list = state.getOutputs(); | |
98 if (list == null || list.size() == 0) { | |
99 logger.debug("-> No output modes for this state."); | |
100 continue; | |
101 } | |
102 | |
103 List<Facet> fs = facets.get(stateId); | |
104 | |
105 if (fs == null || fs.size() == 0) { | |
106 logger.debug("No facets for previous state found."); | |
107 continue; | |
108 } | |
109 | |
110 logger.debug("Found " + fs.size() + " facets in previous states."); | |
111 | |
112 List<Output> generated = generateOutputs(list, fs); | |
113 | |
114 ProtocolUtils.appendOutputModes(doc, outs, generated); | |
115 } | |
116 | |
117 try { | |
118 DefaultState cur = (DefaultState) getCurrentState(context); | |
119 List<Output> list = cur.getOutputs(); | |
120 if (list != null && list.size() > 0) { | |
121 logger.debug( | |
122 "Append output modes for current state: " + cur.getID()); | |
123 | |
124 List<Facet> fs = facets.get(cur.getID()); | |
125 | |
126 if (fs != null && fs.size() > 0) { | |
127 List<Output> generated = generateOutputs(list, fs); | |
128 | |
129 logger.debug("Found " + fs.size() + " current facets."); | |
130 if (!generated.isEmpty()) { | |
131 ProtocolUtils.appendOutputModes( | |
132 doc, outs, generated); | |
133 } | |
134 } | |
135 else { | |
136 logger.debug("No facets found for the current state."); | |
137 } | |
138 } | |
139 } | |
140 catch (IllegalArgumentException iae) { | |
141 // state is not valid, so we do not append its outputs. | |
142 } | |
143 } | |
144 | |
145 public static class ChartState extends DefaultState { | |
146 | |
147 public static final String FIELD_MODE = "chart_type"; | |
148 | |
149 public static final String DURATION_CURVE = | |
150 "chart.new.durationcurve"; | |
151 | |
152 public static final String COMPUTED_DISCHARGE_CURVE = | |
153 "chart.new.computeddischargecurve"; | |
154 | |
155 public static final String DISCHARGE_LONGITUDINAL_CURVE = | |
156 "chart.new.longitudinal_section"; | |
157 | |
158 public static final String W_DIFFERENCES = | |
159 "chart.new.w_differences"; | |
160 | |
161 public static final String WATERLEVEL = | |
162 "chart.new.crosssection"; | |
163 | |
164 public static final String[] CHARTS = { | |
165 COMPUTED_DISCHARGE_CURVE, | |
166 DURATION_CURVE, | |
167 DISCHARGE_LONGITUDINAL_CURVE, | |
168 W_DIFFERENCES, | |
169 WATERLEVEL }; | |
170 | |
171 | |
172 | |
173 @Override | |
174 public Object computeAdvance( | |
175 FLYSArtifact artifact, | |
176 String hash, | |
177 CallContext context, | |
178 List<Facet> facets, | |
179 Object old) | |
180 { | |
181 logger.debug("ChartState.computeAdvance"); | |
182 | |
183 | |
184 return null; | |
185 } | |
186 | |
187 | |
188 @Override | |
189 protected Element[] createItems( | |
190 XMLUtils.ElementCreator cr, | |
191 Artifact artifact, | |
192 String name, | |
193 CallContext context) | |
194 { | |
195 CallMeta meta = context.getMeta(); | |
196 Element[] charts = new Element[CHARTS.length]; | |
197 | |
198 int i = 0; | |
199 | |
200 for (String chart: CHARTS) { | |
201 charts[i++] = createItem( | |
202 cr, new String[] { | |
203 Resources.getMsg(meta, chart, chart), | |
204 chart | |
205 }); | |
206 } | |
207 | |
208 return charts; | |
209 } | |
210 } | |
211 } | |
212 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |