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