comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/FLYSArtifact.java @ 140:43f03f6047b9

Implemented the step-back part of the advance() operation. flys-artifacts/trunk@1522 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Mon, 21 Mar 2011 08:17:15 +0000
parents ebb1cb69d847
children fc694a43a7e5
comparison
equal deleted inserted replaced
139:05207cc4a084 140:43f03f6047b9
180 * @param context The CallContext. 180 * @param context The CallContext.
181 * 181 *
182 * @return a document that contains a SUCCESS or FAILURE message. 182 * @return a document that contains a SUCCESS or FAILURE message.
183 */ 183 */
184 public Document advance(Document target, CallContext context) { 184 public Document advance(Document target, CallContext context) {
185 logger.info("FLYSArtifact.advance()");
186
187 Document doc = XMLUtils.newDocument(); 185 Document doc = XMLUtils.newDocument();
188 186
189 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator( 187 XMLUtils.ElementCreator ec = new XMLUtils.ElementCreator(
190 doc, 188 doc,
191 ArtifactNamespaceContext.NAMESPACE_URI, 189 ArtifactNamespaceContext.NAMESPACE_URI,
194 Element result = ec.create("result"); 192 Element result = ec.create("result");
195 193
196 String targetState = XMLUtils.xpathString( 194 String targetState = XMLUtils.xpathString(
197 target, XPATH_ADVANCE_TARGET, ArtifactNamespaceContext.INSTANCE); 195 target, XPATH_ADVANCE_TARGET, ArtifactNamespaceContext.INSTANCE);
198 196
197 logger.info("FLYSArtifact.advance() to '" + targetState + "'");
198
199 if (isStateReachable(targetState, context)) { 199 if (isStateReachable(targetState, context)) {
200 logger.debug("Advance: Step forward."); 200 logger.info("Advance: Step forward");
201 201
202 Vector<String> prev = getPreviousStateIds(); 202 Vector<String> prev = getPreviousStateIds();
203 prev.add(getCurrentStateId()); 203 prev.add(getCurrentStateId());
204 204
205 setCurrentStateId(targetState); 205 setCurrentStateId(targetState);
206 206
207 return describe(target, context); 207 return describe(target, context);
208 } 208 }
209 209 else if (isPreviousState(targetState, context)) {
210 // TODO IMPLEMENT STEP BACK! 210 logger.info("Advance: Step back to");
211
212 Vector<String> prevs = getPreviousStateIds();
213 int targetIdx = prevs.indexOf(targetState);
214 int start = prevs.size() - 1;
215
216 for (int i = start; i >= targetIdx; i--) {
217 String prev = prevs.get(i);
218 logger.debug("Remove state id '" + prev + "'");
219 prevs.remove(prev);
220 }
221
222 setCurrentStateId(targetState);
223
224 return describe(target, context);
225 }
211 226
212 logger.warn("Advance: Cannot advance to '" + targetState + "'"); 227 logger.warn("Advance: Cannot advance to '" + targetState + "'");
213 ec.addAttr(result, "type", OPERATION_FAILED, true); 228 ec.addAttr(result, "type", OPERATION_FAILED, true);
214 229
215 doc.appendChild(result); 230 doc.appendChild(result);
352 * 367 *
353 * @return the filled state. 368 * @return the filled state.
354 */ 369 */
355 protected State fillState(State state) { 370 protected State fillState(State state) {
356 Map<String, StateData> stateData = state.getData(); 371 Map<String, StateData> stateData = state.getData();
372
373 if (stateData == null) {
374 return state;
375 }
376
357 Set<String> keys = stateData.keySet(); 377 Set<String> keys = stateData.keySet();
358 378
359 for (String key: keys) { 379 for (String key: keys) {
360 StateData tmp = getData(key); 380 StateData tmp = getData(key);
361 381
392 TransitionEngine tEngine = (TransitionEngine) flysContext.get( 412 TransitionEngine tEngine = (TransitionEngine) flysContext.get(
393 FLYSContext.TRANSITION_ENGINE_KEY); 413 FLYSContext.TRANSITION_ENGINE_KEY);
394 414
395 return tEngine.isStateReachable(stateId, currentState, sEngine); 415 return tEngine.isStateReachable(stateId, currentState, sEngine);
396 } 416 }
417
418
419 /**
420 * Determines if the state with the identifier <i>stateId</i> is a previous
421 * state of the current state.
422 *
423 * @param stateId The target state identifier.
424 * @param context The context object.
425 */
426 protected boolean isPreviousState(String stateId, Object context) {
427 logger.debug("Determine if the state '" + stateId + "' is old.");
428
429 Vector<String> prevs = getPreviousStateIds();
430 if (prevs.contains(stateId)) {
431 return true;
432 }
433
434 return false;
435 }
397 } 436 }
398 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 437 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org