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);
}
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;
}
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;
}
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;
}
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()));
}
Aggregations