1. /*
  2. * Copyright 2002-2004 the original author or authors.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.springframework.transaction.interceptor;
  17. import java.lang.reflect.Method;
  18. import org.springframework.aop.framework.AopConfigException;
  19. import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
  20. /**
  21. * Advisor driven by a TransactionAttributeSource, used to exclude
  22. * a TransactionInterceptor from methods that are non-transactional.
  23. *
  24. * <p>Because the AOP framework caches advice calculations, this is normally
  25. * faster than just letting the TransactionInterceptor run and find out
  26. * itself that it has no work to do.
  27. *
  28. * @author Rod Johnson
  29. * @version $Id: TransactionAttributeSourceAdvisor.java,v 1.1 2004/03/23 16:05:23 jhoeller Exp $
  30. * @see org.springframework.transaction.interceptor.TransactionInterceptor
  31. * @see org.springframework.transaction.interceptor.TransactionProxyFactoryBean
  32. */
  33. public class TransactionAttributeSourceAdvisor extends StaticMethodMatcherPointcutAdvisor {
  34. private TransactionAttributeSource transactionAttributeSource;
  35. public TransactionAttributeSourceAdvisor(TransactionInterceptor ti) {
  36. super(ti);
  37. if (ti.getTransactionAttributeSource() == null) {
  38. throw new AopConfigException("Cannot construct a TransactionAttributeSourceAdvisor using a " +
  39. "TransactionInterceptor that has no TransactionAttributeSource configured");
  40. }
  41. this.transactionAttributeSource = ti.getTransactionAttributeSource();
  42. }
  43. public boolean matches(Method m, Class targetClass) {
  44. return (this.transactionAttributeSource.getTransactionAttribute(m, targetClass) != null);
  45. }
  46. }