Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/MINFOArtifact.java @ 2693:edaa2297aea3
Started module MINFO (MINFOArtifact, state to choose calculations, configurations).
flys-artifacts/trunk@4397 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 14 May 2012 08:09:10 +0000 |
parents | |
children | 4c00cf83fff1 |
comparison
equal
deleted
inserted
replaced
2692:32b1e28edb15 | 2693:edaa2297aea3 |
---|---|
1 package de.intevation.flys.artifacts; | |
2 | |
3 import de.intevation.artifactdatabase.ProtocolUtils; | |
4 | |
5 import de.intevation.artifactdatabase.state.Output; | |
6 import de.intevation.artifactdatabase.state.State; | |
7 import de.intevation.artifactdatabase.state.StateEngine; | |
8 | |
9 import de.intevation.artifactdatabase.transition.TransitionEngine; | |
10 | |
11 import de.intevation.artifacts.CallContext; | |
12 import de.intevation.artifacts.Message; | |
13 | |
14 import de.intevation.artifacts.common.ArtifactNamespaceContext; | |
15 | |
16 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
17 | |
18 import de.intevation.artifacts.common.utils.XMLUtils; | |
19 | |
20 import de.intevation.flys.artifacts.context.FLYSContext; | |
21 | |
22 import de.intevation.flys.artifacts.model.CalculationMessage; | |
23 import de.intevation.flys.artifacts.model.FacetTypes; | |
24 | |
25 import de.intevation.flys.artifacts.states.DefaultState; | |
26 | |
27 import de.intevation.flys.utils.FLYSUtils; | |
28 | |
29 import java.util.LinkedList; | |
30 import java.util.List; | |
31 | |
32 import org.apache.log4j.Logger; | |
33 | |
34 import org.w3c.dom.Document; | |
35 import org.w3c.dom.Element; | |
36 import org.w3c.dom.Node; | |
37 | |
38 /** | |
39 * The default MINFO artifact. | |
40 * | |
41 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
42 */ | |
43 public class MINFOArtifact | |
44 extends FLYSArtifact | |
45 implements FacetTypes { | |
46 | |
47 /** The logger for this class. */ | |
48 private static Logger logger = Logger.getLogger(MINFOArtifact.class); | |
49 | |
50 /** The name of the artifact. */ | |
51 public static final String ARTIFACT_NAME = "minfo"; | |
52 | |
53 /** XPath */ | |
54 public static final String XPATH_STATIC_UI ="/art:result/art:ui/art:static"; | |
55 | |
56 | |
57 /** | |
58 * The default constructor. | |
59 */ | |
60 public MINFOArtifact() { | |
61 } | |
62 | |
63 | |
64 /** | |
65 * This method returns a description of this artifact. | |
66 * | |
67 * @param data Some data. | |
68 * @param context The CallContext. | |
69 * | |
70 * @return the description of this artifact. | |
71 */ | |
72 public Document describe(Document data, CallContext context) { | |
73 logger.debug("Describe: the current state is: " + getCurrentStateId()); | |
74 | |
75 FLYSContext flysContext = FLYSUtils.getFlysContext(context); | |
76 StateEngine stateEngine = (StateEngine) flysContext.get( | |
77 FLYSContext.STATE_ENGINE_KEY); | |
78 | |
79 TransitionEngine transitionEngine = (TransitionEngine) flysContext.get( | |
80 FLYSContext.TRANSITION_ENGINE_KEY); | |
81 | |
82 List<State> reachable = transitionEngine.getReachableStates( | |
83 this, getCurrentState(context), stateEngine); | |
84 | |
85 Document description = XMLUtils.newDocument(); | |
86 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | |
87 description, | |
88 ArtifactNamespaceContext.NAMESPACE_URI, | |
89 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
90 | |
91 Element root = ProtocolUtils.createRootNode(creator); | |
92 description.appendChild(root); | |
93 | |
94 State current = getCurrentState(context); | |
95 | |
96 ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); | |
97 ProtocolUtils.appendState(creator, root, current); | |
98 ProtocolUtils.appendReachableStates(creator, root, reachable); | |
99 | |
100 appendBackgroundActivity(creator, root, context); | |
101 | |
102 Element name = ProtocolUtils.createArtNode( | |
103 creator, "name", | |
104 new String[] { "value" }, | |
105 new String[] { getName() }); | |
106 | |
107 Element ui = ProtocolUtils.createArtNode( | |
108 creator, "ui", null, null); | |
109 | |
110 Element staticUI = ProtocolUtils.createArtNode( | |
111 creator, "static", null, null); | |
112 | |
113 Element outs = ProtocolUtils.createArtNode( | |
114 creator, "outputmodes", null, null); | |
115 appendOutputModes(description, outs, context, identifier()); | |
116 | |
117 appendStaticUI(description, staticUI, context, identifier()); | |
118 | |
119 Element dynamic = current.describe( | |
120 this, | |
121 description, | |
122 root, | |
123 context, | |
124 identifier()); | |
125 | |
126 if (dynamic != null) { | |
127 ui.appendChild(dynamic); | |
128 } | |
129 | |
130 ui.appendChild(staticUI); | |
131 | |
132 root.appendChild(name); | |
133 root.appendChild(ui); | |
134 root.appendChild(outs); | |
135 | |
136 return description; | |
137 } | |
138 | |
139 | |
140 /** | |
141 * Returns the name of the concrete artifact. | |
142 * | |
143 * @return the name of the concrete artifact. | |
144 */ | |
145 public String getName() { | |
146 return ARTIFACT_NAME; | |
147 } | |
148 | |
149 | |
150 protected static void appendBackgroundActivity( | |
151 ElementCreator cr, | |
152 Element root, | |
153 CallContext context | |
154 ) { | |
155 Element inBackground = cr.create("background-processing"); | |
156 root.appendChild(inBackground); | |
157 | |
158 cr.addAttr( | |
159 inBackground, | |
160 "value", | |
161 String.valueOf(context.isInBackground()), | |
162 true); | |
163 | |
164 LinkedList<Message> messages = context.getBackgroundMessages(); | |
165 | |
166 if (messages == null) { | |
167 return; | |
168 } | |
169 | |
170 CalculationMessage message = (CalculationMessage) messages.getLast(); | |
171 cr.addAttr( | |
172 inBackground, | |
173 "steps", | |
174 String.valueOf(message.getSteps()), | |
175 true); | |
176 | |
177 cr.addAttr( | |
178 inBackground, | |
179 "currentStep", | |
180 String.valueOf(message.getCurrentStep()), | |
181 true); | |
182 | |
183 inBackground.setTextContent(message.getMessage()); | |
184 } | |
185 | |
186 | |
187 /** | |
188 * Append output mode nodes to a document. | |
189 */ | |
190 protected void appendOutputModes( | |
191 Document doc, | |
192 Element outs, | |
193 CallContext context, | |
194 String uuid) | |
195 { | |
196 List<Output> generated = getOutputs(context); | |
197 logger.debug("This Artifact has " + generated.size() + " Outputs."); | |
198 | |
199 ProtocolUtils.appendOutputModes(doc, outs, generated); | |
200 } | |
201 | |
202 | |
203 /** | |
204 * This method appends the static data - that has already been inserted by | |
205 * the user - to the static node of the DESCRIBE document. | |
206 * | |
207 * @param doc The document. | |
208 * @param ui The root node. | |
209 * @param context The CallContext. | |
210 * @param uuid The identifier of the artifact. | |
211 */ | |
212 protected void appendStaticUI( | |
213 Document doc, | |
214 Node ui, | |
215 CallContext context, | |
216 String uuid) | |
217 { | |
218 List<String> stateIds = getPreviousStateIds(); | |
219 | |
220 FLYSContext flysContext = FLYSUtils.getFlysContext(context); | |
221 StateEngine engine = (StateEngine) flysContext.get( | |
222 FLYSContext.STATE_ENGINE_KEY); | |
223 | |
224 for (String stateId: stateIds) { | |
225 logger.debug("Append static data for state: " + stateId); | |
226 DefaultState state = (DefaultState) engine.getState(stateId); | |
227 | |
228 ui.appendChild(state.describeStatic(this, doc, ui, context, uuid)); | |
229 } | |
230 } | |
231 | |
232 | |
233 /** | |
234 * Determines Facets initial disposition regarding activity (think of | |
235 * selection in Client ThemeList GUI). This will be checked one time | |
236 * when the facet enters a collections describe document. | |
237 * | |
238 * @param facetName name of the facet. | |
239 * @param index index of the facet. | |
240 * @return 0 if not active | |
241 */ | |
242 @Override | |
243 public int getInitialFacetActivity(String outputName, String facetName, int index) { | |
244 logger.warn("MINFOArtifact.getInitialFacetActivity: not implemented!"); | |
245 return 1; | |
246 } | |
247 } | |
248 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |