Search in sources :

Example 1 with FunctionExecutorModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.property.FunctionExecutorModelProperty in project mule by mulesoft.

the class FunctionModelLoaderDelegate method declareFunctions.

void declareFunctions(ExtensionDeclarer extensionDeclarer, HasFunctionDeclarer declarer, FunctionContainerElement methodOwnerClass, List<FunctionElement> functions) {
    for (FunctionElement function : functions) {
        FunctionContainerElement functionOwner = methodOwnerClass != null ? methodOwnerClass : function.getEnclosingType();
        checkIsNotAnExtension(functionOwner);
        final Optional<ExtensionParameter> configParameter = loader.getConfigParameter(function);
        if (configParameter.isPresent()) {
            throw new IllegalModelDefinitionException(format("Function '%s' requires a config parameter, but that is not allowed. " + "Remove such parameter.", function.getName()));
        }
        HasFunctionDeclarer actualDeclarer = (HasFunctionDeclarer) loader.selectDeclarerBasedOnConfig(extensionDeclarer, (Declarer) declarer, configParameter, empty());
        if (functionDeclarers.containsKey(function)) {
            actualDeclarer.withFunction(functionDeclarers.get(function));
            continue;
        }
        final FunctionDeclarer functionDeclarer = actualDeclarer.withFunction(function.getAlias());
        function.getMethod().ifPresent(method -> {
            functionDeclarer.withModelProperty(new ImplementingMethodModelProperty(method));
            function.getDeclaringClass().ifPresent(clazz -> functionDeclarer.withModelProperty(new FunctionExecutorModelProperty(new ReflectiveFunctionExecutorFactory<>(clazz, method))));
        });
        functionDeclarer.withOutput().ofType(function.getReturnMetadataType());
        ParameterDeclarationContext declarationContext = new ParameterDeclarationContext(FUNCTION, functionDeclarer.getDeclaration());
        loader.getMethodParametersLoader().declare(functionDeclarer, function.getParameters(), declarationContext);
        functionDeclarers.put(function, functionDeclarer);
    }
}
Also used : FunctionContainerElement(org.mule.runtime.module.extension.api.loader.java.type.FunctionContainerElement) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) FunctionElement(org.mule.runtime.module.extension.api.loader.java.type.FunctionElement) FunctionExecutorModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.FunctionExecutorModelProperty) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) HasFunctionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasFunctionDeclarer) FunctionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.FunctionDeclarer) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) HasFunctionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasFunctionDeclarer) FunctionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.FunctionDeclarer) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) HasFunctionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasFunctionDeclarer)

Aggregations

Declarer (org.mule.runtime.api.meta.model.declaration.fluent.Declarer)1 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)1 FunctionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.FunctionDeclarer)1 HasFunctionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasFunctionDeclarer)1 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)1 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)1 FunctionContainerElement (org.mule.runtime.module.extension.api.loader.java.type.FunctionContainerElement)1 FunctionElement (org.mule.runtime.module.extension.api.loader.java.type.FunctionElement)1 FunctionExecutorModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.FunctionExecutorModelProperty)1 ImplementingMethodModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty)1 ParameterDeclarationContext (org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext)1