Search in sources :

Example 1 with ExtensionDeclarer

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

the class MuleExtensionModelDeclarer method createExtensionModel.

ExtensionDeclarer createExtensionModel() {
    final ClassTypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader(MuleExtensionModelDeclarer.class.getClassLoader());
    ExtensionDeclarer extensionDeclarer = new ExtensionDeclarer().named(MULE_NAME).describedAs("Mule Runtime and Integration Platform: Core components").onVersion(MULE_VERSION).fromVendor(MULESOFT_VENDOR).withCategory(COMMUNITY).withModelProperty(new CustomBuildingDefinitionProviderModelProperty()).withXmlDsl(XmlDslModel.builder().setPrefix(CORE_PREFIX).setNamespace(CORE_NAMESPACE).setSchemaVersion(MULE_VERSION).setXsdFileName(CORE_PREFIX + ".xsd").setSchemaLocation(CORE_SCHEMA_LOCATION).build());
    declareExportedTypes(typeLoader, extensionDeclarer);
    // constructs
    declareFlow(extensionDeclarer, typeLoader);
    declareSubflow(extensionDeclarer);
    declareChoice(extensionDeclarer, typeLoader);
    declareErrorHandler(extensionDeclarer, typeLoader);
    declareTry(extensionDeclarer, typeLoader);
    declareScatterGather(extensionDeclarer, typeLoader);
    declareSplitAggregate(extensionDeclarer, typeLoader);
    declareFirstSuccessful(extensionDeclarer);
    declareRoundRobin(extensionDeclarer);
    declareConfiguration(extensionDeclarer, typeLoader);
    declareConfigurationProperties(extensionDeclarer, typeLoader);
    declareAsync(extensionDeclarer, typeLoader);
    declareForEach(extensionDeclarer, typeLoader);
    declareUntilSuccessful(extensionDeclarer, typeLoader);
    // operations
    declareFlowRef(extensionDeclarer, typeLoader);
    declareIdempotentValidator(extensionDeclarer, typeLoader);
    declareLogger(extensionDeclarer, typeLoader);
    declareSetPayload(extensionDeclarer, typeLoader);
    declareSetVariable(extensionDeclarer, typeLoader);
    declareRemoveVariable(extensionDeclarer, typeLoader);
    declareParseTemplate(extensionDeclarer, typeLoader);
    declareRaiseError(extensionDeclarer, typeLoader);
    // sources
    declareScheduler(extensionDeclarer, typeLoader);
    // errors
    declareErrors(extensionDeclarer);
    return extensionDeclarer;
}
Also used : ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) CustomBuildingDefinitionProviderModelProperty(org.mule.runtime.core.internal.extension.CustomBuildingDefinitionProviderModelProperty)

Example 2 with ExtensionDeclarer

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

the class SoapModelLoaderDelegate method declare.

/**
 * {@inheritDoc}
 */
public ExtensionDeclarer declare(ExtensionLoadingContext context) {
    final SoapExtensionTypeWrapper<?> extension = getSoapExtensionType(this.extensionType, typeLoader);
    List<MessageDispatcherProviderTypeWrapper> customTransportProviders = extension.getDispatcherProviders();
    ExtensionDeclarer extensionDeclarer = getExtensionDeclarer(context);
    declareSubtypes(extensionDeclarer, customTransportProviders);
    Set<ErrorModel> soapErrors = getSoapErrors(extensionDeclarer);
    soapErrors.forEach(extensionDeclarer::withErrorModel);
    ConfigurationDeclarer configDeclarer = getConfigDeclarer(extensionDeclarer, extension, soapErrors);
    extension.getSoapServiceProviders().forEach(provider -> serviceProviderDeclarer.declare(configDeclarer, provider, !customTransportProviders.isEmpty()));
    return extensionDeclarer;
}
Also used : MessageDispatcherProviderTypeWrapper(org.mule.runtime.module.extension.soap.internal.loader.type.runtime.MessageDispatcherProviderTypeWrapper) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) ConfigurationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclarer) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel)

Example 3 with ExtensionDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer 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)

