Search in sources :

Example 1 with HasNestedComponentsDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.HasNestedComponentsDeclarer in project mule by mulesoft.

the class ParameterModelsLoaderDelegate method declare.

public List<ParameterDeclarer> declare(HasParametersDeclarer component, List<? extends ExtensionParameter> parameters, ParameterDeclarationContext declarationContext, ParameterGroupDeclarer parameterGroupDeclarer) {
    List<ParameterDeclarer> declarerList = new ArrayList<>();
    checkAnnotationsNotUsedMoreThanOnce(parameters, Connection.class, Config.class, MetadataKeyId.class);
    boolean supportsNestedElements = component instanceof HasNestedComponentsDeclarer;
    for (ExtensionParameter extensionParameter : parameters) {
        // Both nested components and parameters are declared using the @Parameter annotation in order to simplify the API
        if (supportsNestedElements && declaredAsNestedComponent((HasNestedComponentsDeclarer) component, extensionParameter)) {
            continue;
        }
        if (!extensionParameter.shouldBeAdvertised()) {
            continue;
        }
        if (isParameterGroup(extensionParameter)) {
            List<ParameterDeclarer> groupParams = declaredAsGroup(component, declarationContext, extensionParameter);
            declarerList.addAll(groupParams);
            continue;
        }
        ParameterGroupDeclarer groupDeclarer = parameterGroupDeclarer != null ? parameterGroupDeclarer : component.onDefaultParameterGroup();
        ParameterDeclarer parameter;
        if (extensionParameter.isRequired()) {
            parameter = groupDeclarer.withRequiredParameter(extensionParameter.getAlias());
        } else {
            parameter = groupDeclarer.withOptionalParameter(extensionParameter.getAlias()).defaultingTo(extensionParameter.defaultValue().isPresent() ? extensionParameter.defaultValue().get() : null);
        }
        parameter.ofType(extensionParameter.getType().asMetadataType()).describedAs(extensionParameter.getDescription());
        parseParameterRole(extensionParameter, parameter);
        parseExpressionSupport(extensionParameter, parameter);
        parseConfigOverride(extensionParameter, parameter);
        parseNullSafe(extensionParameter, parameter);
        parseLayout(extensionParameter, parameter);
        parseExclusiveOptional(extensionParameter, groupDeclarer, parameter);
        parameter.withModelProperty(new ExtensionParameterDescriptorModelProperty(extensionParameter));
        extensionParameter.getDeclaringElement().ifPresent(element -> addImplementingTypeModelProperty(element, parameter));
        parseParameterDsl(extensionParameter, parameter);
        contributors.forEach(contributor -> contributor.contribute(extensionParameter, parameter, declarationContext));
        declarerList.add(parameter);
    }
    return declarerList;
}
Also used : ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) HasNestedComponentsDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasNestedComponentsDeclarer) ArrayList(java.util.ArrayList) ExtensionParameterDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionParameterDescriptorModelProperty) ParameterGroupDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)

Aggregations

ArrayList (java.util.ArrayList)1 HasNestedComponentsDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasNestedComponentsDeclarer)1 ParameterDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer)1 ParameterGroupDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ParameterGroupDeclarer)1 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)1 ExtensionParameterDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionParameterDescriptorModelProperty)1