1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.seasar.tuigwaa.logic.aop;
17
18 import org.aopalliance.intercept.MethodInterceptor;
19 import org.aopalliance.intercept.MethodInvocation;
20
21 public class MethodDecorateInterceptorImpl implements MethodInterceptor,
22 MethodDecorateInterceptor {
23
24 private MethodRegister register;
25
26 public void setRegister(MethodRegister register) {
27 this.register = register;
28 }
29
30 public Object invoke(MethodInvocation invocation) throws Throwable {
31 MethodInvoker[] beforeMethodInvokers = register.getBeforeMethodInvokers(invocation);
32 MethodInvoker[] afterMethodInvokers = register.getAfterMethodInvokers(invocation);
33 MethodInvoker delegateInvoker = register.getDelegateMethodInvoker(invocation);
34 Object ret = null;
35
36 invoke(beforeMethodInvokers, invocation);
37 if(delegateInvoker != null){
38 ret = invoke(delegateInvoker, invocation);
39 }else{
40 ret = invocation.proceed();
41 }
42 invoke(afterMethodInvokers, invocation);
43 return ret;
44 }
45
46 private void invoke(MethodInvoker[] invokers, MethodInvocation invocation){
47 if(invokers==null){
48 return;
49 }
50 for(int i=0; i<invokers.length; i++){
51 invoke(invokers[i], invocation);
52 }
53 }
54
55 private Object invoke(MethodInvoker invoker, MethodInvocation invocation){
56 return invoker.invoke(invocation.getArguments());
57 }
58 }