use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method addConnectionProvider.
private void addConnectionProvider(ConnectionElementDeclaration connection, ConfigurationModel model, InternalComponentConfiguration.Builder configuration, DslElementModel.Builder<ConfigurationModel> configElement) {
concat(model.getConnectionProviders().stream(), currentExtension.getConnectionProviders().stream()).filter(c -> c.getName().equals(connection.getName())).findFirst().ifPresent(provider -> {
DslElementSyntax providerDsl = dsl.resolve(provider);
InternalComponentConfiguration.Builder builder = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(providerDsl));
DslElementModel.Builder<ConnectionProviderModel> element = createParameterizedElementModel(provider, providerDsl, connection, builder);
ComponentConfiguration providerConfig = builder.build();
configuration.withNestedComponent(providerConfig);
configElement.containing(element.withConfig(providerConfig).build());
});
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createTopLevelElement.
private DslElementModel createTopLevelElement(ObjectType model, TopLevelParameterDeclaration declaration) {
DslElementSyntax objectDsl = dsl.resolve(model).orElseThrow(() -> new IllegalArgumentException("Failed to resolve the DSL syntax for type '" + getId(model) + "'"));
DslElementModel.Builder<MetadataType> parentElement = DslElementModel.<MetadataType>builder().withModel(model).withDsl(objectDsl);
InternalComponentConfiguration.Builder configuration = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(objectDsl)).withParameter(NAME_ATTRIBUTE_NAME, declaration.getRefName());
populateObjectElementFields(model, declaration.getValue(), objectDsl, configuration, parentElement);
return parentElement.withConfig(configuration.build()).build();
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method createComponentElement.
private DslElementModel<? extends ComponentModel> createComponentElement(ComponentModel model, ComponentElementDeclaration<?> componentDeclaration) {
DslElementSyntax configDsl = dsl.resolve(model);
InternalComponentConfiguration.Builder configuration = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(configDsl));
if (componentDeclaration instanceof ReferableElementDeclaration) {
configuration.withParameter(NAME_ATTRIBUTE_NAME, ((ReferableElementDeclaration) componentDeclaration).getRefName());
}
if (componentDeclaration.getConfigRef() != null) {
configuration.withParameter(CONFIG_ATTRIBUTE_NAME, componentDeclaration.getConfigRef());
}
DslElementModel.Builder<? extends ComponentModel> componentElement = createParameterizedElementModel(model, configDsl, componentDeclaration, configuration);
ExtensionModel componentsOwner = currentExtension;
DslSyntaxResolver componentsDslResolver = dsl;
componentDeclaration.getComponents().forEach(nestedComponentDeclaration -> {
if (nestedComponentDeclaration instanceof RouteElementDeclaration) {
if (model instanceof ComposableModel) {
((ComposableModel) model).getNestedComponents().stream().filter(nestedModel -> nestedModel instanceof NestedRouteModel && nestedModel.getName().equals(nestedComponentDeclaration.getName())).findFirst().ifPresent(nestedRouteModel -> componentElement.containing(crateRouteElement((NestedRouteModel) nestedRouteModel, (RouteElementDeclaration) nestedComponentDeclaration)));
}
} else {
create(nestedComponentDeclaration).ifPresent(nestedComponentElement -> {
nestedComponentElement.getConfiguration().ifPresent(configuration::withNestedComponent);
componentElement.containing(nestedComponentElement);
});
}
currentExtension = componentsOwner;
dsl = componentsDslResolver;
});
return componentElement.withConfig(configuration.build()).build();
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax in project mule by mulesoft.
the class DeclarationBasedElementModelFactory method crateRouteElement.
private DslElementModel<? extends NestedRouteModel> crateRouteElement(NestedRouteModel model, RouteElementDeclaration routeDeclaration) {
DslElementSyntax routeDsl = dsl.resolve(model);
InternalComponentConfiguration.Builder routeConfiguration = InternalComponentConfiguration.builder().withIdentifier(asIdentifier(routeDsl));
DslElementModel.Builder<? extends NestedRouteModel> routeElement = createParameterizedElementModel(model, routeDsl, routeDeclaration, routeConfiguration);
ExtensionModel routerOwner = currentExtension;
DslSyntaxResolver routerDslResolver = dsl;
routeDeclaration.getComponents().forEach(componentDeclaration -> {
create(componentDeclaration).ifPresent(componentElement -> {
componentElement.getConfiguration().ifPresent(routeConfiguration::withNestedComponent);
routeElement.containing(componentElement);
});
currentExtension = routerOwner;
dsl = routerDslResolver;
});
return routeElement.withConfig(routeConfiguration.build()).build();
}
use of org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax 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());
}
Aggregations