1 16 17 package org.springframework.transaction.interceptor; 18 19 import java.io.Serializable ; 20 import java.lang.reflect.Method ; 21 22 import org.aopalliance.aop.Advice; 23 24 import org.springframework.aop.ClassFilter; 25 import org.springframework.aop.Pointcut; 26 import org.springframework.aop.support.AbstractPointcutAdvisor; 27 import org.springframework.aop.support.StaticMethodMatcherPointcut; 28 import org.springframework.util.ObjectUtils; 29 30 43 public class TransactionAttributeSourceAdvisor extends AbstractPointcutAdvisor { 44 45 private TransactionInterceptor transactionInterceptor; 46 47 private final TransactionAttributeSourcePointcut pointcut = new TransactionAttributeSourcePointcut(); 48 49 50 53 public TransactionAttributeSourceAdvisor() { 54 } 55 56 60 public TransactionAttributeSourceAdvisor(TransactionInterceptor interceptor) { 61 setTransactionInterceptor(interceptor); 62 } 63 64 65 68 public void setTransactionInterceptor(TransactionInterceptor interceptor) { 69 this.transactionInterceptor = interceptor; 70 } 71 72 76 public void setClassFilter(ClassFilter classFilter) { 77 this.pointcut.setClassFilter(classFilter); 78 } 79 80 81 public Advice getAdvice() { 82 return this.transactionInterceptor; 83 } 84 85 public Pointcut getPointcut() { 86 return this.pointcut; 87 } 88 89 90 94 private class TransactionAttributeSourcePointcut extends StaticMethodMatcherPointcut implements Serializable { 95 96 private TransactionAttributeSource getTransactionAttributeSource() { 97 return (transactionInterceptor != null ? transactionInterceptor.getTransactionAttributeSource() : null); 98 } 99 100 public boolean matches(Method method, Class targetClass) { 101 TransactionAttributeSource tas = getTransactionAttributeSource(); 102 return (tas != null && tas.getTransactionAttribute(method, targetClass) != null); 103 } 104 105 public boolean equals(Object other) { 106 if (this == other) { 107 return true; 108 } 109 if (!(other instanceof TransactionAttributeSourcePointcut)) { 110 return false; 111 } 112 TransactionAttributeSourcePointcut otherPc = (TransactionAttributeSourcePointcut) other; 113 return ObjectUtils.nullSafeEquals(getTransactionAttributeSource(), otherPc.getTransactionAttributeSource()); 114 } 115 116 public int hashCode() { 117 return TransactionAttributeSourcePointcut.class.hashCode(); 118 } 119 120 public String toString() { 121 return getClass().getName() + ": " + getTransactionAttributeSource(); 122 } 123 } 124 125 } 126 | Popular Tags |