1
14
15 package com.liferay.portal.spring.aop;
16
17 import org.aopalliance.intercept.MethodInterceptor;
18 import org.aopalliance.intercept.MethodInvocation;
19
20
26 public abstract class ChainableMethodAdvice implements MethodInterceptor {
27
28 public void afterReturning(MethodInvocation methodInvocation, Object result)
29 throws Throwable {
30 }
31
32 public void afterThrowing(
33 MethodInvocation methodInvocation, Throwable throwable)
34 throws Throwable {
35 }
36
37 public Object before(MethodInvocation methodInvocation) throws Throwable {
38 return null;
39 }
40
41 public void duringFinally(MethodInvocation methodInvocation) {
42 }
43
44 public final Object invoke(MethodInvocation methodInvocation)
45 throws Throwable {
46
47 Object returnValue = before(methodInvocation);
48
49 if (returnValue != null) {
50 if (returnValue == nullResult) {
51 return null;
52 }
53 else {
54 return returnValue;
55 }
56 }
57
58 try {
59 if (nextMethodInterceptor != null) {
60 returnValue = nextMethodInterceptor.invoke(methodInvocation);
61 }
62 else {
63 returnValue = methodInvocation.proceed();
64 }
65
66 afterReturning(methodInvocation, returnValue);
67 }
68 catch (Throwable throwable) {
69 afterThrowing(methodInvocation, throwable);
70
71 throw throwable;
72 }
73 finally {
74 duringFinally(methodInvocation);
75 }
76
77 return returnValue;
78 }
79
80 public void setNextMethodInterceptor(
81 MethodInterceptor nextMethodInterceptor) {
82
83 this.nextMethodInterceptor = nextMethodInterceptor;
84 }
85
86 protected MethodInterceptor nextMethodInterceptor;
87 protected Object nullResult = new Object();
88
89 }