Search in sources :

Example 56 with ManagedMap

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

the class GatewayParser method methods.

private void methods(final Element element, ParserContext parserContext, final Map<String, Object> gatewayAttributes) {
    List<Element> methodElements = DomUtils.getChildElementsByTagName(element, "method");
    if (!CollectionUtils.isEmpty(methodElements)) {
        Map<String, BeanDefinition> methodMetadataMap = new ManagedMap<>();
        for (Element methodElement : methodElements) {
            String methodName = methodElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE);
            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"));
            String payloadExpression = methodElement.getAttribute("payload-expression");
            Assert.state(!hasMapper || !StringUtils.hasText(payloadExpression), "'payload-expression' is not allowed when a 'mapper' is provided");
            if (StringUtils.hasText(payloadExpression)) {
                methodMetadataBuilder.addPropertyValue("payloadExpression", BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class).addConstructorArgValue(payloadExpression).getBeanDefinition());
            }
            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<>();
                for (Element headerElement : invocationHeaders) {
                    BeanDefinition expressionDef = IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression("value", "expression", parserContext, headerElement, true);
                    headerExpressions.put(headerElement.getAttribute(AbstractBeanDefinitionParser.NAME_ATTRIBUTE), expressionDef);
                }
                methodMetadataBuilder.addPropertyValue("headerExpressions", headerExpressions);
            }
            methodMetadataMap.put(methodName, methodMetadataBuilder.getBeanDefinition());
        }
        gatewayAttributes.put("methods", methodMetadataMap);
    }
}
Also used : BeanDefinitionBuilder(org.springframework.beans.factory.support.BeanDefinitionBuilder) ExpressionFactoryBean(org.springframework.integration.config.ExpressionFactoryBean) Element(org.w3c.dom.Element) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 57 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 58 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<>();
    Map<String, String> payloadExpressionMap = new HashMap<>();
    Map<String, Map<String, String>> headersExpressionMap = new HashMap<>();
    Map<String, String> channelMap = new HashMap<>();
    ManagedMap<String, Object> resolvableChannelMap = new ManagedMap<>();
    if (!CollectionUtils.isEmpty(mappings)) {
        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
            Map<String, String> headerExpressions = headerExpressions(parserContext, mapping);
            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)

Example 59 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 60 with ManagedMap

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

the class IdempotentReceiverAutoProxyCreatorInitializer method annotated.

private void annotated(ConfigurableListableBeanFactory beanFactory, List<Map<String, String>> idempotentEndpointsMapping, String beanName, BeanDefinition beanDefinition) throws LinkageError {
    if (beanDefinition.getSource() instanceof MethodMetadata) {
        MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource();
        String annotationType = IdempotentReceiver.class.getName();
        if (beanMethod.isAnnotated(annotationType)) {
            // NOSONAR never null
            // NOSONAR
            Object value = beanMethod.getAnnotationAttributes(annotationType).get("value");
            if (value != null) {
                Class<?> returnType;
                if (beanMethod instanceof StandardMethodMetadata) {
                    returnType = ((StandardMethodMetadata) beanMethod).getIntrospectedMethod().getReturnType();
                } else {
                    try {
                        returnType = ClassUtils.forName(beanMethod.getReturnTypeName(), beanFactory.getBeanClassLoader());
                    } catch (ClassNotFoundException e) {
                        throw new CannotLoadBeanClassException(beanDefinition.getDescription(), beanName, beanMethod.getReturnTypeName(), e);
                    }
                }
                String endpoint = beanName;
                if (!MessageHandler.class.isAssignableFrom(returnType)) {
                    /*
						   MessageHandler beans, populated from @Bean methods, have a complex id,
						   including @Configuration bean name, method name and the Messaging annotation name.
						   The following pattern matches the bean name, regardless of the annotation name.
						*/
                    endpoint = beanDefinition.getFactoryBeanName() + "." + beanName + ".*" + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX;
                }
                String[] interceptors = (String[]) value;
                for (String interceptor : interceptors) {
                    Map<String, String> idempotentEndpoint = new ManagedMap<>();
                    idempotentEndpoint.put(interceptor, endpoint);
                    idempotentEndpointsMapping.add(idempotentEndpoint);
                }
            }
        }
    }
}
Also used : MessageHandler(org.springframework.messaging.MessageHandler) CannotLoadBeanClassException(org.springframework.beans.factory.CannotLoadBeanClassException) MethodMetadata(org.springframework.core.type.MethodMetadata) StandardMethodMetadata(org.springframework.core.type.StandardMethodMetadata) StandardMethodMetadata(org.springframework.core.type.StandardMethodMetadata) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Aggregations

ManagedMap (org.springframework.beans.factory.support.ManagedMap)136 Element (org.w3c.dom.Element)74 RootBeanDefinition (org.springframework.beans.factory.support.RootBeanDefinition)69 RuntimeBeanReference (org.springframework.beans.factory.config.RuntimeBeanReference)54 BeanDefinition (org.springframework.beans.factory.config.BeanDefinition)35 BeanDefinitionBuilder (org.springframework.beans.factory.support.BeanDefinitionBuilder)33 TypedStringValue (org.springframework.beans.factory.config.TypedStringValue)21 Map (java.util.Map)17 BeanComponentDefinition (org.springframework.beans.factory.parsing.BeanComponentDefinition)17 ManagedList (org.springframework.beans.factory.support.ManagedList)14 Node (org.w3c.dom.Node)13 BeanMetadataElement (org.springframework.beans.BeanMetadataElement)11 ConstructorArgumentValues (org.springframework.beans.factory.config.ConstructorArgumentValues)10 Nullable (org.springframework.lang.Nullable)10 MutablePropertyValues (org.springframework.beans.MutablePropertyValues)9 GroovyObject (groovy.lang.GroovyObject)8 AbstractBeanDefinition (org.springframework.beans.factory.support.AbstractBeanDefinition)8 BeanDefinitionHolder (org.springframework.beans.factory.config.BeanDefinitionHolder)7 NamedNodeMap (org.w3c.dom.NamedNodeMap)7 Collection (java.util.Collection)6