1 16 17 package org.springframework.aop.config; 18 19 import org.w3c.dom.Element ; 20 import org.w3c.dom.Node ; 21 import org.w3c.dom.NodeList ; 22 23 import org.springframework.beans.factory.config.BeanDefinition; 24 import org.springframework.beans.factory.config.TypedStringValue; 25 import org.springframework.beans.factory.support.ManagedList; 26 import org.springframework.beans.factory.xml.BeanDefinitionParser; 27 import org.springframework.beans.factory.xml.ParserContext; 28 import org.springframework.core.Conventions; 29 import org.springframework.util.StringUtils; 30 31 40 class AspectJAutoProxyBeanDefinitionParser implements BeanDefinitionParser { 41 42 private static final String PROXY_TARGET_ATTRIBUTE = "proxy-target-class"; 43 44 private static final String PROXY_TARGET_CLASS = Conventions.attributeNameToPropertyName(PROXY_TARGET_ATTRIBUTE); 45 46 47 public BeanDefinition parse(Element element, ParserContext parserContext) { 48 AopNamespaceUtils.registerAtAspectJAutoProxyCreatorIfNecessary(parserContext, element); 49 extendBeanDefinition(element, parserContext); 50 return null; 51 } 52 53 private void extendBeanDefinition(Element element, ParserContext parserContext) { 54 BeanDefinition beanDef = 55 parserContext.getRegistry().getBeanDefinition(AopNamespaceUtils.AUTO_PROXY_CREATOR_BEAN_NAME); 56 String proxyTargetClass = element.getAttribute(PROXY_TARGET_ATTRIBUTE); 57 if (StringUtils.hasText(proxyTargetClass)) { 58 beanDef.getPropertyValues().addPropertyValue(PROXY_TARGET_CLASS, proxyTargetClass); 59 } 60 if (element.hasChildNodes()) { 61 addIncludePatterns(element, parserContext, beanDef); 62 } 63 } 64 65 private void addIncludePatterns(Element element, ParserContext parserContext, BeanDefinition beanDef) { 66 ManagedList includePatterns = new ManagedList(); 67 includePatterns.setSource(parserContext.extractSource(element)); 68 NodeList childNodes = element.getChildNodes(); 69 for (int i = 0; i < childNodes.getLength(); i++) { 70 Node node = childNodes.item(i); 71 if (node instanceof Element ) { 72 Element includeElement = (Element ) node; 73 TypedStringValue valueHolder = new TypedStringValue(includeElement.getAttribute("name")); 74 valueHolder.setSource(parserContext.extractSource(includeElement)); 75 includePatterns.add(valueHolder); 76 } 77 } 78 beanDef.getPropertyValues().addPropertyValue("includePatterns", includePatterns); 79 } 80 81 } 82 | Popular Tags |