Example 4 with ExtensionDeclarer

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

the class RouterModelLoaderDelegate method declareRouter.

void declareRouter(ExtensionDeclarer extensionDeclarer, HasOperationDeclarer ownerDeclarer, OperationContainerElement enclosingType, OperationElement routerMethod, Optional<ExtensionParameter> configParameter, Optional<ExtensionParameter> connectionParameter) {
    checkDefinition(!configParameter.isPresent(), format("Scope '%s' requires a config, but that is not allowed, remove such parameter", routerMethod.getName()));
    checkDefinition(!connectionParameter.isPresent(), format("Scope '%s' requires a connection, but that is not allowed, remove such parameter", routerMethod.getName()));
    HasConstructDeclarer actualDeclarer = (HasConstructDeclarer) loader.selectDeclarerBasedOnConfig(extensionDeclarer, (Declarer) ownerDeclarer, configParameter, connectionParameter);
    if (constructDeclarers.containsKey(routerMethod)) {
        actualDeclarer.withConstruct(constructDeclarers.get(routerMethod));
        return;
    }
    final ConstructDeclarer router = actualDeclarer.withConstruct(routerMethod.getAlias());
    router.withModelProperty(new ExtensionOperationDescriptorModelProperty(routerMethod));
    Optional<Method> method = routerMethod.getMethod();
    Optional<Class<?>> declaringClass = enclosingType.getDeclaringClass();
    if (method.isPresent() && declaringClass.isPresent()) {
        router.withModelProperty(new ImplementingMethodModelProperty(method.get())).withModelProperty(new ComponentExecutorModelProperty(new ReflectiveOperationExecutorFactory<>(declaringClass.get(), method.get())));
    }
    processMimeType(router, routerMethod);
    List<ExtensionParameter> callbackParameters = routerMethod.getParameters().stream().filter(p -> VALID_CALLBACK_PARAMETERS.stream().anyMatch(validType -> p.getType().isSameType(validType))).collect(toList());
    List<ExtensionParameter> routes = routerMethod.getParameters().stream().filter(this::isRoute).collect(toList());
    checkDefinition(!callbackParameters.isEmpty(), format("Router '%s' does not declare a parameter with one of the types '%s'. One is required.", routerMethod.getAlias(), VALID_CALLBACK_PARAMETERS));
    checkDefinition(!routes.isEmpty(), format("Router '%s' does not declare a '%s' parameter. One is required.", routerMethod.getAlias(), Route.class.getSimpleName()));
    checkDefinition(callbackParameters.size() <= 1, format("Router '%s' defines more than one CompletionCallback parameters. Only one is allowed", routerMethod.getAlias()));
    checkDefinition(isVoid(routerMethod), format("Router '%s' is not declared in a void method.", routerMethod.getAlias()));
    List<ExtensionParameter> nonRouteParameters = routerMethod.getParameters().stream().filter(p -> !isRoute(p) && !callbackParameters.contains(p)).collect(toList());
    declareParameters(router, nonRouteParameters, routerMethod.getEnclosingType().getParameters(), new ParameterDeclarationContext(CONSTRUCT, router.getDeclaration()));
    declareRoutes(router, routes);
}
Also used : OperationModelLoaderDelegate.checkDefinition(org.mule.runtime.module.extension.internal.loader.java.OperationModelLoaderDelegate.checkDefinition) FieldElement(org.mule.runtime.module.extension.api.loader.java.type.FieldElement) HashMap(java.util.HashMap) RouterCompletionCallback(org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback) OperationElement(org.mule.runtime.module.extension.api.loader.java.type.OperationElement) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer) VoidCompletionCallback(org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback) Parameter(org.mule.runtime.extension.api.annotation.param.Parameter) Method(java.lang.reflect.Method) String.format(java.lang.String.format) HasConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer) NestedRouteDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) IntrospectionUtils.isVoid(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isVoid) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty) Route(org.mule.runtime.extension.api.runtime.route.Route) OperationContainerElement(org.mule.runtime.module.extension.api.loader.java.type.OperationContainerElement) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer) HasConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) Method(java.lang.reflect.Method) HasConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer) HasConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer) NestedRouteDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty)

