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 afterPropertiesSet() {
034
035
036
037 if (_beanMatcher == null) {
038 _beanMatcher = new ServiceBeanMatcher();
039 }
040 }
041
042 public void setBeanMatcher(BeanMatcher beanMatcher) {
043 _beanMatcher = beanMatcher;
044 }
045
046 public void setMethodInterceptor(MethodInterceptor methodInterceptor) {
047 _methodInterceptor = methodInterceptor;
048 }
049
050 @Override
051 protected void customizeProxyFactory(ProxyFactory proxyFactory) {
052 proxyFactory.setAopProxyFactory(
053 new AopProxyFactory() {
054
055 @Override
056 public AopProxy createAopProxy(AdvisedSupport advisedSupport)
057 throws AopConfigException {
058
059 return new ServiceBeanAopProxy(
060 advisedSupport, _methodInterceptor);
061 }
062
063 }
064 );
065 }
066
067 @Override
068 @SuppressWarnings("rawtypes")
069 protected Object[] getAdvicesAndAdvisorsForBean(
070 Class beanClass, String beanName, TargetSource targetSource) {
071
072 Object[] advices = DO_NOT_PROXY;
073
074 if (_beanMatcher.match(beanClass, beanName)) {
075 advices = super.getAdvicesAndAdvisorsForBean(
076 beanClass, beanName, targetSource);
077
078 if (advices == DO_NOT_PROXY) {
079 advices = PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
080 }
081 }
082
083 return advices;
084 }
085
086 private BeanMatcher _beanMatcher;
087 private MethodInterceptor _methodInterceptor;
088
089 }