Search in sources :

Example 11 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.

the class HeaderEnricherParserSupport method parseTransformer.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
protected void parseTransformer(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    ManagedMap headers = new ManagedMap();
    this.processHeaders(element, headers, parserContext);
    builder.addConstructorArgValue(headers);
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "default-overwrite");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "should-skip-nulls");
    this.postProcessHeaderEnricher(builder, element, parserContext);
}
Also used : ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 12 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.

the class AbstractRouterParser method parseRouter.

protected final BeanDefinition parseRouter(Element element, ParserContext parserContext) {
    BeanDefinition beanDefinition = this.doParseRouter(element, parserContext);
    if (beanDefinition != null) {
        // check if mapping is provided otherwise returned values will be treated as channel names
        List<Element> mappingElements = DomUtils.getChildElementsByTagName(element, "mapping");
        if (!CollectionUtils.isEmpty(mappingElements)) {
            ManagedMap<String, String> channelMappings = new ManagedMap<String, String>();
            for (Element mappingElement : mappingElements) {
                String key = mappingElement.getAttribute(this.getMappingKeyAttributeName());
                channelMappings.put(key, mappingElement.getAttribute("channel"));
            }
            beanDefinition.getPropertyValues().add("channelMappings", channelMappings);
        }
    }
    return beanDefinition;
}
Also used : Element(org.w3c.dom.Element) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 13 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.

the class DefaultRouterParser method postProcess.

@Override
protected void postProcess(BeanDefinitionBuilder builder, Element element, ParserContext parserContext) {
    List<Element> mappingElements = DomUtils.getChildElementsByTagName(element, "mapping");
    if (!CollectionUtils.isEmpty(mappingElements)) {
        ManagedMap<String, String> channelMappings = new ManagedMap<String, String>();
        for (Element mappingElement : mappingElements) {
            channelMappings.put(mappingElement.getAttribute("value"), mappingElement.getAttribute("channel"));
        }
        builder.addPropertyValue("channelMappings", channelMappings);
    }
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "default-output-channel");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "timeout");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "resolution-required");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "apply-sequence");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "ignore-send-failures");
}
Also used : Element(org.w3c.dom.Element) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 14 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.

the class GatewayParser method parse.

@Override
@SuppressWarnings("rawtypes")
public BeanDefinition parse(final Element element, ParserContext parserContext) {
    boolean isNested = parserContext.isNested();
    final Map<String, Object> gatewayAttributes = new HashMap<String, Object>();
    gatewayAttributes.put("name", element.getAttribute(AbstractBeanDefinitionParser.ID_ATTRIBUTE));
    gatewayAttributes.put("defaultPayloadExpression", element.getAttribute("default-payload-expression"));
    gatewayAttributes.put("defaultRequestChannel", element.getAttribute(isNested ? "request-channel" : "default-request-channel"));
    gatewayAttributes.put("defaultReplyChannel", element.getAttribute(isNested ? "reply-channel" : "default-reply-channel"));
    gatewayAttributes.put("errorChannel", element.getAttribute("error-channel"));
    String asyncExecutor = element.getAttribute("async-executor");
    if (!element.hasAttribute("async-executor") || StringUtils.hasLength(asyncExecutor)) {
        gatewayAttributes.put("asyncExecutor", asyncExecutor);
    } else {
        gatewayAttributes.put("asyncExecutor", null);
    }
    gatewayAttributes.put("mapper", element.getAttribute("mapper"));
    gatewayAttributes.put("defaultReplyTimeout", element.getAttribute(isNested ? "reply-timeout" : "default-reply-timeout"));
    gatewayAttributes.put("defaultRequestTimeout", element.getAttribute(isNested ? "request-timeout" : "default-request-timeout"));
    List<Element> headerElements = DomUtils.getChildElementsByTagName(element, "default-header");
    if (!CollectionUtils.isEmpty(headerElements)) {
        List<Map<String, Object>> headers = new ArrayList<Map<String, Object>>(headerElements.size());
        for (Element e : headerElements) {
            Map<String, Object> header = new HashMap<String, Object>();
            header.put("name", e.getAttribute("name"));
            header.put("value", e.getAttribute("value"));
            header.put("expression", e.getAttribute("expression"));
            headers.add(header);
        }
        gatewayAttributes.put("defaultHeaders", headers.toArray(new Map[headers.size()]));
    }
    List<Element> methodElements = DomUtils.getChildElementsByTagName(element, "method");
    if (!CollectionUtils.isEmpty(methodElements)) {
        Map<String, BeanDefinition> methodMetadataMap = new ManagedMap<String, BeanDefinition>();
        for (Element methodElement : methodElements) {
            String methodName = methodElement.getAttribute("name");
            BeanDefinitionBuilder methodMetadataBuilder = BeanDefinitionBuilder.genericBeanDefinition(GatewayMethodMetadata.class);
            methodMetadataBuilder.addPropertyValue("requestChannelName", methodElement.getAttribute("request-channel"));
            methodMetadataBuilder.addPropertyValue("replyChannelName", methodElement.getAttribute("reply-channel"));
            methodMetadataBuilder.addPropertyValue("requestTimeout", methodElement.getAttribute("request-timeout"));
            methodMetadataBuilder.addPropertyValue("replyTimeout", methodElement.getAttribute("reply-timeout"));
            boolean hasMapper = StringUtils.hasText(element.getAttribute("mapper"));
            Assert.state(!hasMapper || !StringUtils.hasText(element.getAttribute("payload-expression")), "'payload-expression' is not allowed when a 'mapper' is provided");
            IntegrationNamespaceUtils.setValueIfAttributeDefined(methodMetadataBuilder, methodElement, "payload-expression");
            List<Element> invocationHeaders = DomUtils.getChildElementsByTagName(methodElement, "header");
            if (!CollectionUtils.isEmpty(invocationHeaders)) {
                Assert.state(!hasMapper, "header elements are not allowed when a 'mapper' is provided");
                Map<String, Object> headerExpressions = new ManagedMap<String, Object>();
                for (Element headerElement : invocationHeaders) {
                    BeanDefinition expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("value", "expression", parserContext, headerElement, true);
                    headerExpressions.put(headerElement.getAttribute("name"), expressionDef);
                }
                methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
            }
            methodMetadataMap.put(methodName, methodMetadataBuilder.getBeanDefinition());
        }
        gatewayAttributes.put("methods", methodMetadataMap);
    }
    gatewayAttributes.put("serviceInterface", element.getAttribute("service-interface"));
    BeanDefinitionHolder gatewayHolder = this.registrar.parse(gatewayAttributes);
    if (isNested) {
        return gatewayHolder.getBeanDefinition();
    } else {
        BeanDefinitionReaderUtils.registerBeanDefinition(gatewayHolder, parserContext.getRegistry());
        return null;
    }
}
Also used : HashMap(java.util.HashMap) Element(org.w3c.dom.Element) ArrayList(java.util.ArrayList) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) BeanDefinitionHolder(org.springframework.beans.factory.config.BeanDefinitionHolder) ManagedMap(org.springframework.beans.factory.support.ManagedMap) HashMap(java.util.HashMap) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 15 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project spring-integration by spring-projects.

