use of org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createWrappedObject.
private void createWrappedObject(ParameterObjectValue objectValue, ParameterModel parameterModel, DslElementSyntax paramDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
DslElementModel.Builder<ParameterModel> wrapperElement = DslElementModel.<ParameterModel>builder().withModel(parameterModel).withDsl(paramDsl);
InternalComponentConfiguration.Builder wrapperConfig = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(paramDsl));
Reference<DslSyntaxResolver> customDsl = new Reference<>(dsl);
ObjectType nestedElementType;
if (objectValue.getTypeId() == null || objectValue.getTypeId().trim().isEmpty() || getId(parameterModel.getType()).map(id -> id.equals(objectValue.getTypeId())).orElse(false)) {
nestedElementType = (ObjectType) parameterModel.getType();
} else {
nestedElementType = lookupType(objectValue);
context.getTypeCatalog().getDeclaringExtension(objectValue.getTypeId()).ifPresent(owner -> context.getExtension(owner).ifPresent(extensionModel -> customDsl.set(resolvers.get(extensionModel))));
}
customDsl.get().resolve(nestedElementType).ifPresent(typeDsl -> createObject(objectValue, typeDsl, nestedElementType, nestedElementType, wrapperConfig, wrapperElement));
ComponentConfiguration result = wrapperConfig.build();
parentConfig.withNestedComponent(result);
parentElement.containing(wrapperElement.withConfig(result).build());
}
use of org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue 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.ParameterObjectValue in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareElement.
private void declareElement(final ConfigLine configLine, final ArtifactDeclarer artifactDeclarer) {
final ExtensionModel ownerExtension = getExtensionModel(configLine);
final ElementDeclarer extensionElementsDeclarer = forExtension(ownerExtension.getName());
final DslSyntaxResolver dsl = resolvers.get(getNamespace(configLine));
Reference<Boolean> alreadyDeclared = new Reference<>(false);
new ExtensionWalker() {
@Override
protected void onConstruct(HasConstructModels owner, ConstructModel model) {
declareComponentModel(configLine, model, extensionElementsDeclarer::newConstruct).ifPresent(declarer -> {
getDeclaredName(configLine).ifPresent(((ConstructElementDeclarer) declarer)::withRefName);
artifactDeclarer.withGlobalElement((GlobalElementDeclaration) declarer.getDeclaration());
alreadyDeclared.set(true);
stop();
});
}
@Override
protected void onConfiguration(ConfigurationModel model) {
final DslElementSyntax elementDsl = dsl.resolve(model);
if (elementDsl.getElementName().equals(configLine.getIdentifier())) {
ConfigurationElementDeclarer configurationDeclarer = extensionElementsDeclarer.newConfiguration(model.getName());
getDeclaredName(configLine).ifPresent(configurationDeclarer::withRefName);
Map<String, SimpleConfigAttribute> attributes = configLine.getConfigAttributes().values().stream().filter(a -> !a.getName().equals(NAME_ATTRIBUTE_NAME)).collect(toMap(SimpleConfigAttribute::getName, a -> a));
List<ConfigLine> configComplexParameters = configLine.getChildren().stream().filter(config -> declareAsConnectionProvider(ownerExtension, model, configurationDeclarer, config, extensionElementsDeclarer)).collect(toList());
declareParameterizedComponent(model, elementDsl, configurationDeclarer, attributes, configComplexParameters);
artifactDeclarer.withGlobalElement(configurationDeclarer.getDeclaration());
alreadyDeclared.set(true);
stop();
}
}
}.walk(ownerExtension);
if (!alreadyDeclared.get()) {
ownerExtension.getTypes().stream().filter(type -> dsl.resolve(type).map(typeDsl -> typeDsl.getElementName().equals(configLine.getIdentifier())).orElse(false)).findFirst().ifPresent(type -> {
TopLevelParameterDeclarer topLevelParameter = extensionElementsDeclarer.newGlobalParameter(configLine.getIdentifier());
getDeclaredName(configLine).ifPresent(topLevelParameter::withRefName);
type.accept(getParameterDeclarerVisitor(configLine, dsl.resolve(type).get(), value -> topLevelParameter.withValue((ParameterObjectValue) value)));
artifactDeclarer.withGlobalElement(topLevelParameter.getDeclaration());
});
}
}
use of org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue in project mule by mulesoft.
the class InfrastructureElementModelDelegate method createReconnectionStrategy.
private void createReconnectionStrategy(ParameterValue value, Object parameterModel, DslElementSyntax paramDsl, InternalComponentConfiguration.Builder parentConfig, DslElementModel.Builder parentElement) {
ParameterObjectValue objectValue = (ParameterObjectValue) value;
checkArgument(!isBlank(objectValue.getTypeId()), "Missing declaration of which reconnection to use");
String elementName = objectValue.getTypeId().equals(RECONNECT_ALIAS) ? RECONNECT_ELEMENT_IDENTIFIER : RECONNECT_FOREVER_ELEMENT_IDENTIFIER;
cloneDeclarationToElement(parameterModel, paramDsl, parentConfig, parentElement, objectValue, elementName, paramDsl.getNamespace());
}
use of org.mule.runtime.app.declaration.api.fluent.ParameterObjectValue 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