Search in sources :

Example 6 with ParameterDeclarationContext

use of org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext in project mule by mulesoft.

the class RouterModelLoaderDelegate method declareRoutes.

private void declareRoutes(ConstructDeclarer router, List<ExtensionParameter> routes) {
    routes.forEach(route -> {
        NestedRouteDeclarer routeDeclarer = router.withRoute(route.getAlias()).describedAs(route.getDescription()).withMinOccurs(route.isRequired() ? 1 : 0);
        route.getType().getDeclaringClass().ifPresent(clazz -> routeDeclarer.withModelProperty(new ImplementingTypeModelProperty(clazz)));
        final List<FieldElement> parameters = route.getType().getAnnotatedFields(Parameter.class);
        loader.getFieldParametersLoader().declare(routeDeclarer, parameters, new ParameterDeclarationContext(CONSTRUCT, router.getDeclaration()));
    });
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) FieldElement(org.mule.runtime.module.extension.api.loader.java.type.FieldElement) NestedRouteDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)

Example 7 with ParameterDeclarationContext

use of org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext 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)

Example 8 with ParameterDeclarationContext

use of org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext in project mule by mulesoft.

the class SourceModelLoaderDelegate method declareSourceParameters.

/**
 * Declares the parameters needed to generate messages
 */
private void declareSourceParameters(SourceElement sourceType, SourceDeclarer source) {
    ParameterModelsLoaderDelegate parametersLoader = loader.getFieldParametersLoader();
    ParameterDeclarationContext declarationContext = new ParameterDeclarationContext(SOURCE, source.getDeclaration());
    List<ParameterDeclarer> parameters = parametersLoader.declare(source, sourceType.getParameters(), declarationContext);
    parameters.forEach(p -> p.withExpressionSupport(NOT_SUPPORTED));
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ParameterDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer)

Example 9 with ParameterDeclarationContext

use of org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext in project mule by mulesoft.

the class SoapServiceProviderDeclarer method declare.

/**
 * Declares a new connection provider for a configuration given a {@link SoapServiceProviderWrapper} declaration.
 *
 * @param configDeclarer      the configuration declarer that will own the provider
 * @param provider            a {@link SoapServiceProviderWrapper} that describes the {@link SoapServiceProvider} Type.
 * @param hasCustomTransports if declares custom transport or not.
 */
public void declare(ConfigurationDeclarer configDeclarer, SoapServiceProviderWrapper provider, boolean hasCustomTransports) {
    String description = provider.getDescription();
    // Declares the Service Provider as a Connection Provider.
    ConnectionProviderDeclarer providerDeclarer = configDeclarer.withConnectionProvider(provider.getAlias()).describedAs(description).withModelProperty(new ConnectionTypeModelProperty(ForwardingSoapClient.class)).withModelProperty(new ImplementingTypeModelProperty(provider.getDeclaringClass().get())).withConnectionManagementType(POOLING).supportsConnectivityTesting(provider.supportsConnectivityTesting());
    ParameterDeclarationContext context = new ParameterDeclarationContext("Service Provider", providerDeclarer.getDeclaration());
    parametersLoader.declare(providerDeclarer, provider.getParameters(), context);
    if (hasCustomTransports) {
        providerDeclarer.onParameterGroup(TRANSPORT_GROUP).withRequiredParameter(TRANSPORT_PARAM).withDisplayModel(DisplayModel.builder().displayName(TRANSPORT_GROUP).build()).ofType(typeLoader.load(MessageDispatcherProvider.class)).withLayout(LayoutModel.builder().order(1).tabName(TRANSPORT).build()).withExpressionSupport(NOT_SUPPORTED);
    }
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) ConnectionTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConnectionTypeModelProperty) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) MessageDispatcherProvider(org.mule.runtime.extension.api.soap.MessageDispatcherProvider)

Example 10 with ParameterDeclarationContext

use of org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext in project mule by mulesoft.

the class SourceModelLoaderDelegate method declareSourceCallbackParameters.

private void declareSourceCallbackParameters(SourceDeclarer source, Optional<MethodElement> sourceCallback, Supplier<ParameterizedDeclarer> callback) {
    sourceCallback.ifPresent(method -> {
        ParameterDeclarationContext declarationContext = new ParameterDeclarationContext(SOURCE, source.getDeclaration());
        loader.getMethodParametersLoader().declare(callback.get(), method.getParameters(), declarationContext);
    });
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext)

Aggregations

ParameterDeclarationContext (org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext)11 Declarer (org.mule.runtime.api.meta.model.declaration.fluent.Declarer)4 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)4 ImplementingMethodModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingMethodModelProperty)4 ImplementingTypeModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)4 Method (java.lang.reflect.Method)3 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)3 HasOperationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer)3 ComponentExecutorModelProperty (org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty)3 ExtensionOperationDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty)3 ReflectiveOperationExecutorFactory (org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory)3 String.format (java.lang.String.format)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 ConnectionProviderDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer)2 NestedRouteDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer)2 OperationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer)2 ParameterDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ParameterDeclarer)2 FieldElement (org.mule.runtime.module.extension.api.loader.java.type.FieldElement)2 OperationContainerElement (org.mule.runtime.module.extension.api.loader.java.type.OperationContainerElement)2