comparison gnv-artifacts/src/main/java/de/intevation/gnv/artifacts/GNVArtifactBase.java @ 337:a887074460b6

Last Step of the Refactoring Work on the Transition Model. Splitted Businesslogic between States and Transitions. Splitted the ConfigurationElements of State and Transition in several XML-Fragments. gnv-artifacts/trunk@403 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Tue, 08 Dec 2009 13:38:21 +0000
parents e964a3d8f7bc
children 2f7a28f211c7
comparison
equal deleted inserted replaced
336:1b9ca0f2d498 337:a887074460b6
3 */ 3 */
4 package de.intevation.gnv.artifacts; 4 package de.intevation.gnv.artifacts;
5 5
6 import java.io.IOException; 6 import java.io.IOException;
7 import java.io.OutputStream; 7 import java.io.OutputStream;
8 import java.util.ArrayList;
8 import java.util.Collection; 9 import java.util.Collection;
9 import java.util.HashMap; 10 import java.util.HashMap;
10 import java.util.Iterator; 11 import java.util.Iterator;
11 import java.util.Map; 12 import java.util.Map;
12 13
32 import de.intevation.gnv.state.OutputMode; 33 import de.intevation.gnv.state.OutputMode;
33 import de.intevation.gnv.state.OutputState; 34 import de.intevation.gnv.state.OutputState;
34 import de.intevation.gnv.state.State; 35 import de.intevation.gnv.state.State;
35 import de.intevation.gnv.state.StateFactory; 36 import de.intevation.gnv.state.StateFactory;
36 import de.intevation.gnv.state.exception.StateException; 37 import de.intevation.gnv.state.exception.StateException;
38 import de.intevation.gnv.transition.Transition;
39 import de.intevation.gnv.transition.TransitionFactory;
37 import de.intevation.gnv.utils.ArtifactXMLUtilities; 40 import de.intevation.gnv.utils.ArtifactXMLUtilities;
38 41
39 /** 42 /**
40 * @author Tim Englich <tim.englich@intevation.de> 43 * @author Tim Englich <tim.englich@intevation.de>
41 * 44 *
69 72
70 /** 73 /**
71 * The States that can be used 74 * The States that can be used
72 */ 75 */
73 protected Map<String, State> states = null; 76 protected Map<String, State> states = null;
77
78 /**
79 * The Transitions which can switch between the different States.
80 */
81 protected Collection<Transition> transitions = null;
74 82
75 /** 83 /**
76 * The Name of the Artifact 84 * The Name of the Artifact
77 */ 85 */
78 protected String name = null; 86 protected String name = null;
96 Document result = XMLUtils.newDocument(); 104 Document result = XMLUtils.newDocument();
97 try { 105 try {
98 if (this.current != null) { 106 if (this.current != null) {
99 String stateName = this.readStateName(target); 107 String stateName = this.readStateName(target);
100 log.debug("Statename: " + stateName); 108 log.debug("Statename: " + stateName);
101 if (this.current.isStateReachable(stateName)) { 109 if (this.isStateCurrentlyReachable(stateName)) {
102 try { 110 try {
103 State nextStep = this.states 111 State nextStep = this.states
104 .get(stateName); 112 .get(stateName);
105 // 1.Ergebnisse Berechnen 113 // 1.Ergebnisse Berechnen
106 this.current.advance(super.identifier, context.getMeta()); 114 this.current.advance(super.identifier, context.getMeta());
142 } 150 }
143 return result; 151 return result;
144 } 152 }
145 153
146 154
155 private boolean isStateCurrentlyReachable(String stateid){
156 log.debug("GNVArtifactBase.isStateCurrentlyReachable "+stateid);
157 Iterator<Transition> it = this.transitions.iterator();
158 String from = this.current.getID();
159 while (it.hasNext()){
160 Transition transition = it.next();
161 if (transition.getFrom().equals(from)){
162 if (transition.getTo().equals(stateid) && transition.isValid(this.current)){
163 return true;
164 }
165 }
166 }
167 return false;
168 }
169
147 public Document initialize (CallContext context) { 170 public Document initialize (CallContext context) {
148 Document result = XMLUtils.newDocument(); 171 Document result = XMLUtils.newDocument();
149 try { 172 try {
150 this.current.initialize(super.identifier, context.getMeta()); 173 this.current.initialize(super.identifier, context.getMeta());
151 result = new ArtifactXMLUtilities() 174 result = new ArtifactXMLUtilities()
250 if (this.current == null) { 273 if (this.current == null) {
251 this.current = tmpState; 274 this.current = tmpState;
252 } 275 }
253 } 276 }
254 } 277 }
278
279 NodeList transitionList = Config.getNodeSetXPath(artifactNode,
280 "states/transition");
281 this.transitions = new ArrayList<Transition>(transitionList.getLength());
282 for (int i = 0; i < transitionList.getLength(); i++) {
283 Transition tmpTransition = TransitionFactory.getInstance()
284 .createTransition(transitionList.item(i));
285 if (tmpTransition != null) {
286 this.transitions.add(tmpTransition);
287 }
288 }
255 289
256 } 290 }
257 } 291 }
258 292
259 293
306 340
307 protected void createReachableStates(Element parent, Document document) { 341 protected void createReachableStates(Element parent, Document document) {
308 Element stateNode = xmlUtilities.createArtifactElement(document, 342 Element stateNode = xmlUtilities.createArtifactElement(document,
309 "reachable-states"); 343 "reachable-states");
310 if (this.current != null) { 344 if (this.current != null) {
311 Iterator<String> states = this.current.reachableStates() 345 Iterator<Transition> transitions = this.transitions.iterator();
312 .iterator(); 346 while (transitions.hasNext()) {
313 while (states.hasNext()) { 347 Transition tmpTransition = transitions.next();
314 String value = states.next(); 348 if (tmpTransition.getFrom().equals(current.getID()) &&
315 Element currentNode = xmlUtilities.createArtifactElement( 349 tmpTransition.isValid(this.current)){
316 document, "state"); 350 Element currentNode = xmlUtilities.createArtifactElement(
317 currentNode.setAttribute("name", value); 351 document, "state");
318 log.debug("Reachable State: " + value); 352 currentNode.setAttribute("name", tmpTransition.getTo());
319 currentNode.setAttribute("description", this.states.get(value) 353 log.debug("Reachable State: " + tmpTransition.getTo());
320 .getDescription()); 354 currentNode.setAttribute("description",
321 stateNode.appendChild(currentNode); 355 this.states.get(tmpTransition.getTo())
356 .getDescription());
357 stateNode.appendChild(currentNode);
358 }
322 } 359 }
323 } 360 }
324 parent.appendChild(stateNode); 361 parent.appendChild(stateNode);
325 } 362 }
326 363

http://dive4elements.wald.intevation.org