Search in sources :

Example 51 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project sharding-jdbc by shardingjdbc.

the class ShardingDataSourceBeanDefinitionParser method parseDataSources.

private Map<String, RuntimeBeanReference> parseDataSources(final Element element) {
    Element shardingRuleElement = DomUtils.getChildElementByTagName(element, ShardingDataSourceBeanDefinitionParserTag.SHARDING_RULE_CONFIG_TAG);
    List<String> dataSources = Splitter.on(",").trimResults().splitToList(shardingRuleElement.getAttribute(ShardingDataSourceBeanDefinitionParserTag.DATA_SOURCE_NAMES_TAG));
    Map<String, RuntimeBeanReference> result = new ManagedMap<>(dataSources.size());
    for (String each : dataSources) {
        result.put(each, new RuntimeBeanReference(each));
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 52 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project sharding-jdbc by shardingjdbc.

the class OrchestrationShardingDataSourceBeanDefinitionParser method parseDataSources.

private Map<String, RuntimeBeanReference> parseDataSources(final Element element) {
    Element shardingRuleElement = DomUtils.getChildElementByTagName(element, ShardingDataSourceBeanDefinitionParserTag.SHARDING_RULE_CONFIG_TAG);
    List<String> dataSources = Splitter.on(",").trimResults().splitToList(shardingRuleElement.getAttribute(ShardingDataSourceBeanDefinitionParserTag.DATA_SOURCE_NAMES_TAG));
    Map<String, RuntimeBeanReference> result = new ManagedMap<>(dataSources.size());
    for (String each : dataSources) {
        result.put(each, new RuntimeBeanReference(each));
    }
    return result;
}
Also used : Element(org.w3c.dom.Element) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap)

Example 53 with ManagedMap

use of org.springframework.beans.factory.support.ManagedMap in project mule by mulesoft.

the class PropertyComponentUtils method getPropertyValueFromPropertyComponent.

/**
 * Creates a {@link Pair} from a generic property/ies component in the configuration.
 *
 * @param propertyComponentModel the component model for spring:property, spring:properties or property.
 * @return a {@code PropertyValue} with the parsed content of the component.
 */
public static Pair<String, Object> getPropertyValueFromPropertyComponent(ComponentModel propertyComponentModel) {
    Pair<String, Object> propertyValue;
    String refKey = getReferenceAttributeName(propertyComponentModel.getIdentifier());
    String nameKey = getNameAttributeName(propertyComponentModel.getIdentifier());
    if (propertyComponentModel.getInnerComponents().isEmpty()) {
        Object value;
        if (propertyComponentModel.getParameters().containsKey(refKey)) {
            value = new RuntimeBeanReference(propertyComponentModel.getParameters().get(refKey));
        } else {
            value = propertyComponentModel.getParameters().get(VALUE_PARAMETER_NAME);
        }
        if (!propertyComponentModel.getParameters().containsKey(nameKey)) {
            propertyValue = new Pair<>(PROPERTY_NAME_PROPERTY_ATTRIBUTE, new RuntimeBeanReference(propertyComponentModel.getParameters().get("ref")));
        } else {
            propertyValue = new Pair<>(propertyComponentModel.getParameters().get(nameKey), value);
        }
    } else if (propertyComponentModel.getInnerComponents().get(0).getIdentifier().getName().equals("map")) {
        ComponentModel springMap = propertyComponentModel.getInnerComponents().get(0);
        ManagedMap<String, Object> propertiesMap = new ManagedMap<>();
        springMap.getInnerComponents().stream().forEach(mapEntry -> {
            Object value;
            if (mapEntry.getParameters().containsKey(VALUE_PARAMETER_NAME)) {
                value = mapEntry.getParameters().get(VALUE_PARAMETER_NAME);
            } else {
                value = new RuntimeBeanReference(mapEntry.getParameters().get(REFERENCE_MULE_PROPERTY_ATTRIBUTE));
            }
            propertiesMap.put(mapEntry.getParameters().get(PROPERTY_NAME_MULE_PROPERTY_ATTRIBUTE), value);
        });
        propertyValue = new Pair<>(propertyComponentModel.getNameAttribute(), propertiesMap);
    } else {
        throw new MuleRuntimeException(createStaticMessage("Unrecognized property model identifier: " + propertyComponentModel.getInnerComponents().get(0).getIdentifier()));
    }
    return propertyValue;
}
Also used : MULE_PROPERTY_IDENTIFIER(org.mule.runtime.config.internal.model.ApplicationModel.MULE_PROPERTY_IDENTIFIER) ManagedMap(org.springframework.beans.factory.support.ManagedMap) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ComponentIdentifier(org.mule.runtime.api.component.ComponentIdentifier) Pair(org.mule.runtime.api.util.Pair) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference) ManagedMap(org.springframework.beans.factory.support.ManagedMap) Pair(org.mule.runtime.api.util.Pair)

Example 54 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 55 with ManagedMap

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

the class EnricherParser method propertySubElements.

private void propertySubElements(Element element, ParserContext parserContext, final BeanDefinitionBuilder builder) {
    List<Element> subElements = DomUtils.getChildElementsByTagName(element, "property");
    if (!CollectionUtils.isEmpty(subElements)) {
        ManagedMap<String, Object> expressions = new ManagedMap<String, Object>();
        ManagedMap<String, Object> nullResultExpressions = new ManagedMap<String, Object>();
        for (Element subElement : subElements) {
            String name = subElement.getAttribute("name");
            String value = subElement.getAttribute("value");
            String type = subElement.getAttribute(TYPE_ATTRIBUTE);
            String expression = subElement.getAttribute(EXPRESSION_ATTRIBUTE);
            String nullResultExpression = subElement.getAttribute("null-result-expression");
            boolean hasAttributeValue = StringUtils.hasText(value);
            boolean hasAttributeExpression = StringUtils.hasText(expression);
            boolean hasAttributeNullResultExpression = StringUtils.hasText(nullResultExpression);
            if (hasAttributeValue && hasAttributeExpression) {
                parserContext.getReaderContext().error("Only one of 'value' or 'expression' is allowed", element);
            }
            if (!hasAttributeValue && !hasAttributeExpression && !hasAttributeNullResultExpression) {
                parserContext.getReaderContext().error("One of 'value' or 'expression' or 'null-result-expression' is required", element);
            }
            expression(element, parserContext, expressions, nullResultExpressions, name, value, type, expression, nullResultExpression, hasAttributeValue, hasAttributeExpression, hasAttributeNullResultExpression);
        }
        if (expressions.size() > 0) {
            builder.addPropertyValue("propertyExpressions", expressions);
        }
        if (nullResultExpressions.size() > 0) {
            builder.addPropertyValue("nullResultPropertyExpressions", nullResultExpressions);
        }
    }
}
Also used : Element(org.w3c.dom.Element) 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