Search in sources :

Example 6 with CompositeComponentDefinition

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

the class AnnotationConfigBeanDefinitionParser method parse.

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    Object source = parserContext.extractSource(element);
    // Obtain bean definitions for all relevant BeanPostProcessors.
    Set<BeanDefinitionHolder> processorDefinitions = AnnotationConfigUtils.registerAnnotationConfigProcessors(parserContext.getRegistry(), source);
    // Register component for the surrounding <context:annotation-config> element.
    CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
    parserContext.pushContainingComponent(compDefinition);
    // Nest the concrete beans in the surrounding component.
    for (BeanDefinitionHolder processorDefinition : processorDefinitions) {
        parserContext.registerComponent(new BeanComponentDefinition(processorDefinition));
    }
    // Finally register the composite component.
    parserContext.popAndRegisterContainingComponent();
    return null;
}
Also used : CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Example 7 with CompositeComponentDefinition

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

the class AnnotationDrivenBeanDefinitionParser method parse.

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    Object source = parserContext.extractSource(element);
    // Register component for the surrounding <task:annotation-driven> element.
    CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
    parserContext.pushContainingComponent(compDefinition);
    // Nest the concrete post-processor bean in the surrounding component.
    BeanDefinitionRegistry registry = parserContext.getRegistry();
    String mode = element.getAttribute("mode");
    if ("aspectj".equals(mode)) {
        // mode="aspectj"
        registerAsyncExecutionAspect(element, parserContext);
    } else {
        // mode="proxy"
        if (registry.containsBeanDefinition(TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME)) {
            parserContext.getReaderContext().error("Only one AsyncAnnotationBeanPostProcessor may exist within the context.", source);
        } else {
            BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.scheduling.annotation.AsyncAnnotationBeanPostProcessor");
            builder.getRawBeanDefinition().setSource(source);
            String executor = element.getAttribute("executor");
            if (StringUtils.hasText(executor)) {
                builder.addPropertyReference("executor", executor);
            }
            String exceptionHandler = element.getAttribute("exception-handler");
            if (StringUtils.hasText(exceptionHandler)) {
                builder.addPropertyReference("exceptionHandler", exceptionHandler);
            }
            if (Boolean.valueOf(element.getAttribute(AopNamespaceUtils.PROXY_TARGET_CLASS_ATTRIBUTE))) {
                builder.addPropertyValue("proxyTargetClass", true);
            }
            registerPostProcessor(parserContext, builder, TaskManagementConfigUtils.ASYNC_ANNOTATION_PROCESSOR_BEAN_NAME);
        }
    }
    if (registry.containsBeanDefinition(TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME)) {
        parserContext.getReaderContext().error("Only one ScheduledAnnotationBeanPostProcessor may exist within the context.", source);
    } else {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.scheduling.annotation.ScheduledAnnotationBeanPostProcessor");
        builder.getRawBeanDefinition().setSource(source);
        String scheduler = element.getAttribute("scheduler");
        if (StringUtils.hasText(scheduler)) {
            builder.addPropertyReference("scheduler", scheduler);
        }
        registerPostProcessor(parserContext, builder, TaskManagementConfigUtils.SCHEDULED_ANNOTATION_PROCESSOR_BEAN_NAME);
    }
    // Finally register the composite component.
    parserContext.popAndRegisterContainingComponent();
    return null;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Example 8 with CompositeComponentDefinition

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

the class AbstractListenerContainerParser method parse.

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    CompositeComponentDefinition compositeDef = new CompositeComponentDefinition(element.getTagName(), parserContext.extractSource(element));
    parserContext.pushContainingComponent(compositeDef);
    PropertyValues commonProperties = parseCommonContainerProperties(element, parserContext);
    PropertyValues specificProperties = parseSpecificContainerProperties(element, parserContext);
    String factoryId = element.getAttribute(FACTORY_ID_ATTRIBUTE);
    if (StringUtils.hasText(factoryId)) {
        RootBeanDefinition beanDefinition = createContainerFactory(factoryId, element, parserContext, commonProperties, specificProperties);
        if (beanDefinition != null) {
            beanDefinition.setSource(parserContext.extractSource(element));
            parserContext.registerBeanComponent(new BeanComponentDefinition(beanDefinition, factoryId));
        }
    }
    NodeList childNodes = element.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            String localName = parserContext.getDelegate().getLocalName(child);
            if (LISTENER_ELEMENT.equals(localName)) {
                parseListener(element, (Element) child, parserContext, commonProperties, specificProperties);
            }
        }
    }
    parserContext.popAndRegisterContainingComponent();
    return null;
}
Also used : MutablePropertyValues(org.springframework.beans.MutablePropertyValues) PropertyValues(org.springframework.beans.PropertyValues) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition)

