1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.cubby.action;
17
18 import java.lang.reflect.Method;
19 import java.util.Map;
20
21 import org.seasar.framework.util.ClassUtil;
22 import org.seasar.framework.util.MethodUtil;
23
24
25
26
27
28
29
30
31
32
33
34 public abstract class Action {
35
36
37 protected ActionErrors errors;
38
39
40 protected Map<String, Object> flash;
41
42
43
44
45
46
47 public ActionErrors getErrors() {
48 return errors;
49 }
50
51
52
53
54
55
56
57 public void setErrors(final ActionErrors errors) {
58 this.errors = errors;
59 }
60
61
62
63
64
65
66 public Map<String, Object> getFlash() {
67 return flash;
68 }
69
70
71
72
73
74
75
76 public void setFlash(final Map<String, Object> flash) {
77 this.flash = flash;
78 }
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94 public void invokeInitializeMethod(final Method actionMethod) {
95 this.initialize();
96 if (actionMethod.isAnnotationPresent(InitializeMethod.class)) {
97 final InitializeMethod initializeMethod = actionMethod
98 .getAnnotation(InitializeMethod.class);
99 final String methodName = initializeMethod.value();
100 this.invoke(methodName);
101 } else {
102 this.initialize();
103 }
104 }
105
106
107
108
109
110 protected void initialize() {
111 }
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127 public void invokePreRenderMethod(final Method actionMethod) {
128 if (actionMethod.isAnnotationPresent(PreRenderMethod.class)) {
129 final PreRenderMethod preRenderMethod = actionMethod
130 .getAnnotation(PreRenderMethod.class);
131 final String methodName = preRenderMethod.value();
132 this.invoke(methodName);
133 } else {
134 this.prerender();
135 }
136 }
137
138
139
140
141
142 protected void prerender() {
143 }
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159 public void invokePostRenderMethod(final Method actionMethod) {
160 if (actionMethod.isAnnotationPresent(PostRenderMethod.class)) {
161 final PostRenderMethod postRenderMethod = actionMethod
162 .getAnnotation(PostRenderMethod.class);
163 final String methodName = postRenderMethod.value();
164 this.invoke(methodName);
165 } else {
166 this.postrender();
167 }
168 }
169
170
171
172
173
174 protected void postrender() {
175 }
176
177
178
179
180
181
182
183
184 protected void invoke(final String methodName) {
185 final Method method = ClassUtil.getMethod(this.getClass(), methodName,
186 null);
187 MethodUtil.invoke(method, this, null);
188 }
189
190 }