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 final Object invoke(MethodInvocation methodInvocation)
42 throws Throwable {
43
44 Object returnValue = before(methodInvocation);
45
46 if (returnValue != null) {
47 if (returnValue == nullResult) {
48 return null;
49 }
50 else {
51 return returnValue;
52 }
53 }
54
55 try {
56 if (nextMethodInterceptor != null) {
57 returnValue = nextMethodInterceptor.invoke(methodInvocation);
58 }
59 else {
60 returnValue = methodInvocation.proceed();
61 }
62
63 afterReturning(methodInvocation, returnValue);
64 }
65 catch (Throwable throwable) {
66 afterThrowing(methodInvocation, throwable);
67
68 throw throwable;
69 }
70
71 return returnValue;
72 }
73
74 public void setNextMethodInterceptor(
75 MethodInterceptor nextMethodInterceptor) {
76
77 this.nextMethodInterceptor = nextMethodInterceptor;
78 }
79
80 protected MethodInterceptor nextMethodInterceptor;
81 protected Object nullResult = new Object();
82
83 }