001
014
015 package com.liferay.portal.spring.aop;
016
017 import java.lang.reflect.InvocationHandler;
018 import java.lang.reflect.Method;
019
020 import java.util.List;
021
022 import org.aopalliance.intercept.MethodInterceptor;
023
024
027 public class MethodInterceptorInvocationHandler implements InvocationHandler {
028
029 public MethodInterceptorInvocationHandler(
030 Object target, List<MethodInterceptor> methodInterceptors) {
031
032 if (target == null) {
033 throw new NullPointerException("Target is null");
034 }
035
036 _target = target;
037 _targetClass = target.getClass();
038
039 if (methodInterceptors == null) {
040 throw new NullPointerException("Method interceptors is null");
041 }
042
043 if (methodInterceptors.isEmpty()) {
044 throw new IllegalArgumentException("Method interceptors is empty");
045 }
046
047 for (int i = 0; i < methodInterceptors.size(); i++) {
048 if (methodInterceptors.get(i) == null) {
049 throw new IllegalArgumentException(
050 "Method interceptor " + i + " is null");
051 }
052 }
053
054 _methodInterceptors = methodInterceptors;
055 }
056
057 @Override
058 public Object invoke(Object proxy, Method method, Object[] arguments)
059 throws Throwable {
060
061 ServiceBeanMethodInvocation serviceBeanMethodInvocation =
062 new ServiceBeanMethodInvocation(
063 _target, _targetClass, method, arguments);
064
065 serviceBeanMethodInvocation.setMethodInterceptors(_methodInterceptors);
066
067 return serviceBeanMethodInvocation.proceed();
068 }
069
070 private List<MethodInterceptor> _methodInterceptors;
071 private Object _target;
072 private Class<?> _targetClass;
073
074 }