Search in sources :

Example 1 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.

the class AnnotationDrivenBeanDefinitionParser method getConversionService.

private RuntimeBeanReference getConversionService(Element element, Object source, ParserContext parserContext) {
    RuntimeBeanReference conversionServiceRef;
    if (element.hasAttribute("conversion-service")) {
        conversionServiceRef = new RuntimeBeanReference(element.getAttribute("conversion-service"));
    } else {
        RootBeanDefinition conversionDef = new RootBeanDefinition(FormattingConversionServiceFactoryBean.class);
        conversionDef.setSource(source);
        conversionDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);
        String conversionName = parserContext.getReaderContext().registerWithGeneratedName(conversionDef);
        parserContext.registerComponent(new BeanComponentDefinition(conversionDef, conversionName));
        conversionServiceRef = new RuntimeBeanReference(conversionName);
    }
    return conversionServiceRef;
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 2 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.

the class AopNamespaceHandlerEventTests method testAdvisorEventsWithPointcutRef.

@Test
public void testAdvisorEventsWithPointcutRef() throws Exception {
    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());
}
Also used : CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) ComponentDefinition(org.springframework.beans.factory.parsing.ComponentDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) Test(org.junit.Test)

Example 3 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.

the class AopNamespaceHandlerEventTests method testAspectEvent.

@Test
public void testAspectEvent() throws Exception {
    this.reader.loadBeanDefinitions(CONTEXT);
    ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
    assertEquals("Incorrect number of events fired", 5, 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);
    AspectComponentDefinition acd = null;
    for (int i = 0; i < nestedComponentDefs.length; i++) {
        ComponentDefinition componentDefinition = nestedComponentDefs[i];
        if (componentDefinition instanceof AspectComponentDefinition) {
            acd = (AspectComponentDefinition) componentDefinition;
            break;
        }
    }
    assertNotNull("AspectComponentDefinition not found", acd);
    BeanDefinition[] beanDefinitions = acd.getBeanDefinitions();
    assertEquals(5, beanDefinitions.length);
    BeanReference[] beanReferences = acd.getBeanReferences();
    assertEquals(6, beanReferences.length);
    Set<String> expectedReferences = new HashSet<>();
    expectedReferences.add("pc");
    expectedReferences.add("countingAdvice");
    for (int i = 0; i < beanReferences.length; i++) {
        BeanReference beanReference = beanReferences[i];
        expectedReferences.remove(beanReference.getBeanName());
    }
    assertEquals("Incorrect references found", 0, expectedReferences.size());
    for (int i = 1; i < componentDefinitions.length; i++) {
        assertTrue(componentDefinitions[i] instanceof BeanComponentDefinition);
    }
    ComponentDefinition[] nestedComponentDefs2 = acd.getNestedComponents();
    assertEquals("Inner PointcutComponentDefinition not found", 1, nestedComponentDefs2.length);
    assertTrue(nestedComponentDefs2[0] instanceof PointcutComponentDefinition);
    PointcutComponentDefinition pcd = (PointcutComponentDefinition) nestedComponentDefs2[0];
    assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
}
Also used : CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) BeanReference(org.springframework.beans.factory.config.BeanReference) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) ComponentDefinition(org.springframework.beans.factory.parsing.ComponentDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 4 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.

the class AopNamespaceUtils method registerComponentIfNecessary.

private static void registerComponentIfNecessary(BeanDefinition beanDefinition, ParserContext parserContext) {
    if (beanDefinition != null) {
        BeanComponentDefinition componentDefinition = new BeanComponentDefinition(beanDefinition, AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
        parserContext.registerComponent(componentDefinition);
    }
}
Also used : BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Example 5 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project spring-framework by spring-projects.

the class DefaultBeanDefinitionDocumentReader method processBeanDefinition.

/**
	 * Process the given bean element, parsing the bean definition
	 * and registering it with the registry.
	 */
protected void processBeanDefinition(Element ele, BeanDefinitionParserDelegate delegate) {
    BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(ele);
    if (bdHolder != null) {
        bdHolder = delegate.decorateBeanDefinitionIfRequired(ele, bdHolder);
        try {
            // Register the final decorated instance.
            BeanDefinitionReaderUtils.registerBeanDefinition(bdHolder, getReaderContext().getRegistry());
        } catch (BeanDefinitionStoreException ex) {
            getReaderContext().error("Failed to register bean definition with name '" + bdHolder.getBeanName() + "'", ele, ex);
        }
        // Send registration event.
        getReaderContext().fireComponentRegistered(new BeanComponentDefinition(bdHolder));
    }
}
Also used : BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Aggregations

BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)133 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)75 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)52 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)47 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)47 Element (org.w3c.dom.Element)29 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)22 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)22 CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)20 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)16 ManagedList (org.springframework.beans.factory.support.ManagedList)14 Nullable (org.springframework.lang.Nullable)10 ComponentDefinition (org.springframework.beans.factory.parsing.ComponentDefinition)9 Test (org.junit.jupiter.api.Test)6 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)5 NodeList (org.w3c.dom.NodeList)5 Test (org.junit.Test)4 ManagedMap (org.springframework.beans.factory.support.ManagedMap)4 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)3 PropertyValue (org.springframework.beans.PropertyValue)3