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