Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/ChartArtifact.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/ChartArtifact.java@a2735a4bf75e |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.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 org.dive4elements.artifacts.Artifact; | |
11 | |
12 import org.dive4elements.artifacts.ArtifactFactory; | |
13 import org.dive4elements.artifacts.CallMeta; | |
14 import org.dive4elements.artifacts.CallContext; | |
15 | |
16 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
17 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
18 | |
19 import org.dive4elements.artifactdatabase.ProtocolUtils; | |
20 import org.dive4elements.artifactdatabase.state.Facet; | |
21 import org.dive4elements.artifactdatabase.state.State; | |
22 import org.dive4elements.artifactdatabase.state.StateEngine; | |
23 import org.dive4elements.artifactdatabase.state.Output; | |
24 | |
25 import org.dive4elements.river.utils.FLYSUtils; | |
26 | |
27 import org.dive4elements.river.artifacts.states.DefaultState; | |
28 import org.dive4elements.river.artifacts.context.FLYSContext; | |
29 import org.dive4elements.river.artifacts.resources.Resources; | |
30 | |
31 | |
32 /** Artifact, open to generate any (?) out. */ | |
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 FLYSContext flysContext = FLYSUtils.getFlysContext(context); | |
85 StateEngine engine = (StateEngine) flysContext.get( | |
86 FLYSContext.STATE_ENGINE_KEY); | |
87 | |
88 for (String stateId: stateIds) { | |
89 logger.debug("Append output modes for state: " + stateId); | |
90 DefaultState state = (DefaultState) engine.getState(stateId); | |
91 | |
92 List<Output> list = state.getOutputs(); | |
93 if (list == null || list.isEmpty()) { | |
94 logger.debug("-> No output modes for this state."); | |
95 continue; | |
96 } | |
97 | |
98 List<Facet> fs = getFacets(stateId); | |
99 | |
100 if (fs == null || fs.isEmpty()) { | |
101 logger.debug("No facets for previous state found."); | |
102 continue; | |
103 } | |
104 | |
105 logger.debug("Found " + fs.size() + " facets in previous states."); | |
106 | |
107 List<Output> generated = generateOutputs(list, fs); | |
108 | |
109 ProtocolUtils.appendOutputModes(doc, outs, generated); | |
110 } | |
111 | |
112 try { | |
113 DefaultState cur = (DefaultState) getCurrentState(context); | |
114 List<Output> list = cur.getOutputs(); | |
115 if (list != null && list.size() > 0) { | |
116 logger.debug( | |
117 "Append output modes for current state: " + cur.getID()); | |
118 | |
119 List<Facet> fs = getFacets(cur.getID()); | |
120 | |
121 if (fs != null && fs.size() > 0) { | |
122 List<Output> generated = generateOutputs(list, fs); | |
123 | |
124 logger.debug("Found " + fs.size() + " current facets."); | |
125 if (!generated.isEmpty()) { | |
126 ProtocolUtils.appendOutputModes( | |
127 doc, outs, generated); | |
128 } | |
129 } | |
130 else { | |
131 logger.debug("No facets found for the current state."); | |
132 } | |
133 } | |
134 } | |
135 catch (IllegalArgumentException iae) { | |
136 // state is not valid, so we do not append its outputs. | |
137 } | |
138 } | |
139 | |
140 public static class ChartState extends DefaultState { | |
141 | |
142 public static final String FIELD_MODE = "chart_type"; | |
143 | |
144 public static final String DURATION_CURVE = | |
145 "chart.new.durationcurve"; | |
146 | |
147 public static final String COMPUTED_DISCHARGE_CURVE = | |
148 "chart.new.computeddischargecurve"; | |
149 | |
150 public static final String DISCHARGE_LONGITUDINAL_CURVE = | |
151 "chart.new.longitudinal_section"; | |
152 | |
153 public static final String W_DIFFERENCES = | |
154 "chart.new.w_differences"; | |
155 | |
156 public static final String WATERLEVEL = | |
157 "chart.new.crosssection"; | |
158 | |
159 public static final String[] CHARTS = { | |
160 COMPUTED_DISCHARGE_CURVE, | |
161 DURATION_CURVE, | |
162 DISCHARGE_LONGITUDINAL_CURVE, | |
163 W_DIFFERENCES, | |
164 WATERLEVEL }; | |
165 | |
166 | |
167 | |
168 @Override | |
169 public Object computeAdvance( | |
170 FLYSArtifact artifact, | |
171 String hash, | |
172 CallContext context, | |
173 List<Facet> facets, | |
174 Object old) | |
175 { | |
176 logger.debug("ChartState.computeAdvance"); | |
177 | |
178 | |
179 return null; | |
180 } | |
181 | |
182 | |
183 @Override | |
184 protected Element[] createItems( | |
185 XMLUtils.ElementCreator cr, | |
186 Artifact artifact, | |
187 String name, | |
188 CallContext context) | |
189 { | |
190 CallMeta meta = context.getMeta(); | |
191 Element[] charts = new Element[CHARTS.length]; | |
192 | |
193 int i = 0; | |
194 | |
195 for (String chart: CHARTS) { | |
196 charts[i++] = createItem( | |
197 cr, new String[] { | |
198 Resources.getMsg(meta, chart, chart), | |
199 chart | |
200 }); | |
201 } | |
202 | |
203 return charts; | |
204 } | |
205 } | |
206 } | |
207 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |