1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.seasar.cubby.interceptor; |
17 | |
|
18 | |
import static org.seasar.cubby.CubbyConstants.*; |
19 | |
import static org.seasar.cubby.interceptor.InterceptorUtils.getAction; |
20 | |
import static org.seasar.cubby.interceptor.InterceptorUtils.getActionClass; |
21 | |
import static org.seasar.cubby.interceptor.InterceptorUtils.getMethod; |
22 | |
|
23 | |
import java.lang.reflect.Method; |
24 | |
import java.util.Map; |
25 | |
|
26 | |
import javax.servlet.http.HttpServletRequest; |
27 | |
|
28 | |
import org.aopalliance.intercept.MethodInterceptor; |
29 | |
import org.aopalliance.intercept.MethodInvocation; |
30 | |
import org.seasar.cubby.action.Action; |
31 | |
import org.seasar.cubby.action.ActionResult; |
32 | |
import org.seasar.cubby.controller.RequestParameterBinder; |
33 | |
import org.seasar.cubby.util.CubbyUtils; |
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | 1 | public class InitializeInterceptor implements MethodInterceptor { |
43 | |
|
44 | |
|
45 | |
private HttpServletRequest request; |
46 | |
|
47 | |
|
48 | |
private RequestParameterBinder requestParameterBinder; |
49 | |
|
50 | |
|
51 | |
|
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
public void setRequest(final HttpServletRequest request) { |
57 | 1 | this.request = request; |
58 | 1 | } |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | |
public void setRequestParameterBinder( |
67 | |
final RequestParameterBinder requestParameterBinder) { |
68 | 1 | this.requestParameterBinder = requestParameterBinder; |
69 | 1 | } |
70 | |
|
71 | |
|
72 | |
|
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
|
81 | |
|
82 | |
|
83 | |
|
84 | |
public Object invoke(final MethodInvocation invocation) throws Throwable { |
85 | 2 | final Map<String, Object[]> parameterMap = CubbyUtils.getAttribute( |
86 | |
request, ATTR_PARAMS); |
87 | |
|
88 | 2 | final Action action = getAction(invocation); |
89 | 2 | final Class<? extends Action> actionClass = getActionClass(invocation); |
90 | 2 | final Method method = getMethod(invocation); |
91 | 2 | action.invokeInitializeMethod(method); |
92 | 2 | final Object form = CubbyUtils.getFormBean(action, actionClass, method); |
93 | 2 | if (form != null) { |
94 | 2 | requestParameterBinder.bind(parameterMap, form, actionClass, method); |
95 | |
} |
96 | |
|
97 | 2 | final ActionResult result = (ActionResult) invocation.proceed(); |
98 | 2 | return result; |
99 | |
} |
100 | |
|
101 | |
} |