1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.seasar.cubby.action;
18
19 import java.lang.reflect.InvocationTargetException;
20 import java.lang.reflect.Method;
21 import java.util.Map;
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 public void invokeInitializeMethod(final Method actionMethod) {
92 if (actionMethod.isAnnotationPresent(InitializeMethod.class)) {
93 final InitializeMethod initializeMethod = actionMethod
94 .getAnnotation(InitializeMethod.class);
95 final String methodName = initializeMethod.value();
96 this.invoke(methodName);
97 } else {
98 this.initialize();
99 }
100 }
101
102
103
104
105
106 protected void initialize() {
107 }
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122 public void invokePreRenderMethod(final Method actionMethod) {
123 if (actionMethod.isAnnotationPresent(PreRenderMethod.class)) {
124 final PreRenderMethod preRenderMethod = actionMethod
125 .getAnnotation(PreRenderMethod.class);
126 final String methodName = preRenderMethod.value();
127 this.invoke(methodName);
128 } else {
129 this.prerender();
130 }
131 }
132
133
134
135
136
137 protected void prerender() {
138 }
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 public void invokePostRenderMethod(final Method actionMethod) {
154 if (actionMethod.isAnnotationPresent(PostRenderMethod.class)) {
155 final PostRenderMethod postRenderMethod = actionMethod
156 .getAnnotation(PostRenderMethod.class);
157 final String methodName = postRenderMethod.value();
158 this.invoke(methodName);
159 } else {
160 this.postrender();
161 }
162 }
163
164
165
166
167
168 protected void postrender() {
169 }
170
171
172
173
174
175
176
177 protected void invoke(final String methodName) {
178 try {
179 final Method method = this.getClass().getMethod(methodName);
180 method.invoke(this);
181 } catch (final NoSuchMethodException e) {
182 throw new ActionException(e);
183 } catch (final IllegalAccessException e) {
184 throw new ActionException(e);
185 } catch (final InvocationTargetException e) {
186 throw new ActionException(e);
187 }
188 }
189
190 }