Search in sources :

Example 1 with ReferableElementDeclaration

use of org.mule.runtime.app.declaration.api.ReferableElementDeclaration 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();
}
Also used : RouteElementDeclaration(org.mule.runtime.app.declaration.api.RouteElementDeclaration) ComposableModel(org.mule.runtime.api.meta.model.ComposableModel) DslElementSyntax(org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ReferableElementDeclaration(org.mule.runtime.app.declaration.api.ReferableElementDeclaration) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) DslElementModel(org.mule.runtime.config.api.dsl.model.DslElementModel) InternalComponentConfiguration(org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration) NestedRouteModel(org.mule.runtime.api.meta.model.nested.NestedRouteModel)

Aggregations

ComposableModel (org.mule.runtime.api.meta.model.ComposableModel)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1 NestedRouteModel (org.mule.runtime.api.meta.model.nested.NestedRouteModel)1 ReferableElementDeclaration (org.mule.runtime.app.declaration.api.ReferableElementDeclaration)1 RouteElementDeclaration (org.mule.runtime.app.declaration.api.RouteElementDeclaration)1 DslElementModel (org.mule.runtime.config.api.dsl.model.DslElementModel)1 InternalComponentConfiguration (org.mule.runtime.dsl.internal.component.config.InternalComponentConfiguration)1 DslElementSyntax (org.mule.runtime.extension.api.dsl.syntax.DslElementSyntax)1 DslSyntaxResolver (org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver)1