1 16 17 package org.springframework.aop.config; 18 19 import org.springframework.beans.MutablePropertyValues; 20 import org.springframework.beans.factory.config.BeanDefinition; 21 import org.springframework.beans.factory.config.BeanReference; 22 import org.springframework.beans.factory.parsing.AbstractComponentDefinition; 23 import org.springframework.beans.factory.parsing.ComponentDefinition; 24 import org.springframework.util.Assert; 25 26 36 public class AdvisorComponentDefinition extends AbstractComponentDefinition { 37 38 private final String advisorBeanName; 39 40 private final BeanDefinition advisorDefinition; 41 42 private String description; 43 44 private BeanReference[] beanReferences; 45 46 private BeanDefinition[] beanDefinitions; 47 48 49 public AdvisorComponentDefinition(String advisorBeanName, BeanDefinition advisorDefinition) { 50 this(advisorBeanName, advisorDefinition, null); 51 } 52 53 public AdvisorComponentDefinition( 54 String advisorBeanName, BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) { 55 56 Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null"); 57 Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null"); 58 this.advisorBeanName = advisorBeanName; 59 this.advisorDefinition = advisorDefinition; 60 unwrapDefinitions(advisorDefinition, pointcutDefinition); 61 } 62 63 64 private void unwrapDefinitions(BeanDefinition advisorDefinition, BeanDefinition pointcutDefinition) { 65 MutablePropertyValues pvs = advisorDefinition.getPropertyValues(); 66 BeanReference adviceReference = (BeanReference) pvs.getPropertyValue("adviceBeanName").getValue(); 67 68 if (pointcutDefinition != null) { 69 this.beanReferences = new BeanReference[] {adviceReference}; 70 this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition}; 71 this.description = buildDescription(adviceReference, pointcutDefinition); 72 } 73 else { 74 BeanReference pointcutReference = (BeanReference) pvs.getPropertyValue("pointcut").getValue(); 75 this.beanReferences = new BeanReference[] {adviceReference, pointcutReference}; 76 this.beanDefinitions = new BeanDefinition[] {advisorDefinition}; 77 this.description = buildDescription(adviceReference, pointcutReference); 78 } 79 } 80 81 private String buildDescription(BeanReference adviceReference, BeanDefinition pointcutDefinition) { 82 return new StringBuffer ("Advisor <advice(ref)='"). 83 append(adviceReference.getBeanName()).append("', pointcut(expression)=["). 84 append(pointcutDefinition.getPropertyValues().getPropertyValue("expression").getValue()). 85 append("]>").toString(); 86 } 87 88 private String buildDescription(BeanReference adviceReference, BeanReference pointcutReference) { 89 return new StringBuffer ("Advisor <advice(ref)='"). 90 append(adviceReference.getBeanName()).append("', pointcut(ref)='"). 91 append(pointcutReference.getBeanName()).append("'>").toString(); 92 } 93 94 95 public String getName() { 96 return this.advisorBeanName; 97 } 98 99 public String getDescription() { 100 return this.description; 101 } 102 103 public BeanDefinition[] getBeanDefinitions() { 104 return this.beanDefinitions; 105 } 106 107 public BeanReference[] getBeanReferences() { 108 return this.beanReferences; 109 } 110 111 public Object getSource() { 112 return this.advisorDefinition.getSource(); 113 } 114 115 } 116 | Popular Tags |