Example 5 with ExtensionDeclarer

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

the class ScopeModelLoaderDelegate method declareScope.

void declareScope(ExtensionDeclarer extensionDeclarer, HasOperationDeclarer ownerDeclarer, OperationContainerElement enclosingType, OperationElement scopeMethod, Optional<ExtensionParameter> configParameter, Optional<ExtensionParameter> connectionParameter) {
    HasOperationDeclarer actualDeclarer = (HasOperationDeclarer) loader.selectDeclarerBasedOnConfig(extensionDeclarer, (Declarer) ownerDeclarer, configParameter, connectionParameter);
    checkDefinition(!configParameter.isPresent(), format("Scope '%s' requires a config, but that is not allowed, remove such parameter", scopeMethod.getName()));
    checkDefinition(!connectionParameter.isPresent(), format("Scope '%s' requires a connection, but that is not allowed, remove such parameter", scopeMethod.getName()));
    checkDefinition(isNonBlocking(scopeMethod), format("Scope '%s' does not declare a '%s' parameter. One is required for all operations " + "that receive and execute a Chain of other components", scopeMethod.getAlias(), CompletionCallback.class.getSimpleName()));
    if (operationDeclarers.containsKey(scopeMethod)) {
        actualDeclarer.withOperation(operationDeclarers.get(scopeMethod));
        return;
    }
    final OperationDeclarer scope = actualDeclarer.withOperation(scopeMethod.getAlias());
    scope.withModelProperty(new ExtensionOperationDescriptorModelProperty(scopeMethod));
    Optional<Method> method = scopeMethod.getMethod();
    Optional<Class<?>> declaringClass = enclosingType.getDeclaringClass();
    if (method.isPresent() && declaringClass.isPresent()) {
        scope.withModelProperty(new ImplementingMethodModelProperty(method.get())).withModelProperty(new ComponentExecutorModelProperty(new ReflectiveOperationExecutorFactory<>(declaringClass.get(), method.get())));
    }
    processMimeType(scope, scopeMethod);
    processNonBlockingOperation(scope, scopeMethod, false);
    List<ExtensionParameter> processorChain = scopeMethod.getParameters().stream().filter(ModelLoaderUtils::isProcessorChain).collect(toList());
    checkDefinition(processorChain.size() <= 1, format("Scope '%s' declares too many parameters of type '%s', only one input of this kind is supported." + "Offending parameters are: %s", scopeMethod.getAlias(), Chain.class.getSimpleName(), processorChain.stream().map(ExtensionParameter::getName).collect(toList())));
    declareParameters(scope, scopeMethod.getParameters(), scopeMethod.getEnclosingType().getParameters(), new ParameterDeclarationContext(SCOPE, scope.getDeclaration()));
    loader.addExceptionEnricher(scopeMethod, scope);
    operationDeclarers.put(scopeMethod, scope);
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) Method(java.lang.reflect.Method) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ImplementingMethodModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) HasOperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty)

Aggregations

ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)35 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)15 Test (org.junit.Test)14 SmallTest (org.mule.tck.size.SmallTest)14 DefaultExtensionLoadingContext (org.mule.runtime.extension.internal.loader.DefaultExtensionLoadingContext)8 MetadataType (org.mule.metadata.api.model.MetadataType)6 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)6 Before (org.junit.Before)5 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)5 HeisenbergExtension (org.mule.test.heisenberg.extension.HeisenbergExtension)5 Declarer (org.mule.runtime.api.meta.model.declaration.fluent.Declarer)4 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)4 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)4 ObjectType (org.mule.metadata.api.model.ObjectType)3 ConfigurationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration)3 HasOperationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer)3 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)3 ExtensionLoadingContext (org.mule.runtime.extension.api.loader.ExtensionLoadingContext)3 DefaultJavaModelLoaderDelegate (org.mule.runtime.module.extension.internal.loader.java.DefaultJavaModelLoaderDelegate)3 ImplementingMethodModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty)3