Example 9 with CompositeComponentDefinition

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

the class AnnotationDrivenJmsBeanDefinitionParser method parse.

@Override
public BeanDefinition parse(Element element, ParserContext parserContext) {
    Object source = parserContext.extractSource(element);
    // Register component for the surrounding <jms:annotation-driven> element.
    CompositeComponentDefinition compDefinition = new CompositeComponentDefinition(element.getTagName(), source);
    parserContext.pushContainingComponent(compDefinition);
    // Nest the concrete post-processor bean in the surrounding component.
    BeanDefinitionRegistry registry = parserContext.getRegistry();
    if (registry.containsBeanDefinition(JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME)) {
        parserContext.getReaderContext().error("Only one JmsListenerAnnotationBeanPostProcessor may exist within the context.", source);
    } else {
        BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition("org.springframework.jms.annotation.JmsListenerAnnotationBeanPostProcessor");
        builder.getRawBeanDefinition().setSource(source);
        String endpointRegistry = element.getAttribute("registry");
        if (StringUtils.hasText(endpointRegistry)) {
            builder.addPropertyReference("endpointRegistry", endpointRegistry);
        } else {
            registerDefaultEndpointRegistry(source, parserContext);
        }
        String containerFactory = element.getAttribute("container-factory");
        if (StringUtils.hasText(containerFactory)) {
            builder.addPropertyValue("containerFactoryBeanName", containerFactory);
        }
        String handlerMethodFactory = element.getAttribute("handler-method-factory");
        if (StringUtils.hasText(handlerMethodFactory)) {
            builder.addPropertyReference("messageHandlerMethodFactory", handlerMethodFactory);
        }
        registerInfrastructureBean(parserContext, builder, JmsListenerConfigUtils.JMS_LISTENER_ANNOTATION_PROCESSOR_BEAN_NAME);
    }
    // Finally register the composite component.
    parserContext.popAndRegisterContainingComponent();
    return null;
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) BeanDefinitionRegistry(org.springframework.beans.factory.support.BeanDefinitionRegistry)

Example 10 with CompositeComponentDefinition

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

the class JmsNamespaceHandlerTests method testSourceExtraction.

@Test
public void testSourceExtraction() {
    Iterator<ComponentDefinition> iterator = context.getRegisteredComponents();
    while (iterator.hasNext()) {
        ComponentDefinition compDef = iterator.next();
        assertNotNull("CompositeComponentDefinition '" + compDef.getName() + "' has no source attachment", compDef.getSource());
        validateComponentDefinition(compDef);
    }
}
Also used : ComponentDefinition(org.springframework.beans.factory.parsing.ComponentDefinition) CompositeComponentDefinition(org.springframework.beans.factory.parsing.CompositeComponentDefinition) Test(org.junit.Test)

Aggregations

CompositeComponentDefinition (org.springframework.beans.factory.parsing.CompositeComponentDefinition)24 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)16 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)12 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)10 Element (org.w3c.dom.Element)8 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)7 Test (org.junit.Test)5 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)5 ComponentDefinition (org.springframework.beans.factory.parsing.ComponentDefinition)5 BeanDefinitionRegistry (org.springframework.beans.factory.support.BeanDefinitionRegistry)4 ManagedList (org.springframework.beans.factory.support.ManagedList)4 BeanReference (org.springframework.beans.factory.config.BeanReference)3 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)2 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)2 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 List (java.util.List)1 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)1