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