Search in sources :

Example 1 with NestedRouteDeclarer

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

the class MuleExtensionModelDeclarer method declareChoice.

private void declareChoice(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
    ConstructDeclarer choice = extensionDeclarer.withConstruct("choice").describedAs("Sends the message to the first message processor whose condition has been satisfied. " + "If no conditions were satisfied, sends to the configured default message processor (if configured), " + "or throws an exception (if not configured).").withErrorModel(routingError);
    NestedRouteDeclarer when = choice.withRoute("when").withMinOccurs(1);
    when.withChain();
    when.onDefaultParameterGroup().withRequiredParameter("expression").ofType(typeLoader.load(boolean.class)).describedAs("The expression to evaluate.");
    choice.withRoute("otherwise").withMaxOccurs(1).withChain();
}
Also used : ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer) NestedRouteDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer)

Example 2 with NestedRouteDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer 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 3 with NestedRouteDeclarer

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

the class MuleExtensionModelDeclarer method declareErrorHandler.

private void declareErrorHandler(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
    ConstructDeclarer errorHandler = extensionDeclarer.withConstruct("errorHandler").withStereotype(ERROR_HANDLER).allowingTopLevelDefinition().describedAs("Allows the definition of internal selective handlers. It will route the error to the first handler that matches it." + " If there's no match, then a default error handler will be executed.");
    errorHandler.onDefaultParameterGroup().withOptionalParameter("ref").withAllowedStereotypes(singletonList(ERROR_HANDLER)).ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The name of the error handler to reuse.");
    NestedRouteDeclarer onErrorContinue = errorHandler.withRoute("onErrorContinue").describedAs("Error handler used to handle exceptions. It will commit any transaction as if the message was consumed successfully.");
    declareOnErrorRoute(typeLoader, onErrorContinue);
    NestedRouteDeclarer onErrorPropagate = errorHandler.withRoute("onErrorPropagate").describedAs("Error handler used to propagate errors. It will rollback any transaction and not consume messages.");
    declareOnErrorRoute(typeLoader, onErrorPropagate);
    errorHandler.withOptionalComponent("onError").withAllowedStereotypes(ON_ERROR).describedAs("Error handler used to reference other ones.");
    ConstructDeclarer onError = extensionDeclarer.withConstruct("onError").withStereotype(ON_ERROR).describedAs("Error handler used to reference other ones.");
    onError.onDefaultParameterGroup().withRequiredParameter("ref").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The name of the error handler to reuse.");
// TODO MULE-13277 errorHandler.isOneRouteRequired(true);
}
Also used : ConstructDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer) NestedRouteDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer)

Aggregations

NestedRouteDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.NestedRouteDeclarer)3 ConstructDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclarer)2 FieldElement (org.mule.runtime.module.extension.api.loader.java.type.FieldElement)1 ImplementingTypeModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)1 ParameterDeclarationContext (org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext)1