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.interceptor.InterceptorUtils.getAction; |
19 | |
import static org.seasar.cubby.interceptor.InterceptorUtils.getActionClass; |
20 | |
import static org.seasar.cubby.interceptor.InterceptorUtils.getMethod; |
21 | |
|
22 | |
import java.lang.reflect.Method; |
23 | |
|
24 | |
import javax.servlet.http.HttpServletRequest; |
25 | |
|
26 | |
import org.aopalliance.intercept.MethodInterceptor; |
27 | |
import org.aopalliance.intercept.MethodInvocation; |
28 | |
import org.seasar.cubby.action.Action; |
29 | |
import org.seasar.cubby.validator.ValidationException; |
30 | |
import org.seasar.cubby.validator.ValidationProcessor; |
31 | |
|
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
public class ValidationInterceptor implements MethodInterceptor { |
40 | |
|
41 | |
|
42 | |
private ValidationProcessor validationProcessor; |
43 | |
|
44 | |
|
45 | |
private HttpServletRequest request; |
46 | |
|
47 | |
|
48 | |
|
49 | |
|
50 | 1 | public ValidationInterceptor() { |
51 | 1 | } |
52 | |
|
53 | |
|
54 | |
|
55 | |
|
56 | |
|
57 | |
|
58 | |
|
59 | |
public void setValidationProcessor( |
60 | |
final ValidationProcessor validationProcessor) { |
61 | 1 | this.validationProcessor = validationProcessor; |
62 | 1 | } |
63 | |
|
64 | |
|
65 | |
|
66 | |
|
67 | |
|
68 | |
|
69 | |
|
70 | |
public void setRequest(final HttpServletRequest request) { |
71 | 1 | this.request = request; |
72 | 1 | } |
73 | |
|
74 | |
|
75 | |
|
76 | |
|
77 | |
|
78 | |
|
79 | |
|
80 | |
public Object invoke(final MethodInvocation invocation) throws Throwable { |
81 | 2 | final Action action = getAction(invocation); |
82 | 2 | final Class<? extends Action> actionClass = getActionClass(invocation); |
83 | 2 | final Method method = getMethod(invocation); |
84 | |
try { |
85 | 2 | validationProcessor.process(request, action, actionClass, method); |
86 | 2 | return invocation.proceed(); |
87 | 0 | } catch (final ValidationException e) { |
88 | 0 | return validationProcessor.handleValidationException(e, request, |
89 | |
action, method); |
90 | |
} |
91 | |
} |
92 | |
|
93 | |
} |