use of org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createMapParameter.
private void createMapParameter(ParameterObjectValue objectValue, DslElementSyntax paramDsl, Object model, ObjectType mapType, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
InternalComponentConfiguration.Builder mapConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(paramDsl));
DslElementModel.Builder mapElement = DslElementModel.builder().withModel(model).withDsl(paramDsl);
MetadataType valueType = mapType.getOpenRestriction().get();
paramDsl.getGeneric(valueType).ifPresent(entryDsl -> objectValue.getParameters().forEach((key, value) -> {
InternalComponentConfiguration.Builder entryConfigBuilder = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(entryDsl));
DslElementModel.Builder<MetadataType> entryElement = DslElementModel.<MetadataType>builder().withModel(valueType).withDsl(entryDsl);
entryDsl.getAttribute(KEY_ATTRIBUTE_NAME).ifPresent(keyDsl -> {
entryConfigBuilder.withParameter(KEY_ATTRIBUTE_NAME, key);
entryElement.containing(DslElementModel.builder().withModel(typeLoader.load(String.class)).withDsl(keyDsl).withValue(key).build());
});
entryDsl.getAttribute(VALUE_ATTRIBUTE_NAME).ifPresent(valueDsl -> value.accept(new ParameterValueVisitor() {
@Override
public void visitSimpleValue(ParameterSimpleValue text) {
entryConfigBuilder.withParameter(VALUE_ATTRIBUTE_NAME, text.getValue());
entryElement.containing(DslElementModel.builder().withModel(valueType).withDsl(valueDsl).withValue(text.getValue()).build());
}
@Override
public void visitListValue(ParameterListValue list) {
createList(list, valueDsl, valueType, (ArrayType) valueType, entryConfigBuilder, entryElement);
}
@Override
public void visitObjectValue(ParameterObjectValue objectValue) {
if (isMap(valueType)) {
createMapParameter(objectValue, valueDsl, valueType, (ObjectType) valueType, entryConfigBuilder, entryElement);
} else {
createObject(objectValue, valueDsl, valueType, (ObjectType) valueType, entryConfigBuilder, entryElement);
}
}
}));
ComponentConfiguration entryConfig = entryConfigBuilder.build();
mapConfig.withNestedComponent(entryConfig);
mapElement.containing(entryElement.withConfig(entryConfig).build());
}));
ComponentConfiguration result = mapConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(mapElement.withConfig(result).build());
}
use of org.mule.runtime.app.declaration.api.fluent.ParameterSimpleValue in project mule by mulesoft.
the class InfrastructureElementModelDelegate method createReconnectionConfig.
private void createReconnectionConfig(ParameterValue value, ParameterModel parameterModel, DslElementSyntax paramDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
InternalComponentConfiguration.Builder config = InternalComponentConfiguration.builder().withIdentifier(builder().namespace(CORE_PREFIX).name(RECONNECTION_CONFIG_PARAMETER_NAME).build());
final DslElementModel.Builder<Object> elementBuilder = DslElementModel.builder().withModel(parameterModel).withDsl(paramDsl);
((ParameterObjectValue) value).getParameters().forEach((name, fieldValue) -> fieldValue.accept(new ParameterValueVisitor() {
@Override
public void visitSimpleValue(ParameterSimpleValue text) {
config.withParameter(name, text.getValue());
}
@Override
public void visitObjectValue(ParameterObjectValue objectValue) {
if (name.equals(RECONNECTION_STRATEGY_PARAMETER_NAME)) {
createReconnectionStrategy(fieldValue, ((ObjectType) parameterModel.getType()).getFieldByName(RECONNECTION_STRATEGY_PARAMETER_NAME).get(), paramDsl.getContainedElement(RECONNECTION_STRATEGY_PARAMETER_NAME).get(), config, elementBuilder);
}
}
}));
final ComponentConfiguration result = config.build();
parentConfig.withNestedComponent(result);
parentElement.containing(elementBuilder.withConfig(result).build());
}
Aggregations