Search in sources :

Example 6 with BeanComponentDefinition

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

the class AbstractListenerContainerParser method parseListener.

private void parseListener(Element containerEle, Element listenerEle, ParserContext parserContext, PropertyValues commonContainerProperties, PropertyValues specificContainerProperties) {
    RootBeanDefinition listenerDef = new RootBeanDefinition();
    listenerDef.setSource(parserContext.extractSource(listenerEle));
    listenerDef.setBeanClassName("org.springframework.jms.listener.adapter.MessageListenerAdapter");
    String ref = listenerEle.getAttribute(REF_ATTRIBUTE);
    if (!StringUtils.hasText(ref)) {
        parserContext.getReaderContext().error("Listener 'ref' attribute contains empty value.", listenerEle);
    } else {
        listenerDef.getPropertyValues().add("delegate", new RuntimeBeanReference(ref));
    }
    String method = null;
    if (listenerEle.hasAttribute(METHOD_ATTRIBUTE)) {
        method = listenerEle.getAttribute(METHOD_ATTRIBUTE);
        if (!StringUtils.hasText(method)) {
            parserContext.getReaderContext().error("Listener 'method' attribute contains empty value.", listenerEle);
        }
    }
    listenerDef.getPropertyValues().add("defaultListenerMethod", method);
    PropertyValue messageConverterPv = commonContainerProperties.getPropertyValue("messageConverter");
    if (messageConverterPv != null) {
        listenerDef.getPropertyValues().addPropertyValue(messageConverterPv);
    }
    BeanDefinition containerDef = createContainer(containerEle, listenerEle, parserContext, commonContainerProperties, specificContainerProperties);
    containerDef.getPropertyValues().add("messageListener", listenerDef);
    if (listenerEle.hasAttribute(RESPONSE_DESTINATION_ATTRIBUTE)) {
        String responseDestination = listenerEle.getAttribute(RESPONSE_DESTINATION_ATTRIBUTE);
        Boolean pubSubDomain = (Boolean) commonContainerProperties.getPropertyValue("replyPubSubDomain").getValue();
        listenerDef.getPropertyValues().add(pubSubDomain ? "defaultResponseTopicName" : "defaultResponseQueueName", responseDestination);
        if (containerDef.getPropertyValues().contains("destinationResolver")) {
            listenerDef.getPropertyValues().add("destinationResolver", containerDef.getPropertyValues().getPropertyValue("destinationResolver").getValue());
        }
    }
    String containerBeanName = listenerEle.getAttribute(ID_ATTRIBUTE);
    // If no bean id is given auto generate one using the ReaderContext's BeanNameGenerator
    if (!StringUtils.hasText(containerBeanName)) {
        containerBeanName = parserContext.getReaderContext().generateBeanName(containerDef);
    }
    // Register the listener and fire event
    parserContext.registerBeanComponent(new BeanComponentDefinition(containerDef, containerBeanName));
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) PropertyValue(org.springframework.beans.PropertyValue) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

Example 7 with BeanComponentDefinition

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

the class ClearCredentialsMethodInvokingFactoryBean method createPortMapper.

private BeanReference createPortMapper(Element elt, ParserContext pc) {
    // Register the portMapper. A default will always be created, even if no element
    // exists.
    BeanDefinition portMapper = new PortMappingsBeanDefinitionParser().parse(DomUtils.getChildElementByTagName(elt, Elements.PORT_MAPPINGS), pc);
    String portMapperName = pc.getReaderContext().generateBeanName(portMapper);
    pc.registerBeanComponent(new BeanComponentDefinition(portMapper, portMapperName));
    return new RuntimeBeanReference(portMapperName);
}
Also used : BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 8 with BeanComponentDefinition

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

the class ClearCredentialsMethodInvokingFactoryBean method createPortResolver.

private RuntimeBeanReference createPortResolver(BeanReference portMapper, ParserContext pc) {
    RootBeanDefinition portResolver = new RootBeanDefinition(PortResolverImpl.class);
    portResolver.getPropertyValues().addPropertyValue("portMapper", portMapper);
    String portResolverName = pc.getReaderContext().generateBeanName(portResolver);
    pc.registerBeanComponent(new BeanComponentDefinition(portResolver, portResolverName));
    return new RuntimeBeanReference(portResolverName);
}
Also used : RootBeanDefinition(org.springframework.beans.factory.support.RootBeanDefinition) BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 9 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project camel by apache.

the class CamelNamespaceHandler method registerEndpoint.

private void registerEndpoint(Element childElement, ParserContext parserContext, String contextId) {
    String id = childElement.getAttribute("id");
    // must have an id to be registered
    if (ObjectHelper.isNotEmpty(id)) {
        BeanDefinition definition = endpointParser.parse(childElement, parserContext);
        definition.getPropertyValues().addPropertyValue("camelContext", new RuntimeBeanReference(contextId));
        // Need to add this dependency of CamelContext for Spring 3.0
        try {
            Method method = definition.getClass().getMethod("setDependsOn", String[].class);
            method.invoke(definition, (Object) new String[] { contextId });
        } catch (Exception e) {
        // Do nothing here
        }
        parserContext.registerBeanComponent(new BeanComponentDefinition(definition, id));
    }
}
Also used : BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) Method(java.lang.reflect.Method) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) JAXBException(javax.xml.bind.JAXBException) BeanCreationException(org.springframework.beans.factory.BeanCreationException) BeanDefinitionStoreException(org.springframework.beans.factory.BeanDefinitionStoreException)

Example 10 with BeanComponentDefinition

use of org.springframework.beans.factory.parsing.BeanComponentDefinition in project camel by apache.

the class CamelNamespaceHandler method autoRegisterBeanDefinition.

private void autoRegisterBeanDefinition(String id, BeanDefinition definition, ParserContext parserContext, String contextId) {
    // it is a bit cumbersome to work with the spring bean definition parser
    // as we kinda need to eagerly register the bean definition on the parser context
    // and then later we might find out that we should not have done that in case we have multiple camel contexts
    // that would have a id clash by auto registering the same bean definition with the same id such as a producer template
    // see if we have already auto registered this id
    BeanDefinition existing = autoRegisterMap.get(id);
    if (existing == null) {
        // no then add it to the map and register it
        autoRegisterMap.put(id, definition);
        parserContext.registerComponent(new BeanComponentDefinition(definition, id));
        if (LOG.isDebugEnabled()) {
            LOG.debug("Registered default: {} with id: {} on camel context: {}", new Object[] { definition.getBeanClassName(), id, contextId });
        }
    } else {
        // ups we have already registered it before with same id, but on another camel context
        // this is not good so we need to remove all traces of this auto registering.
        // end user must manually add the needed XML elements and provide unique ids access all camel context himself.
        LOG.debug("Unregistered default: {} with id: {} as we have multiple camel contexts and they must use unique ids." + " You must define the definition in the XML file manually to avoid id clashes when using multiple camel contexts", definition.getBeanClassName(), id);
        parserContext.getRegistry().removeBeanDefinition(id);
    }
}
Also used : BeanComponentDefinition(org.springframework.beans.factory.parsing.BeanComponentDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition)

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