001
014
015 package com.liferay.portal.spring.aop;
016
017 import org.aopalliance.intercept.MethodInterceptor;
018 import org.aopalliance.intercept.MethodInvocation;
019
020
024 public abstract class ChainableMethodAdvice implements MethodInterceptor {
025
026 public void afterReturning(MethodInvocation methodInvocation, Object result)
027 throws Throwable {
028 }
029
030 public void afterThrowing(
031 MethodInvocation methodInvocation, Throwable throwable)
032 throws Throwable {
033 }
034
035 public Object before(MethodInvocation methodInvocation) throws Throwable {
036 return null;
037 }
038
039 public void duringFinally(MethodInvocation methodInvocation) {
040 }
041
042 @Override
043 public Object invoke(MethodInvocation methodInvocation) throws Throwable {
044 Object returnValue = before(methodInvocation);
045
046 if (returnValue != null) {
047 if (returnValue == nullResult) {
048 return null;
049 }
050 else {
051 return returnValue;
052 }
053 }
054
055 try {
056 returnValue = methodInvocation.proceed();
057
058 afterReturning(methodInvocation, returnValue);
059 }
060 catch (Throwable throwable) {
061 afterThrowing(methodInvocation, throwable);
062
063 throw throwable;
064 }
065 finally {
066 duringFinally(methodInvocation);
067 }
068
069 return returnValue;
070 }
071
072 public void setNextMethodInterceptor(
073 MethodInterceptor nextMethodInterceptor) {
074
075 this.nextMethodInterceptor = nextMethodInterceptor;
076 }
077
078 protected void setServiceBeanAopCacheManager(
079 ServiceBeanAopCacheManager serviceBeanAopCacheManager) {
080
081 if (this.serviceBeanAopCacheManager != null) {
082 return;
083 }
084
085 this.serviceBeanAopCacheManager = serviceBeanAopCacheManager;
086 }
087
088 protected MethodInterceptor nextMethodInterceptor;
089 protected Object nullResult = new Object();
090 protected ServiceBeanAopCacheManager serviceBeanAopCacheManager;
091
092 }