2009/05/20 - Apache Shale has been retired.
For more information, please explore the Attic.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.shale.test.mock;
19
20 import java.util.HashMap;
21 import java.util.Map;
22
23 import javax.faces.application.NavigationHandler;
24 import javax.faces.application.ViewHandler;
25 import javax.faces.component.UIViewRoot;
26 import javax.faces.context.FacesContext;
27
28 /***
29 * <p>Mock implementation of <code>NavigationHandler</code>.</p>
30 *
31 * $Id$
32 */
33
34 public class MockNavigationHandler extends NavigationHandler {
35
36
37
38
39 /***
40 * <p>Construct a default instance.</p>
41 */
42 public MockNavigationHandler() {
43 }
44
45
46
47
48
49 /***
50 * <p>Add a outcome-viewId pair to the destinations map.</p>
51 *
52 * @param outcome Logical outcome string
53 * @param viewId Destination view identifier
54 */
55 public void addDestination(String outcome, String viewId) {
56
57 destinations.put(outcome, viewId);
58
59 }
60
61
62
63
64
65 /***
66 * <p>Set of destination view ids, keyed by logical outcome String
67 * that will cause navigation to that view id.</p>
68 */
69 private Map destinations = new HashMap();
70
71
72
73
74
75 /***
76 * <p>Process the specified navigation request.</p>
77 *
78 * @param context <code>FacesContext</code> for the current request
79 * @param action Action method being executed
80 * @param outcome Logical outcome from this action method
81 */
82 public void handleNavigation(FacesContext context,
83 String action, String outcome) {
84
85
86 String viewId = (String) destinations.get(outcome);
87 if (viewId != null) {
88 UIViewRoot view = getViewHandler(context).createView(context, viewId);
89 context.setViewRoot(view);
90 }
91
92 }
93
94
95
96
97
98 /***
99 * <p>Return the <code>ViewHandler</code> instance for this application.</p>
100 *
101 * @param context <code>FacesContext</code> for the current request
102 */
103 private ViewHandler getViewHandler(FacesContext context) {
104
105 return context.getApplication().getViewHandler();
106
107 }
108
109
110 }