1 16 17 package org.springframework.transaction.config; 18 19 import org.w3c.dom.Element ; 20 21 import org.springframework.aop.config.AopNamespaceUtils; 22 import org.springframework.beans.factory.config.RuntimeBeanReference; 23 import org.springframework.beans.factory.support.AbstractBeanDefinition; 24 import org.springframework.beans.factory.support.RootBeanDefinition; 25 import org.springframework.beans.factory.xml.AbstractBeanDefinitionParser; 26 import org.springframework.beans.factory.xml.ParserContext; 27 import org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor; 28 import org.springframework.transaction.interceptor.TransactionInterceptor; 29 30 43 class AnnotationDrivenBeanDefinitionParser extends AbstractBeanDefinitionParser { 44 45 48 private static final String TRANSACTION_INTERCEPTOR = "transactionInterceptor"; 49 50 51 private static final String PROXY_TARGET_CLASS = "proxy-target-class"; 52 53 54 private static final String ORDER = "order"; 55 56 57 62 protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) { 63 AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(parserContext, element); 64 65 boolean proxyTargetClass = Boolean.valueOf(element.getAttribute(PROXY_TARGET_CLASS)).booleanValue(); 66 if (proxyTargetClass) { 67 AopNamespaceUtils.forceAutoProxyCreatorToUseClassProxying(parserContext.getRegistry()); 68 } 69 70 String transactionManagerName = element.getAttribute(TxNamespaceUtils.TRANSACTION_MANAGER_ATTRIBUTE); 71 Class sourceClass = TxNamespaceUtils.getAnnotationTransactionAttributeSourceClass(); 72 73 RootBeanDefinition interceptorDefinition = new RootBeanDefinition(TransactionInterceptor.class); 75 interceptorDefinition.setSource(parserContext.extractSource(element)); 76 interceptorDefinition.getPropertyValues().addPropertyValue( 77 TxNamespaceUtils.TRANSACTION_MANAGER_PROPERTY, new RuntimeBeanReference(transactionManagerName)); 78 interceptorDefinition.getPropertyValues().addPropertyValue( 79 TxNamespaceUtils.TRANSACTION_ATTRIBUTE_SOURCE, new RootBeanDefinition(sourceClass)); 80 81 RootBeanDefinition advisorDefinition = new RootBeanDefinition(TransactionAttributeSourceAdvisor.class); 83 advisorDefinition.setSource(parserContext.extractSource(element)); 84 advisorDefinition.getPropertyValues().addPropertyValue(TRANSACTION_INTERCEPTOR, interceptorDefinition); 85 if (element.hasAttribute(ORDER)) { 86 advisorDefinition.getPropertyValues().addPropertyValue( 87 ORDER, element.getAttribute(ORDER)); 88 } 89 return advisorDefinition; 90 } 91 92 protected boolean shouldGenerateId() { 93 return true; 94 } 95 96 } 97 | Popular Tags |