use of org.mule.runtime.api.meta.model.ComposableModel 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.api.meta.model.ComposableModel in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareRoute.
private Optional<RouteElementDeclaration> declareRoute(ComposableModel model, DslElementSyntax elementDsl, ConfigLine child, ElementDeclarer extensionElementsDeclarer) {
return model.getNestedComponents().stream().filter(nestedModel -> elementDsl.getContainedElement(nestedModel.getName()).map(nestedDsl -> child.getIdentifier().equals(nestedDsl.getElementName())).orElse(false)).filter(nestedModel -> nestedModel instanceof NestedRouteModel).findFirst().map(nestedModel -> {
RouteElementDeclarer routeDeclarer = extensionElementsDeclarer.newRoute(nestedModel.getName());
DslElementSyntax routeDsl = elementDsl.getContainedElement(nestedModel.getName()).get();
declareParameterizedComponent((ParameterizedModel) nestedModel, routeDsl, routeDeclarer, child.getConfigAttributes(), child.getChildren());
declareComposableModel((ComposableModel) nestedModel, elementDsl, child, routeDeclarer);
return routeDeclarer.getDeclaration();
});
}
use of org.mule.runtime.api.meta.model.ComposableModel in project mule by mulesoft.
the class DefaultXmlArtifactDeclarationLoader method declareComposableModel.
private void declareComposableModel(ComposableModel model, DslElementSyntax elementDsl, ConfigLine containerConfig, HasNestedComponentDeclarer declarer) {
containerConfig.getChildren().forEach((ConfigLine child) -> {
ExtensionModel extensionModel = getExtensionModel(child);
ElementDeclarer extensionElementsDeclarer = forExtension(extensionModel.getName());
Reference<Boolean> componentFound = new Reference<>(false);
getComponentDeclaringWalker(declaration -> {
declarer.withComponent(declaration);
componentFound.set(true);
}, child, extensionElementsDeclarer).walk(extensionModel);
if (!componentFound.get()) {
declareRoute(model, elementDsl, child, extensionElementsDeclarer).ifPresent(declarer::withComponent);
}
});
}
use of org.mule.runtime.api.meta.model.ComposableModel in project mule by mulesoft.
the class ConfigurationBasedElementModelFactory method populateComposableElements.
private void populateComposableElements(ComposableModel model, DslElementSyntax elementDsl, DslElementModel.Builder builder, ComponentConfiguration configuration) {
configuration.getNestedComponents().forEach(nestedComponentConfig -> {
DslElementModel nestedElement = createIdentifiedElement(nestedComponentConfig);
if (nestedElement != null) {
builder.containing(nestedElement);
} else {
model.getNestedComponents().stream().filter(nestedModel -> nestedModel instanceof NestedRouteModel).filter(nestedModel -> elementDsl.getContainedElement(nestedModel.getName()).map(nestedDsl -> getIdentifier(nestedDsl).map(id -> nestedComponentConfig.getIdentifier().equals(id)).orElse(false)).orElse(false)).findFirst().ifPresent(nestedModel -> {
DslElementSyntax routeDsl = elementDsl.getContainedElement(nestedModel.getName()).get();
DslElementModel.Builder<? extends NestableElementModel> routeBuilder = DslElementModel.<NestableElementModel>builder().withModel(nestedModel).withDsl(routeDsl).withConfig(nestedComponentConfig).isExplicitInDsl(true);
populateParameterizedElements((ParameterizedModel) nestedModel, routeDsl, routeBuilder, nestedComponentConfig);
nestedComponentConfig.getNestedComponents().forEach(routeElement -> {
DslElementModel nestableElementModel = createIdentifiedElement(routeElement);
if (nestableElementModel != null) {
routeBuilder.containing(nestableElementModel);
}
});
builder.containing(routeBuilder.build());
});
}
});
}
Aggregations