advisorDef.getPropertyValues().add(POINTCUT, pointcut); parserContext.registerComponent( new AdvisorComponentDefinition(advisorBeanName, advisorDef, (BeanDefinition) pointcut)); new AdvisorComponentDefinition(advisorBeanName, advisorDef));
public AdvisorComponentDefinition( String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) { Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null"); Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null"); this.advisorBeanName = advisorBeanName; this.advisorDefinition = advisorDefinition; MutablePropertyValues pvs = advisorDefinition.getPropertyValues(); BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName"); Assert.state(adviceReference != null, "Missing 'adviceBeanName' property"); if (pointcutDefinition != null) { this.beanReferences = new BeanReference[] {adviceReference}; this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition}; this.description = buildDescription(adviceReference, pointcutDefinition); } else { BeanReference pointcutReference = (BeanReference) pvs.get("pointcut"); Assert.state(pointcutReference != null, "Missing 'pointcut' property"); this.beanReferences = new BeanReference[] {adviceReference, pointcutReference}; this.beanDefinitions = new BeanDefinition[] {advisorDefinition}; this.description = buildDescription(adviceReference, pointcutReference); } }
@Test public void testAdvisorEventsWithPointcutRef() { this.reader.loadBeanDefinitions(POINTCUT_REF_CONTEXT); ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); assertEquals("Incorrect number of events fired", 2, componentDefinitions.length); assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; assertEquals("aop:config", compositeDef.getName()); ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); assertEquals("Incorrect number of inner components", 3, nestedComponentDefs.length); AdvisorComponentDefinition acd = null; for (int i = 0; i < nestedComponentDefs.length; i++) { ComponentDefinition componentDefinition = nestedComponentDefs[i]; if (componentDefinition instanceof AdvisorComponentDefinition) { acd = (AdvisorComponentDefinition) componentDefinition; break; } } assertNotNull("AdvisorComponentDefinition not found", acd); assertEquals(1, acd.getBeanDefinitions().length); assertEquals(2, acd.getBeanReferences().length); assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition); BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1]; assertEquals("countingAdvice", adviceDef.getBeanName()); }
@Test public void testAdvisorEventsWithDirectPointcut() { this.reader.loadBeanDefinitions(DIRECT_POINTCUT_EVENTS_CONTEXT); ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions(); assertEquals("Incorrect number of events fired", 2, componentDefinitions.length); assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition); CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0]; assertEquals("aop:config", compositeDef.getName()); ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents(); assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length); AdvisorComponentDefinition acd = null; for (int i = 0; i < nestedComponentDefs.length; i++) { ComponentDefinition componentDefinition = nestedComponentDefs[i]; if (componentDefinition instanceof AdvisorComponentDefinition) { acd = (AdvisorComponentDefinition) componentDefinition; break; } } assertNotNull("AdvisorComponentDefinition not found", acd); assertEquals(2, acd.getBeanDefinitions().length); assertEquals(1, acd.getBeanReferences().length); assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition); BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1]; assertEquals("countingAdvice", adviceDef.getBeanName()); }
this.beanReferences = new BeanReference[] {adviceReference}; this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition}; this.description = buildDescription(adviceReference, pointcutDefinition); this.beanReferences = new BeanReference[] {adviceReference, pointcutReference}; this.beanDefinitions = new BeanDefinition[] {advisorDefinition}; this.description = buildDescription(adviceReference, pointcutReference);
advisorDef.getPropertyValues().add(POINTCUT, pointcut); parserContext.registerComponent( new AdvisorComponentDefinition(advisorBeanName, advisorDef, (BeanDefinition) pointcut)); new AdvisorComponentDefinition(advisorBeanName, advisorDef));
public AdvisorComponentDefinition( String advisorBeanName, BeanDefinition advisorDefinition, @Nullable BeanDefinition pointcutDefinition) { Assert.notNull(advisorBeanName, "'advisorBeanName' must not be null"); Assert.notNull(advisorDefinition, "'advisorDefinition' must not be null"); this.advisorBeanName = advisorBeanName; this.advisorDefinition = advisorDefinition; MutablePropertyValues pvs = advisorDefinition.getPropertyValues(); BeanReference adviceReference = (BeanReference) pvs.get("adviceBeanName"); Assert.state(adviceReference != null, "Missing 'adviceBeanName' property"); if (pointcutDefinition != null) { this.beanReferences = new BeanReference[] {adviceReference}; this.beanDefinitions = new BeanDefinition[] {advisorDefinition, pointcutDefinition}; this.description = buildDescription(adviceReference, pointcutDefinition); } else { BeanReference pointcutReference = (BeanReference) pvs.get("pointcut"); Assert.state(pointcutReference != null, "Missing 'pointcut' property"); this.beanReferences = new BeanReference[] {adviceReference, pointcutReference}; this.beanDefinitions = new BeanDefinition[] {advisorDefinition}; this.description = buildDescription(adviceReference, pointcutReference); } }
advisorDef.getPropertyValues().add(POINTCUT, pointcut); parserContext.registerComponent( new AdvisorComponentDefinition(advisorBeanName, advisorDef, (BeanDefinition) pointcut)); new AdvisorComponentDefinition(advisorBeanName, advisorDef));