1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
package org.apache.shale.dialog.basic; |
19 | |
|
20 | |
import java.io.IOException; |
21 | |
import java.io.Serializable; |
22 | |
import java.util.ArrayList; |
23 | |
import java.util.List; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import javax.faces.FacesException; |
27 | |
import javax.faces.application.ViewHandler; |
28 | |
import javax.faces.component.UIViewRoot; |
29 | |
import javax.faces.context.ExternalContext; |
30 | |
import javax.faces.context.FacesContext; |
31 | |
import javax.faces.el.MethodBinding; |
32 | |
|
33 | |
import org.apache.commons.logging.Log; |
34 | |
import org.apache.commons.logging.LogFactory; |
35 | |
import org.apache.shale.dialog.Constants; |
36 | |
import org.apache.shale.dialog.DialogContext; |
37 | |
import org.apache.shale.dialog.DialogContextListener; |
38 | |
import org.apache.shale.dialog.DialogContextManager; |
39 | |
import org.apache.shale.dialog.base.AbstractDialogContext; |
40 | |
import org.apache.shale.dialog.basic.model.ActionState; |
41 | |
import org.apache.shale.dialog.basic.model.Dialog; |
42 | |
import org.apache.shale.dialog.basic.model.EndState; |
43 | |
import org.apache.shale.dialog.basic.model.State; |
44 | |
import org.apache.shale.dialog.basic.model.SubdialogState; |
45 | |
import org.apache.shale.dialog.basic.model.Transition; |
46 | |
import org.apache.shale.dialog.basic.model.ViewState; |
47 | |
|
48 | |
|
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
final class BasicDialogContext extends AbstractDialogContext |
59 | |
implements Serializable { |
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
private static final long serialVersionUID = 4858871161274193403L; |
69 | |
|
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
BasicDialogContext(DialogContextManager manager, Dialog dialog, |
81 | 0 | String id, String parentDialogId) { |
82 | |
|
83 | 0 | this.manager = manager; |
84 | 0 | this.dialog = dialog; |
85 | 0 | this.dialogName = dialog.getName(); |
86 | 0 | this.id = id; |
87 | 0 | this.parentDialogId = parentDialogId; |
88 | |
|
89 | 0 | if (log().isDebugEnabled()) { |
90 | 0 | log().debug("Constructor(id=" + id + ", name=" |
91 | |
+ dialogName + ")"); |
92 | |
} |
93 | |
|
94 | 0 | } |
95 | |
|
96 | |
|
97 | |
|
98 | |
|
99 | |
|
100 | |
|
101 | |
|
102 | |
|
103 | 0 | private boolean active = true; |
104 | |
|
105 | |
|
106 | |
|
107 | |
|
108 | |
|
109 | |
|
110 | 0 | private transient Dialog dialog = null; |
111 | |
|
112 | |
|
113 | |
|
114 | |
|
115 | |
|
116 | 0 | private String dialogName = null; |
117 | |
|
118 | |
|
119 | |
|
120 | |
|
121 | |
|
122 | |
|
123 | 0 | private transient Map dialogs = null; |
124 | |
|
125 | |
|
126 | |
|
127 | |
|
128 | |
|
129 | 0 | private String id = null; |
130 | |
|
131 | |
|
132 | |
|
133 | |
|
134 | |
|
135 | 0 | private DialogContextManager manager = null; |
136 | |
|
137 | |
|
138 | |
|
139 | |
|
140 | |
|
141 | |
|
142 | 0 | private transient Log log = null; |
143 | |
|
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | |
|
149 | |
|
150 | 0 | private String parentDialogId = null; |
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | |
|
157 | |
|
158 | 0 | private List positions = new ArrayList(); |
159 | |
|
160 | |
|
161 | |
|
162 | |
|
163 | |
|
164 | 0 | private boolean started = false; |
165 | |
|
166 | |
|
167 | |
|
168 | |
|
169 | |
|
170 | |
|
171 | |
|
172 | 0 | private transient String strategy = null; |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
|
178 | |
|
179 | 0 | private static final Object[] ACTION_STATE_PARAMETERS = new Object[0]; |
180 | |
|
181 | |
|
182 | |
|
183 | |
|
184 | |
|
185 | |
|
186 | 0 | private static final Class[] ACTION_STATE_SIGNATURE = new Class[0]; |
187 | |
|
188 | |
|
189 | |
|
190 | |
|
191 | |
|
192 | |
|
193 | |
private static final String START_OUTCOME = |
194 | |
"org.apache.shale.dialog.basic.START_OUTCOME"; |
195 | |
|
196 | |
|
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
public boolean isActive() { |
202 | |
|
203 | 0 | return this.active; |
204 | |
|
205 | |
} |
206 | |
|
207 | |
|
208 | |
|
209 | |
public Object getData() { |
210 | |
|
211 | 0 | synchronized (positions) { |
212 | 0 | int index = positions.size() - 1; |
213 | 0 | if (index < 0) { |
214 | 0 | return null; |
215 | |
} |
216 | 0 | Position position = (Position) positions.get(index); |
217 | 0 | return position.getData(); |
218 | 0 | } |
219 | |
|
220 | |
} |
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public void setData(Object data) { |
226 | |
|
227 | 0 | synchronized (positions) { |
228 | 0 | int index = positions.size() - 1; |
229 | 0 | if (index < 0) { |
230 | 0 | throw new IllegalStateException("Cannot set data when no positions are stacked"); |
231 | |
} |
232 | 0 | Position position = (Position) positions.get(index); |
233 | 0 | Object old = position.getData(); |
234 | 0 | if ((old != null) && (old instanceof DialogContextListener)) { |
235 | 0 | removeDialogContextListener((DialogContextListener) old); |
236 | |
} |
237 | 0 | position.setData(data); |
238 | 0 | if ((data != null) && (data instanceof DialogContextListener)) { |
239 | 0 | addDialogContextListener((DialogContextListener) data); |
240 | |
} |
241 | 0 | } |
242 | |
|
243 | 0 | } |
244 | |
|
245 | |
|
246 | |
|
247 | |
public String getId() { |
248 | |
|
249 | 0 | return this.id; |
250 | |
|
251 | |
} |
252 | |
|
253 | |
|
254 | |
|
255 | |
public String getName() { |
256 | |
|
257 | 0 | Position position = peek(); |
258 | 0 | if (position != null) { |
259 | 0 | return position.getDialog().getName(); |
260 | |
} else { |
261 | 0 | return null; |
262 | |
} |
263 | |
|
264 | |
} |
265 | |
|
266 | |
|
267 | |
|
268 | |
public Object getOpaqueState() { |
269 | |
|
270 | 0 | if ("top".equals(strategy())) { |
271 | 0 | if (log().isTraceEnabled()) { |
272 | 0 | log().trace("getOpaqueState<top> returns " + new TopState(peek().getState().getName(), positions.size())); |
273 | |
} |
274 | 0 | return new TopState(peek().getState().getName(), positions.size()); |
275 | 0 | } else if ("stack".equals(strategy())) { |
276 | 0 | if (log().isTraceEnabled()) { |
277 | 0 | log().trace("getOpaqueStrategy<stack> returns stack of " + positions.size()); |
278 | |
} |
279 | 0 | return positions; |
280 | |
} else { |
281 | 0 | if (log().isTraceEnabled()) { |
282 | 0 | log().trace("getOpaqueStrategy<none> returns nothing"); |
283 | |
} |
284 | 0 | return null; |
285 | |
} |
286 | |
|
287 | |
} |
288 | |
|
289 | |
|
290 | |
|
291 | |
public void setOpaqueState(Object opaqueState) { |
292 | |
|
293 | 0 | if ("top".equals(strategy())) { |
294 | 0 | TopState topState = (TopState) opaqueState; |
295 | 0 | if (log().isTraceEnabled()) { |
296 | 0 | log().trace("setOpaqueState<top> restores " + topState); |
297 | |
} |
298 | 0 | if (topState.stackDepth != positions.size()) { |
299 | 0 | throw new IllegalStateException("Restored stack depth expects " |
300 | |
+ positions.size() + " but is actually " |
301 | |
+ topState.stackDepth); |
302 | |
} |
303 | 0 | Position top = peek(); |
304 | 0 | String oldStateName = top.getState().getName(); |
305 | 0 | if (!oldStateName.equals(topState.stateName)) { |
306 | 0 | fireOnExit(oldStateName); |
307 | 0 | top.setState(top.getDialog().findState(topState.stateName)); |
308 | 0 | fireOnEntry(topState.stateName); |
309 | |
} |
310 | 0 | } else if ("stack".equals(strategy())) { |
311 | 0 | if (log().isTraceEnabled()) { |
312 | 0 | log().trace("setOpaqueState<stack> restores stack of " + ((List) opaqueState).size()); |
313 | |
} |
314 | 0 | List list = (List) opaqueState; |
315 | 0 | String oldStateName = peek().getState().getName(); |
316 | 0 | String newStateName = ((Position) list.get(list.size() - 1)).getState().getName(); |
317 | 0 | if (!oldStateName.equals(newStateName) || (list.size() != positions.size())) { |
318 | 0 | fireOnExit(oldStateName); |
319 | 0 | positions = list; |
320 | 0 | fireOnEntry(newStateName); |
321 | |
} |
322 | 0 | } else { |
323 | 0 | if (log().isTraceEnabled()) { |
324 | 0 | log().trace("setOpaqueState<none> restores nothing"); |
325 | |
} |
326 | |
; |
327 | |
} |
328 | |
|
329 | 0 | } |
330 | |
|
331 | |
|
332 | |
|
333 | |
public DialogContext getParent() { |
334 | |
|
335 | 0 | if (this.parentDialogId != null) { |
336 | 0 | DialogContext parent = manager.get(this.parentDialogId); |
337 | 0 | if (parent == null) { |
338 | 0 | throw new IllegalStateException("Dialog instance '" |
339 | |
+ parentDialogId + "' was associated with this instance '" |
340 | |
+ getId() + "' but is no longer available"); |
341 | |
} |
342 | 0 | return parent; |
343 | |
} else { |
344 | 0 | return null; |
345 | |
} |
346 | |
|
347 | |
} |
348 | |
|
349 | |
|
350 | |
|
351 | |
|
352 | |
|
353 | |
|
354 | |
public void advance(FacesContext context, String outcome) { |
355 | |
|
356 | 0 | if (!started) { |
357 | 0 | throw new IllegalStateException("Dialog instance '" |
358 | |
+ getId() + "' for dialog name '" |
359 | |
+ getName() + "' has not yet been started"); |
360 | |
} |
361 | |
|
362 | 0 | if (log().isDebugEnabled()) { |
363 | 0 | log().debug("advance(id=" + getId() + ", name=" + getName() |
364 | |
+ ", outcome=" + outcome + ")"); |
365 | |
} |
366 | |
|
367 | |
|
368 | |
|
369 | |
|
370 | 0 | if (outcome == null) { |
371 | 0 | if (log().isTraceEnabled()) { |
372 | 0 | log().trace("punt early since outcome is null"); |
373 | |
} |
374 | 0 | return; |
375 | |
} |
376 | |
|
377 | |
|
378 | |
|
379 | 0 | Position position = peek(); |
380 | 0 | if (!START_OUTCOME.equals(outcome)) { |
381 | 0 | transition(position, outcome); |
382 | |
} |
383 | 0 | State state = position.getState(); |
384 | 0 | String viewId = null; |
385 | 0 | boolean redirect = false; |
386 | |
|
387 | |
|
388 | |
|
389 | |
while (true) { |
390 | |
|
391 | 0 | if (state instanceof ActionState) { |
392 | 0 | ActionState astate = (ActionState) state; |
393 | 0 | if (log().isTraceEnabled()) { |
394 | 0 | log().trace("-->ActionState(method=" + astate.getMethod() + ")"); |
395 | |
} |
396 | |
try { |
397 | 0 | MethodBinding mb = context.getApplication(). |
398 | |
createMethodBinding(astate.getMethod(), ACTION_STATE_SIGNATURE); |
399 | 0 | outcome = (String) mb.invoke(context, ACTION_STATE_PARAMETERS); |
400 | 0 | } catch (Exception e) { |
401 | 0 | fireOnException(e); |
402 | 0 | } |
403 | 0 | transition(position, outcome); |
404 | 0 | state = position.getState(); |
405 | 0 | continue; |
406 | 0 | } else if (state instanceof EndState) { |
407 | 0 | if (log().isTraceEnabled()) { |
408 | 0 | log().trace("-->EndState()"); |
409 | |
} |
410 | 0 | pop(); |
411 | 0 | position = peek(); |
412 | 0 | if (position == null) { |
413 | 0 | stop(context); |
414 | |
} |
415 | 0 | viewId = ((EndState) state).getViewId(); |
416 | 0 | redirect = ((EndState) state).isRedirect(); |
417 | 0 | break; |
418 | 0 | } else if (state instanceof SubdialogState) { |
419 | 0 | SubdialogState sstate = (SubdialogState) state; |
420 | 0 | if (log().isTraceEnabled()) { |
421 | 0 | log().trace("-->SubdialogState(dialogName=" |
422 | |
+ sstate.getDialogName() + ")"); |
423 | |
} |
424 | 0 | Dialog subdialog = (Dialog) dialogs(context).get(sstate.getDialogName()); |
425 | 0 | if (subdialog == null) { |
426 | 0 | throw new IllegalStateException("Cannot find dialog definition '" |
427 | |
+ sstate.getDialogName() + "'"); |
428 | |
} |
429 | 0 | start(subdialog); |
430 | 0 | position = peek(); |
431 | 0 | state = position.getState(); |
432 | 0 | continue; |
433 | 0 | } else if (state instanceof ViewState) { |
434 | 0 | viewId = ((ViewState) state).getViewId(); |
435 | 0 | redirect = ((ViewState) state).isRedirect(); |
436 | 0 | if (log().isTraceEnabled()) { |
437 | 0 | log().trace("-->ViewState(viewId=" |
438 | |
+ ((ViewState) state).getViewId() |
439 | |
+ ",redirect=" + ((ViewState) state).isRedirect() |
440 | |
+ ")"); |
441 | 0 | } |
442 | |
break; |
443 | |
} else { |
444 | 0 | throw new IllegalStateException |
445 | |
("State '" + state.getName() |
446 | |
+ "' of dialog '" + position.getDialog().getName() |
447 | |
+ "' is of unknown type '" + state.getClass().getName() + "'"); |
448 | |
} |
449 | |
} |
450 | |
|
451 | |
|
452 | 0 | if (viewId == null) { |
453 | 0 | return; |
454 | |
} |
455 | 0 | if (log().isTraceEnabled()) { |
456 | 0 | log().trace("-->Navigate(viewId=" + viewId + ")"); |
457 | |
} |
458 | 0 | ViewHandler vh = context.getApplication().getViewHandler(); |
459 | 0 | if (redirect) { |
460 | 0 | String actionURL = vh.getActionURL(context, viewId); |
461 | 0 | if (actionURL.indexOf('?') < 0) { |
462 | 0 | actionURL += '?'; |
463 | 0 | } else { |
464 | 0 | actionURL += '&'; |
465 | |
} |
466 | 0 | actionURL += Constants.DIALOG_ID + "=" + this.id; |
467 | |
try { |
468 | 0 | ExternalContext econtext = context.getExternalContext(); |
469 | 0 | econtext.redirect(econtext.encodeActionURL(actionURL)); |
470 | 0 | context.responseComplete(); |
471 | 0 | } catch (IOException e) { |
472 | 0 | throw new FacesException("Cannot redirect to " + actionURL, e); |
473 | 0 | } |
474 | 0 | } else { |
475 | 0 | UIViewRoot view = vh.createView(context, viewId); |
476 | 0 | view.setViewId(viewId); |
477 | 0 | context.setViewRoot(view); |
478 | 0 | context.renderResponse(); |
479 | |
} |
480 | |
|
481 | 0 | } |
482 | |
|
483 | |
|
484 | |
|
485 | |
public void start(FacesContext context) { |
486 | |
|
487 | 0 | if (started) { |
488 | 0 | throw new IllegalStateException("Dialog instance '" |
489 | |
+ getId() + "' for dialog name '" |
490 | |
+ getName() + "' has already been started"); |
491 | |
} |
492 | 0 | started = true; |
493 | |
|
494 | 0 | if (log().isDebugEnabled()) { |
495 | 0 | log().debug("start(id=" + getId() + ", name=" |
496 | |
+ getName() + ")"); |
497 | |
} |
498 | |
|
499 | |
|
500 | 0 | fireOnStart(); |
501 | |
|
502 | |
|
503 | 0 | start(dialog); |
504 | |
|
505 | |
|
506 | |
|
507 | 0 | advance(context, START_OUTCOME); |
508 | |
|
509 | 0 | } |
510 | |
|
511 | |
|
512 | |
|
513 | |
public void stop(FacesContext context) { |
514 | |
|
515 | 0 | if (!started) { |
516 | 0 | throw new IllegalStateException("Dialog instance '" |
517 | |
+ getId() + "' for dialog name '" |
518 | |
+ getName() + "' has not yet been started"); |
519 | |
} |
520 | 0 | started = false; |
521 | |
|
522 | 0 | if (log().isDebugEnabled()) { |
523 | 0 | log().debug("stop(id=" + getId() + ", name=" |
524 | |
+ getName() + ")"); |
525 | |
} |
526 | |
|
527 | 0 | deactivate(); |
528 | 0 | manager.remove(this); |
529 | |
|
530 | |
|
531 | 0 | fireOnStop(); |
532 | |
|
533 | 0 | } |
534 | |
|
535 | |
|
536 | |
|
537 | |
|
538 | |
|
539 | |
|
540 | |
|
541 | |
|
542 | |
|
543 | |
|
544 | |
|
545 | |
void deactivate() { |
546 | |
|
547 | 0 | while (positions.size() > 0) { |
548 | 0 | pop(); |
549 | 0 | } |
550 | 0 | this.active = false; |
551 | |
|
552 | 0 | } |
553 | |
|
554 | |
|
555 | |
|
556 | |
|
557 | |
|
558 | |
|
559 | |
|
560 | |
|
561 | |
|
562 | |
|
563 | |
|
564 | |
|
565 | |
private Dialog dialog(FacesContext context) { |
566 | |
|
567 | 0 | if (this.dialog == null) { |
568 | 0 | this.dialog = (Dialog) dialogs(context).get(this.dialogName); |
569 | |
} |
570 | 0 | return this.dialog; |
571 | |
|
572 | |
} |
573 | |
|
574 | |
|
575 | |
|
576 | |
|
577 | |
|
578 | |
|
579 | |
|
580 | |
|
581 | |
|
582 | |
|
583 | |
|
584 | |
|
585 | |
private Map dialogs(FacesContext context) { |
586 | |
|
587 | |
|
588 | 0 | if (this.dialogs != null) { |
589 | 0 | return this.dialogs; |
590 | |
} |
591 | |
|
592 | |
|
593 | 0 | this.dialogs = (Map) |
594 | |
context.getExternalContext().getApplicationMap().get(Globals.DIALOGS); |
595 | 0 | if (this.dialogs != null) { |
596 | 0 | return this.dialogs; |
597 | |
} |
598 | |
|
599 | |
|
600 | |
|
601 | 0 | throw new IllegalStateException("Dialog configuration resources have not yet been processed"); |
602 | |
|
603 | |
} |
604 | |
|
605 | |
|
606 | |
|
607 | |
|
608 | |
|
609 | |
|
610 | |
private Log log() { |
611 | |
|
612 | 0 | if (log == null) { |
613 | 0 | log = LogFactory.getLog(BasicDialogContext.class); |
614 | |
} |
615 | 0 | return log; |
616 | |
|
617 | |
} |
618 | |
|
619 | |
|
620 | |
|
621 | |
|
622 | |
|
623 | |
|
624 | |
|
625 | |
|
626 | |
|
627 | |
private Position peek() { |
628 | |
|
629 | 0 | synchronized (positions) { |
630 | 0 | int index = positions.size() - 1; |
631 | 0 | if (index < 0) { |
632 | 0 | return null; |
633 | |
} |
634 | 0 | return (Position) positions.get(index); |
635 | 0 | } |
636 | |
|
637 | |
} |
638 | |
|
639 | |
|
640 | |
|
641 | |
|
642 | |
|
643 | |
|
644 | |
|
645 | |
|
646 | |
|
647 | |
|
648 | |
|
649 | |
private Position pop() { |
650 | |
|
651 | 0 | synchronized (positions) { |
652 | 0 | int index = positions.size() - 1; |
653 | 0 | if (index < 0) { |
654 | 0 | throw new IllegalStateException("No position to be popped"); |
655 | |
} |
656 | 0 | Object data = ((Position) positions.get(index)).getData(); |
657 | 0 | if ((data != null) && (data instanceof DialogContextListener)) { |
658 | 0 | removeDialogContextListener((DialogContextListener) data); |
659 | |
} |
660 | 0 | positions.remove(index); |
661 | 0 | if (index > 0) { |
662 | 0 | return (Position) positions.get(index - 1); |
663 | |
} else { |
664 | 0 | return null; |
665 | |
} |
666 | 0 | } |
667 | |
|
668 | |
} |
669 | |
|
670 | |
|
671 | |
|
672 | |
|
673 | |
|
674 | |
|
675 | |
|
676 | |
|
677 | |
private void push(Position position) { |
678 | |
|
679 | 0 | if (position == null) { |
680 | 0 | throw new IllegalArgumentException(); |
681 | |
} |
682 | 0 | Object data = position.getData(); |
683 | 0 | if ((data != null) && (data instanceof DialogContextListener)) { |
684 | 0 | addDialogContextListener((DialogContextListener) data); |
685 | |
} |
686 | 0 | synchronized (positions) { |
687 | 0 | positions.add(position); |
688 | 0 | } |
689 | |
|
690 | 0 | } |
691 | |
|
692 | |
|
693 | |
|
694 | |
|
695 | |
|
696 | |
|
697 | |
|
698 | |
|
699 | |
private void start(Dialog dialog) { |
700 | |
|
701 | |
|
702 | 0 | State state = dialog.findState(dialog.getStart()); |
703 | 0 | if (state == null) { |
704 | 0 | throw new IllegalStateException |
705 | |
("Cannot find starting state '" |
706 | |
+ dialog.getStart() |
707 | |
+ "' for dialog '" + dialog.getName() + "'"); |
708 | |
} |
709 | |
|
710 | |
|
711 | 0 | Object data = null; |
712 | |
try { |
713 | 0 | data = dialog.getDataClass().newInstance(); |
714 | 0 | } catch (Exception e) { |
715 | 0 | fireOnException(e); |
716 | 0 | } |
717 | |
|
718 | |
|
719 | 0 | push(new Position(dialog, state, data)); |
720 | |
|
721 | |
|
722 | 0 | fireOnEntry(state.getName()); |
723 | |
|
724 | 0 | } |
725 | |
|
726 | |
|
727 | |
|
728 | |
|
729 | |
|
730 | |
|
731 | |
private String strategy() { |
732 | |
|
733 | 0 | if (this.strategy == null) { |
734 | 0 | this.strategy = FacesContext.getCurrentInstance().getExternalContext().getInitParameter(Globals.STRATEGY); |
735 | 0 | if (this.strategy == null) { |
736 | 0 | this.strategy = "top"; |
737 | 0 | } else { |
738 | 0 | this.strategy = this.strategy.toLowerCase(); |
739 | |
} |
740 | |
} |
741 | 0 | return this.strategy; |
742 | |
|
743 | |
} |
744 | |
|
745 | |
|
746 | |
|
747 | |
|
748 | |
|
749 | |
|
750 | |
|
751 | |
|
752 | |
|
753 | |
private void transition(Position position, String outcome) { |
754 | |
|
755 | |
|
756 | |
|
757 | 0 | if (outcome == null) { |
758 | 0 | return; |
759 | |
} |
760 | |
|
761 | 0 | State current = position.getState(); |
762 | 0 | String fromStateId = current.getName(); |
763 | |
|
764 | |
|
765 | 0 | Transition transition = current.findTransition(outcome); |
766 | 0 | if (transition == null) { |
767 | 0 | transition = position.getDialog().findTransition(outcome); |
768 | |
} |
769 | 0 | if (transition == null) { |
770 | 0 | throw new IllegalStateException |
771 | |
("Cannot find transition '" + outcome |
772 | |
+ "' for state '" + fromStateId |
773 | |
+ "' of dialog '" + position.getDialog().getName() + "'"); |
774 | |
} |
775 | 0 | State next = position.getDialog().findState(transition.getTarget()); |
776 | 0 | if (next == null) { |
777 | 0 | throw new IllegalStateException |
778 | |
("Cannot find state '" + transition.getTarget() |
779 | |
+ "' for dialog '" + position.getDialog().getName() + "'"); |
780 | |
} |
781 | 0 | String toStateId = next.getName(); |
782 | 0 | position.setState(next); |
783 | |
|
784 | |
|
785 | |
|
786 | |
|
787 | |
|
788 | |
|
789 | 0 | fireOnExit(fromStateId); |
790 | |
|
791 | |
|
792 | 0 | fireOnTransition(fromStateId, toStateId); |
793 | |
|
794 | |
|
795 | 0 | fireOnEntry(toStateId); |
796 | |
|
797 | 0 | } |
798 | |
|
799 | |
|
800 | |
|
801 | |
|
802 | |
|
803 | |
|
804 | |
|
805 | |
|
806 | |
|
807 | |
public class TopState implements Serializable { |
808 | |
|
809 | |
|
810 | |
|
811 | |
|
812 | |
private static final long serialVersionUID = 1L; |
813 | |
|
814 | |
|
815 | |
|
816 | |
|
817 | |
|
818 | 0 | public TopState() { |
819 | |
; |
820 | 0 | } |
821 | |
|
822 | |
|
823 | |
|
824 | |
|
825 | |
|
826 | |
|
827 | |
|
828 | |
|
829 | 0 | public TopState(String stateName, int stackDepth) { |
830 | 0 | this.stateName = stateName; |
831 | 0 | this.stackDepth = stackDepth; |
832 | 0 | } |
833 | |
|
834 | |
|
835 | |
|
836 | |
|
837 | |
|
838 | |
|
839 | |
public String stateName; |
840 | |
|
841 | |
|
842 | |
|
843 | |
|
844 | |
|
845 | |
|
846 | |
|
847 | |
|
848 | |
public int stackDepth; |
849 | |
|
850 | |
|
851 | |
|
852 | |
|
853 | |
|
854 | |
public String toString() { |
855 | 0 | return "TopState[stateName=" + this.stateName |
856 | |
+ ", stackDepth=" + this.stackDepth + "]"; |
857 | |
} |
858 | |
|
859 | |
|
860 | |
|
861 | |
} |
862 | |
|
863 | |
|
864 | |
|
865 | |
} |