Search in sources :

Example 1 with HasConstructDeclarer

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

Aggregations

String.format (java.lang.String.format)1 Method (java.lang.reflect.Method)1 Arrays.asList (java.util.Arrays.asList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Collectors.toList (java.util.stream.Collectors.toList)1 ConstructDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer)1 Declarer (org.mule.runtime.api.meta.model.declaration.fluent.Declarer)1 ExtensionDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer)1 HasConstructDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasConstructDeclarer)1 HasOperationDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasOperationDeclarer)1 NestedRouteDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer)1 Parameter (org.mule.runtime.extension.api.annotation.param.Parameter)1 RouterCompletionCallback (org.mule.runtime.extension.api.runtime.process.RouterCompletionCallback)1 VoidCompletionCallback (org.mule.runtime.extension.api.runtime.process.VoidCompletionCallback)1 Route (org.mule.runtime.extension.api.runtime.route.Route)1 ComponentExecutorModelProperty (org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty)1 ExtensionParameter (org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter)1