the class PublishingInterceptorParser method getMappings.

private Map<String, Map<?, ?>> getMappings(Element element, String defaultChannel, ParserContext parserContext) {
    List<Element> mappings = DomUtils.getChildElementsByTagName(element, "method");
    Map<String, Map<?, ?>> interceptorMappings = new HashMap<String, Map<?, ?>>();
    Map<String, String> payloadExpressionMap = new HashMap<String, String>();
    Map<String, Map<String, String>> headersExpressionMap = new HashMap<String, Map<String, String>>();
    Map<String, String> channelMap = new HashMap<String, String>();
    ManagedMap<String, Object> resolvableChannelMap = new ManagedMap<String, Object>();
    if (mappings != null && mappings.size() > 0) {
        for (Element mapping : mappings) {
            // set payloadMap
            String methodPattern = StringUtils.hasText(mapping.getAttribute("pattern")) ? mapping.getAttribute("pattern") : "*";
            String payloadExpression = StringUtils.hasText(mapping.getAttribute("payload")) ? mapping.getAttribute("payload") : "#return";
            payloadExpressionMap.put(methodPattern, payloadExpression);
            // set headersMap
            List<Element> headerElements = DomUtils.getChildElementsByTagName(mapping, "header");
            Map<String, String> headerExpressions = new HashMap<String, String>();
            for (Element headerElement : headerElements) {
                String name = headerElement.getAttribute("name");
                if (!StringUtils.hasText(name)) {
                    parserContext.getReaderContext().error("the 'name' attribute is required on the <header> element", parserContext.extractSource(headerElement));
                    continue;
                }
                String value = headerElement.getAttribute("value");
                String expression = headerElement.getAttribute("expression");
                boolean hasValue = StringUtils.hasText(value);
                boolean hasExpression = StringUtils.hasText(expression);
                if (hasValue == hasExpression) {
                    parserContext.getReaderContext().error("exactly one of 'value' or 'expression' is required on the <header> element", parserContext.extractSource(headerElement));
                    continue;
                }
                if (hasValue) {
                    expression = "'" + value + "'";
                }
                headerExpressions.put(name, expression);
            }
            if (headerExpressions.size() > 0) {
                headersExpressionMap.put(methodPattern, headerExpressions);
            }
            // set channelMap
            String tmpChannel = mapping.getAttribute("channel");
            String channel = StringUtils.hasText(tmpChannel) ? tmpChannel : defaultChannel;
            channelMap.put(methodPattern, channel);
            resolvableChannelMap.put(channel, new RuntimeBeanReference(channel));
        }
    }
    if (payloadExpressionMap.size() == 0) {
        payloadExpressionMap.put("*", "#return");
    }
    interceptorMappings.put("payload", payloadExpressionMap);
    if (headersExpressionMap.size() > 0) {
        interceptorMappings.put("headers", headersExpressionMap);
    }
    if (channelMap.size() > 0) {
        interceptorMappings.put("channels", channelMap);
        interceptorMappings.put("resolvableChannels", resolvableChannelMap);
    }
    return interceptorMappings;
}
Also used : HashMap(java.util.HashMap) Element(org.w3c.dom.Element) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap) HashMap(java.util.HashMap) Map(java.util.Map) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Aggregations

ManagedMap (org.springframework.beans.factory.support.ManagedMap)63 Element (org.w3c.dom.Element)37 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)25 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)25 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)24 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)23 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)11 Map (java.util.Map)10 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)9 HashMap (java.util.HashMap)6 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)6 Node (org.w3c.dom.Node)6 ManagedList (org.springframework.beans.factory.support.ManagedList)5 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)4 NamedNodeMap (org.w3c.dom.NamedNodeMap)4 GroovyObject (groovy.lang.GroovyObject)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)3