001
014
015 package com.liferay.portal.spring.aop;
016
017 import org.aopalliance.intercept.MethodInterceptor;
018
019 import org.springframework.aop.TargetSource;
020 import org.springframework.aop.framework.AdvisedSupport;
021 import org.springframework.aop.framework.AopConfigException;
022 import org.springframework.aop.framework.AopProxy;
023 import org.springframework.aop.framework.AopProxyFactory;
024 import org.springframework.aop.framework.ProxyFactory;
025 import org.springframework.aop.framework.autoproxy.AbstractAdvisorAutoProxyCreator;
026
027
030 public class ServiceBeanAutoProxyCreator
031 extends AbstractAdvisorAutoProxyCreator {
032
033 public void setMethodInterceptor(MethodInterceptor methodInterceptor) {
034 _methodInterceptor = methodInterceptor;
035 }
036
037 @Override
038 protected void customizeProxyFactory(ProxyFactory proxyFactory) {
039 proxyFactory.setAopProxyFactory(
040 new AopProxyFactory() {
041
042 public AopProxy createAopProxy(AdvisedSupport advisedSupport)
043 throws AopConfigException {
044
045 return new ServiceBeanAopProxy(
046 advisedSupport, _methodInterceptor);
047 }
048
049 }
050 );
051 }
052
053 @Override
054 @SuppressWarnings("rawtypes")
055 protected Object[] getAdvicesAndAdvisorsForBean(
056 Class beanClass, String beanName, TargetSource targetSource) {
057
058 Object[] advices = DO_NOT_PROXY;
059
060 if (beanName.endsWith(_SERVICE_SUFFIX)) {
061 advices = super.getAdvicesAndAdvisorsForBean(
062 beanClass, beanName, targetSource);
063
064 if (advices == DO_NOT_PROXY) {
065 advices = PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
066 }
067 }
068
069 return advices;
070 }
071
072 private static final String _SERVICE_SUFFIX = "Service";
073
074 private MethodInterceptor _methodInterceptor;
075
076 }