Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 335:e964a3d8f7bc
Some Refactoring work done.
Moved Transition to State
gnv-artifacts/trunk@401 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Tim Englich <tim.englich@intevation.de> |
---|---|
date | Tue, 08 Dec 2009 08:39:03 +0000 |
parents | 3eff9241ea1e |
children | a887074460b6 |
comparison
equal
deleted
inserted
replaced
334:e37930705daa | 335:e964a3d8f7bc |
---|---|
24 import de.intevation.artifacts.ArtifactFactory; | 24 import de.intevation.artifacts.ArtifactFactory; |
25 import de.intevation.artifacts.ArtifactNamespaceContext; | 25 import de.intevation.artifacts.ArtifactNamespaceContext; |
26 import de.intevation.artifacts.CallContext; | 26 import de.intevation.artifacts.CallContext; |
27 import de.intevation.artifacts.CallMeta; | 27 import de.intevation.artifacts.CallMeta; |
28 import de.intevation.gnv.artifacts.context.GNVArtifactContext; | 28 import de.intevation.gnv.artifacts.context.GNVArtifactContext; |
29 import de.intevation.gnv.transition.DefaultInputData; | 29 import de.intevation.gnv.state.DefaultInputData; |
30 import de.intevation.gnv.transition.InputData; | 30 import de.intevation.gnv.state.InputData; |
31 import de.intevation.gnv.transition.InputValue; | 31 import de.intevation.gnv.state.InputValue; |
32 import de.intevation.gnv.transition.OutputMode; | 32 import de.intevation.gnv.state.OutputMode; |
33 import de.intevation.gnv.transition.OutputTransition; | 33 import de.intevation.gnv.state.OutputState; |
34 import de.intevation.gnv.transition.Transition; | 34 import de.intevation.gnv.state.State; |
35 import de.intevation.gnv.transition.TransitionFactory; | 35 import de.intevation.gnv.state.StateFactory; |
36 import de.intevation.gnv.transition.exception.TransitionException; | 36 import de.intevation.gnv.state.exception.StateException; |
37 import de.intevation.gnv.utils.ArtifactXMLUtilities; | 37 import de.intevation.gnv.utils.ArtifactXMLUtilities; |
38 | 38 |
39 /** | 39 /** |
40 * @author Tim Englich <tim.englich@intevation.de> | 40 * @author Tim Englich <tim.englich@intevation.de> |
41 * | 41 * |
61 public static final String XPATH_ARTIFACT_CONFIGURATION = "/artifact-database/artifacts/artifact[@name='" | 61 public static final String XPATH_ARTIFACT_CONFIGURATION = "/artifact-database/artifacts/artifact[@name='" |
62 + XPATH_IDENTIFIER_REPLACE | 62 + XPATH_IDENTIFIER_REPLACE |
63 + "']"; | 63 + "']"; |
64 | 64 |
65 /** | 65 /** |
66 * The current Transition | 66 * The current State |
67 */ | 67 */ |
68 protected Transition current = null; | 68 protected State current = null; |
69 | 69 |
70 /** | 70 /** |
71 * The Transitions that can be used | 71 * The States that can be used |
72 */ | 72 */ |
73 protected Map<String, Transition> transitions = null; | 73 protected Map<String, State> states = null; |
74 | 74 |
75 /** | 75 /** |
76 * The Name of the Artifact | 76 * The Name of the Artifact |
77 */ | 77 */ |
78 protected String name = null; | 78 protected String name = null; |
94 public Document advance(Document target, CallContext context) { | 94 public Document advance(Document target, CallContext context) { |
95 log.debug("GNVArtifactBase.advance"); | 95 log.debug("GNVArtifactBase.advance"); |
96 Document result = XMLUtils.newDocument(); | 96 Document result = XMLUtils.newDocument(); |
97 try { | 97 try { |
98 if (this.current != null) { | 98 if (this.current != null) { |
99 String transitionName = this.readTransitionName(target); | 99 String stateName = this.readStateName(target); |
100 log.debug("Transitionsname: " + transitionName); | 100 log.debug("Statename: " + stateName); |
101 if (this.current.isTransitionReachable(transitionName)) { | 101 if (this.current.isStateReachable(stateName)) { |
102 try { | 102 try { |
103 Transition nextStep = this.transitions | 103 State nextStep = this.states |
104 .get(transitionName); | 104 .get(stateName); |
105 // 1.Ergebnisse Berechnen | 105 // 1.Ergebnisse Berechnen |
106 this.current.advance(super.identifier, context.getMeta()); | 106 this.current.advance(super.identifier, context.getMeta()); |
107 // 2. Ergebnisse Übergeben | 107 // 2. Ergebnisse Übergeben |
108 nextStep.putInputData(this.current.getInputData(), | 108 nextStep.putInputData(this.current.getInputData(), |
109 super.identifier); | 109 super.identifier); |
114 this.current.initialize(super.identifier, context.getMeta()); | 114 this.current.initialize(super.identifier, context.getMeta()); |
115 | 115 |
116 result = new ArtifactXMLUtilities() | 116 result = new ArtifactXMLUtilities() |
117 .createSuccessReport("Advance success", | 117 .createSuccessReport("Advance success", |
118 XMLUtils.newDocument()); | 118 XMLUtils.newDocument()); |
119 } catch (TransitionException e) { | 119 } catch (StateException e) { |
120 log.error(e, e); | 120 log.error(e, e); |
121 result = new ArtifactXMLUtilities() | 121 result = new ArtifactXMLUtilities() |
122 .createExceptionReport(e | 122 .createExceptionReport(e |
123 .getLocalizedMessage(), XMLUtils | 123 .getLocalizedMessage(), XMLUtils |
124 .newDocument()); | 124 .newDocument()); |
128 log.error(msg); | 128 log.error(msg); |
129 result = new ArtifactXMLUtilities().createExceptionReport( | 129 result = new ArtifactXMLUtilities().createExceptionReport( |
130 msg, XMLUtils.newDocument()); | 130 msg, XMLUtils.newDocument()); |
131 } | 131 } |
132 } else { | 132 } else { |
133 String msg = "Kein Transitionsschritt aktiviert."; | 133 String msg = "Kein State aktiviert."; |
134 log.error(msg); | 134 log.error(msg); |
135 result = new ArtifactXMLUtilities().createExceptionReport(msg, | 135 result = new ArtifactXMLUtilities().createExceptionReport(msg, |
136 XMLUtils.newDocument()); | 136 XMLUtils.newDocument()); |
137 } | 137 } |
138 } catch (Exception e) { | 138 } catch (Exception e) { |
149 try { | 149 try { |
150 this.current.initialize(super.identifier, context.getMeta()); | 150 this.current.initialize(super.identifier, context.getMeta()); |
151 result = new ArtifactXMLUtilities() | 151 result = new ArtifactXMLUtilities() |
152 .createSuccessReport("Initialize success", | 152 .createSuccessReport("Initialize success", |
153 XMLUtils.newDocument()); | 153 XMLUtils.newDocument()); |
154 } catch (TransitionException e) { | 154 } catch (StateException e) { |
155 log.error(e,e); | 155 log.error(e,e); |
156 result = new ArtifactXMLUtilities().createExceptionReport(e | 156 result = new ArtifactXMLUtilities().createExceptionReport(e |
157 .getLocalizedMessage(), XMLUtils.newDocument()); | 157 .getLocalizedMessage(), XMLUtils.newDocument()); |
158 } | 158 } |
159 return result; | 159 return result; |
160 } | 160 } |
161 | 161 |
162 protected String readTransitionName(Document document) { | 162 protected String readStateName(Document document) { |
163 String returnValue = Config.getStringXPath(document, | 163 String returnValue = Config.getStringXPath(document, |
164 "action/target/@name"); | 164 "action/target/@name"); |
165 return returnValue; | 165 return returnValue; |
166 } | 166 } |
167 | 167 |
203 log.warn(msg); | 203 log.warn(msg); |
204 result = new ArtifactXMLUtilities().createExceptionReport(msg, | 204 result = new ArtifactXMLUtilities().createExceptionReport(msg, |
205 XMLUtils.newDocument()); | 205 XMLUtils.newDocument()); |
206 } | 206 } |
207 } else { | 207 } else { |
208 String msg = "No Transition instantiated"; | 208 String msg = "No State instantiated"; |
209 log.warn(msg); | 209 log.warn(msg); |
210 result = new ArtifactXMLUtilities().createExceptionReport(msg, | 210 result = new ArtifactXMLUtilities().createExceptionReport(msg, |
211 XMLUtils.newDocument()); | 211 XMLUtils.newDocument()); |
212 } | 212 } |
213 } catch (TransitionException e) { | 213 } catch (StateException e) { |
214 log.error(e, e); | 214 log.error(e, e); |
215 result = new ArtifactXMLUtilities().createExceptionReport(e | 215 result = new ArtifactXMLUtilities().createExceptionReport(e |
216 .getLocalizedMessage(), XMLUtils.newDocument()); | 216 .getLocalizedMessage(), XMLUtils.newDocument()); |
217 } | 217 } |
218 return result; | 218 return result; |
236 if (localContext instanceof GNVArtifactContext) { | 236 if (localContext instanceof GNVArtifactContext) { |
237 GNVArtifactContext gnvContext = (GNVArtifactContext) localContext; | 237 GNVArtifactContext gnvContext = (GNVArtifactContext) localContext; |
238 Document doc = gnvContext.getConfig(); | 238 Document doc = gnvContext.getConfig(); |
239 Node artifactNode = this.getConfigurationFragment(doc); | 239 Node artifactNode = this.getConfigurationFragment(doc); |
240 | 240 |
241 NodeList transitionList = Config.getNodeSetXPath(artifactNode, | 241 NodeList stateList = Config.getNodeSetXPath(artifactNode, |
242 "transitions/transition"); | 242 "states/state"); |
243 this.transitions = new HashMap<String, Transition>(transitionList | 243 this.states = new HashMap<String, State>(stateList |
244 .getLength()); | 244 .getLength()); |
245 for (int i = 0; i < transitionList.getLength(); i++) { | 245 for (int i = 0; i < stateList.getLength(); i++) { |
246 Transition tmpTransition = TransitionFactory.getInstance() | 246 State tmpState = StateFactory.getInstance() |
247 .createTransition(transitionList.item(i)); | 247 .createState(stateList.item(i)); |
248 if (tmpTransition != null) { | 248 if (tmpState != null) { |
249 this.transitions.put(tmpTransition.getID(), tmpTransition); | 249 this.states.put(tmpState.getID(), tmpState); |
250 if (this.current == null) { | 250 if (this.current == null) { |
251 this.current = tmpTransition; | 251 this.current = tmpState; |
252 } | 252 } |
253 } | 253 } |
254 } | 254 } |
255 | 255 |
256 } | 256 } |
306 | 306 |
307 protected void createReachableStates(Element parent, Document document) { | 307 protected void createReachableStates(Element parent, Document document) { |
308 Element stateNode = xmlUtilities.createArtifactElement(document, | 308 Element stateNode = xmlUtilities.createArtifactElement(document, |
309 "reachable-states"); | 309 "reachable-states"); |
310 if (this.current != null) { | 310 if (this.current != null) { |
311 Iterator<String> states = this.current.reachableTransitions() | 311 Iterator<String> states = this.current.reachableStates() |
312 .iterator(); | 312 .iterator(); |
313 while (states.hasNext()) { | 313 while (states.hasNext()) { |
314 String value = states.next(); | 314 String value = states.next(); |
315 Element currentNode = xmlUtilities.createArtifactElement( | 315 Element currentNode = xmlUtilities.createArtifactElement( |
316 document, "state"); | 316 document, "state"); |
317 currentNode.setAttribute("name", value); | 317 currentNode.setAttribute("name", value); |
318 log.debug("Reachable State: " + value); | 318 log.debug("Reachable State: " + value); |
319 currentNode.setAttribute("description", transitions.get(value) | 319 currentNode.setAttribute("description", this.states.get(value) |
320 .getDescription()); | 320 .getDescription()); |
321 stateNode.appendChild(currentNode); | 321 stateNode.appendChild(currentNode); |
322 } | 322 } |
323 } | 323 } |
324 parent.appendChild(stateNode); | 324 parent.appendChild(stateNode); |
366 | 366 |
367 protected void createOutputs(Element parent, Document document) { | 367 protected void createOutputs(Element parent, Document document) { |
368 log.debug("GNVArtifactBase.createOutputs"); | 368 log.debug("GNVArtifactBase.createOutputs"); |
369 Element outputsNode = xmlUtilities.createArtifactElement(document, | 369 Element outputsNode = xmlUtilities.createArtifactElement(document, |
370 "outputs"); | 370 "outputs"); |
371 if (this.current instanceof OutputTransition) { | 371 if (this.current instanceof OutputState) { |
372 Collection<OutputMode> outputModes = ((OutputTransition) this.current) | 372 Collection<OutputMode> outputModes = ((OutputState) this.current) |
373 .getOutputModes(); | 373 .getOutputModes(); |
374 if (outputModes != null) { | 374 if (outputModes != null) { |
375 Iterator<OutputMode> it = outputModes.iterator(); | 375 Iterator<OutputMode> it = outputModes.iterator(); |
376 while (it.hasNext()) { | 376 while (it.hasNext()) { |
377 OutputMode outputMode = it.next(); | 377 OutputMode outputMode = it.next(); |
455 public void out(Document format, OutputStream outputStream, | 455 public void out(Document format, OutputStream outputStream, |
456 CallContext context) throws IOException { | 456 CallContext context) throws IOException { |
457 log.debug("TGNVArtifactBase.out"); | 457 log.debug("TGNVArtifactBase.out"); |
458 try { | 458 try { |
459 | 459 |
460 if (current != null && current instanceof OutputTransition) { | 460 if (current != null && current instanceof OutputState) { |
461 ((OutputTransition) current) | 461 ((OutputState) current) |
462 .out(format, this.parseInputData( | 462 .out(format, this.parseInputData( |
463 format, "/action/out/params/input"), | 463 format, "/action/out/params/input"), |
464 outputStream, super.identifier, context.getMeta()); | 464 outputStream, super.identifier, context.getMeta()); |
465 } | 465 } |
466 } catch (TransitionException e) { | 466 } catch (StateException e) { |
467 log.error(e, e); | 467 log.error(e, e); |
468 throw new IOException(e.getMessage()); | 468 throw new IOException(e.getMessage()); |
469 } | 469 } |
470 } | 470 } |
471 | 471 |