Search in sources :

Example 16 with ComponentModel

use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.

the class MacroExpansionModuleModel method copyGlobalElementComponentModel.

/**
 * Goes over the {@code modelToCopy} by consuming the attributes as they are, unless some of them are actually targeting a
 * global component (such as a configuration), in which it will append the {@code configRefName} to that reference, which will
 * be the definitive name once the Mule application has been completely macro expanded in the final XML configuration.
 *
 * @param modelToCopy original source of truth that comes from the <module/>
 * @param configRefName name of the configuration being used in the Mule application
 * @param moduleGlobalElementsNames names of the <module/>s global component that will be macro expanded in the Mule application
 * @param literalsParameters {@link Map} with all he <property>s and <parameter>s that were feed with a literal value in the
 *        Mule application's code.
 * @return a transformed {@link ComponentModel} from the {@code modelToCopy}, where the global element's attributes has been
 *         updated accordingly (both global components updates plus the line number, and so on). If the value for some parameter
 *         can be optimized by replacing it for the literal's value, it will be done as well using the
 *         {@code literalsParameters}
 */
private ComponentModel copyGlobalElementComponentModel(ComponentModel modelToCopy, String configRefName, Set<String> moduleGlobalElementsNames, Map<String, String> literalsParameters) {
    ComponentModel.Builder globalElementReplacementModel = getComponentModelBuilderFrom(modelToCopy);
    for (Map.Entry<String, String> entry : modelToCopy.getParameters().entrySet()) {
        String value = calculateAttributeValue(configRefName, moduleGlobalElementsNames, entry.getValue());
        final String optimizedValue = literalsParameters.getOrDefault(value, value);
        globalElementReplacementModel.addParameter(entry.getKey(), optimizedValue, false);
    }
    for (ComponentModel operationChildModel : modelToCopy.getInnerComponents()) {
        globalElementReplacementModel.addChildComponentModel(copyGlobalElementComponentModel(operationChildModel, configRefName, moduleGlobalElementsNames, literalsParameters));
    }
    return buildFrom(modelToCopy, globalElementReplacementModel);
}
Also used : ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) HashMap(java.util.HashMap) Map(java.util.Map) Collections.emptyMap(java.util.Collections.emptyMap)

Example 17 with ComponentModel

use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.

the class ExceptionStrategyRefBeanDefinitionCreator method handleRequest.

@Override
boolean handleRequest(CreateBeanDefinitionRequest createBeanDefinitionRequest) {
    ComponentModel componentModel = createBeanDefinitionRequest.getComponentModel();
    if (componentModel.getIdentifier().equals(EXCEPTION_STRATEGY_REFERENCE_IDENTIFIER)) {
        componentModel.setType(FlowExceptionHandler.class);
        ((SpringComponentModel) componentModel).setBeanReference(new RuntimeBeanReference(componentModel.getParameters().get(REFERENCE_ATTRIBUTE)));
        return true;
    }
    return false;
}
Also used : SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) RuntimeBeanReference(org.springframework.beans.factory.config.RuntimeBeanReference)

Example 18 with ComponentModel

use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.

the class PropertiesMapBeanDefinitionCreator method createManagedMapFromEntries.

private ManagedMap<Object, Object> createManagedMapFromEntries(ComponentModel componentModel) {
    ManagedMap<Object, Object> managedMap;
    managedMap = new ManagedMap<>();
    for (ComponentModel innerComponent : componentModel.getInnerComponents()) {
        processAndAddMapProperty(innerComponent, managedMap);
    }
    return managedMap;
}
Also used : ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel)

Example 19 with ComponentModel

use of org.mule.runtime.config.internal.model.ComponentModel 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 20 with ComponentModel

use of org.mule.runtime.config.internal.model.ComponentModel in project mule by mulesoft.

the class ObjectTypeVisitorTestCase method typeIsInstanceOfCheckedClassFromAttribute.

@Test
public void typeIsInstanceOfCheckedClassFromAttribute() throws ClassNotFoundException {
    ComponentModel componentModel = new SpringComponentModel();
    componentModel.setParameter("type", "org.mule.runtime.core.internal.processor.ReferenceProcessor");
    ObjectTypeVisitor visitor = new ObjectTypeVisitor(componentModel);
    TypeDefinition typeDefinition = fromConfigurationAttribute("type").checkingThatIsClassOrInheritsFrom(ReferenceProcessor.class);
    typeDefinition.visit(visitor);
    assertTrue(ReferenceProcessor.class.isAssignableFrom(visitor.getType()));
}
Also used : ReferenceProcessor(org.mule.runtime.core.internal.processor.ReferenceProcessor) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ComponentModel(org.mule.runtime.config.internal.model.ComponentModel) SpringComponentModel(org.mule.runtime.config.internal.dsl.model.SpringComponentModel) ObjectTypeVisitor(org.mule.runtime.config.internal.dsl.processor.ObjectTypeVisitor) TypeDefinition(org.mule.runtime.dsl.api.component.TypeDefinition) Test(org.junit.Test)

Aggregations

ComponentModel (org.mule.runtime.config.internal.model.ComponentModel)41 HashMap (java.util.HashMap)14 List (java.util.List)13 Map (java.util.Map)13 SpringComponentModel (org.mule.runtime.config.internal.dsl.model.SpringComponentModel)13 Optional (java.util.Optional)11 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)11 Set (java.util.Set)9 ComponentIdentifier (org.mule.runtime.api.component.ComponentIdentifier)9 String.format (java.lang.String.format)8 ArrayList (java.util.ArrayList)8 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)8 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)8 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)8 Collections.emptyMap (java.util.Collections.emptyMap)7 GlobalElementComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.GlobalElementComponentModelModelProperty)7 Optional.of (java.util.Optional.of)6 Collectors (java.util.stream.Collectors)6 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)6 OperationComponentModelModelProperty (org.mule.runtime.config.internal.dsl.model.extension.xml.property.OperationComponentModelModelProperty)6