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 if (actionMethod.isAnnotationPresent(InitializeMethod.class)) {
96 final InitializeMethod initializeMethod = actionMethod
97 .getAnnotation(InitializeMethod.class);
98 final String methodName = initializeMethod.value();
99 this.invoke(methodName);
100 } else {
101 this.initialize();
102 }
103 }
104
105
106
107
108
109 protected void initialize() {
110 }
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126 public void invokePreRenderMethod(final Method actionMethod) {
127 if (actionMethod.isAnnotationPresent(PreRenderMethod.class)) {
128 final PreRenderMethod preRenderMethod = actionMethod
129 .getAnnotation(PreRenderMethod.class);
130 final String methodName = preRenderMethod.value();
131 this.invoke(methodName);
132 } else {
133 this.prerender();
134 }
135 }
136
137
138
139
140
141 protected void prerender() {
142 }
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158 public void invokePostRenderMethod(final Method actionMethod) {
159 if (actionMethod.isAnnotationPresent(PostRenderMethod.class)) {
160 final PostRenderMethod postRenderMethod = actionMethod
161 .getAnnotation(PostRenderMethod.class);
162 final String methodName = postRenderMethod.value();
163 this.invoke(methodName);
164 } else {
165 this.postrender();
166 }
167 }
168
169
170
171
172
173 protected void postrender() {
174 }
175
176
177
178
179
180
181
182
183 protected void invoke(final String methodName) {
184 final Method method = ClassUtil.getMethod(this.getClass(), methodName,
185 null);
186 MethodUtil.invoke(method, this, null);
187 }
188
189 }