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.usecases.view;
19
20 import java.util.Map;
21 import org.apache.shale.view.AbstractViewController;
22
23 /***
24 * <p>Test implementation of <code>Viewcontroller</code> for use by
25 * <code>ViewControllerTestCase</code>. Event history is accumulated
26 * under a request scope attribute named by symbolic constant
27 * <code>ATTRIBUTES</code>.</p>
28 */
29 public class TestViewController extends AbstractViewController {
30
31 /*** Creates a new instance of TestViewController */
32 public TestViewController() {
33 }
34
35
36 public static final String ATTRIBUTE =
37 "org.apache.shale.usecases.systest.TestViewController.EVENTS";
38
39
40
41
42
43 /***
44 * <p>Return the accumuated history string.</p>
45 */
46 public String getText() {
47 String history = (String) getExternalContext().getRequestMap().get(ATTRIBUTE);
48 if (history == null) {
49 history = "";
50 }
51 return history;
52 }
53
54
55
56
57
58 /***
59 * <p>Do-nothing submit method.</p>
60 */
61 public String submit() {
62 event("submit");
63 return null;
64 }
65
66
67
68
69
70 public void init() {
71 event("init");
72 }
73
74
75 public void preprocess() {
76 event("preprocess");
77 }
78
79
80 public void prerender() {
81 event("prerender");
82 }
83
84
85 public void destroy() {
86 event("destroy");
87 }
88
89
90
91
92
93 private Map map = null;
94
95
96 /***
97 * <p>Record the specified event, a slash, the state of the postback flag,
98 * and another slash.</p>
99 */
100 private void event(String event) {
101 System.out.println("TestViewController.event(" + event + "," + isPostBack() + ")");
102 if ("init".equals(event) || "destroy".equals(event)) {
103 try {
104 throw new IllegalArgumentException("Trace source of event '" + event + "'");
105 } catch (IllegalArgumentException e) {
106 e.printStackTrace();
107 }
108 }
109 if (map == null) {
110 map = getExternalContext().getRequestMap();
111 }
112 String history = (String) map.get(ATTRIBUTE);
113 if (history == null) {
114 history = "";
115 }
116 map.put(ATTRIBUTE, history + event + "/" + isPostBack() + "/");
117 }
118
119
120
121 }