use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.
the class MuleExtensionModelDeclarer method declareSetPayload.
private void declareSetPayload(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
OperationDeclarer setPayload = extensionDeclarer.withOperation("setPayload").describedAs("A transformer that sets the payload with the provided value.");
setPayload.withOutput().ofType(typeLoader.load(void.class));
setPayload.withOutputAttributes().ofType(typeLoader.load(void.class));
setPayload.onDefaultParameterGroup().withOptionalParameter("encoding").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The encoding of the value assigned to the payload.");
setPayload.onDefaultParameterGroup().withRequiredParameter("value").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The value to be set on the payload. Supports expressions.");
setPayload.onDefaultParameterGroup().withOptionalParameter("mimeType").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The mime type, e.g. text/plain or application/json");
}
use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.
the class MuleExtensionModelDeclarer method declareParseTemplate.
private void declareParseTemplate(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
OperationDeclarer parseTemplate = extensionDeclarer.withOperation("parseTemplate").describedAs("Parses a template defined inline.");
parseTemplate.withOutput().ofType(typeLoader.load(String.class));
parseTemplate.withOutputAttributes().ofType(typeLoader.load(void.class));
parseTemplate.onDefaultParameterGroup().withOptionalParameter("content").ofType(typeLoader.load(String.class)).withRole(ParameterRole.PRIMARY_CONTENT).withExpressionSupport(SUPPORTED).describedAs("Template to be processed.");
parseTemplate.onDefaultParameterGroup().withOptionalParameter("location").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The location of the template. The order in which the transformer will attempt to load the file are: from the file system, from a URL, then from the classpath.");
}
use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method extractOperationExtension.
private void extractOperationExtension(HasOperationDeclarer declarer, ComponentModel operationModel, DirectedGraph<String, DefaultEdge> directedGraph, XmlDslModel xmlDslModel) {
String operationName = operationModel.getNameAttribute();
OperationDeclarer operationDeclarer = declarer.withOperation(operationName);
ComponentModel bodyComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_BODY_IDENTIFIER)).findFirst().orElseThrow(() -> new IllegalArgumentException(format("The operation '%s' is missing the <body> statement", operationName)));
directedGraph.addVertex(operationName);
fillGraphWithTnsReferences(directedGraph, operationName, bodyComponentModel.getInnerComponents());
operationDeclarer.withModelProperty(new OperationComponentModelModelProperty(operationModel, bodyComponentModel));
operationDeclarer.describedAs(getDescription(operationModel));
operationDeclarer.getDeclaration().setDisplayModel(getDisplayModel(operationModel));
extractOperationParameters(operationDeclarer, operationModel);
extractOutputType(operationDeclarer.withOutput(), OPERATION_OUTPUT_IDENTIFIER, operationModel, getDeclarationOutputFor(operationName));
extractOutputType(operationDeclarer.withOutputAttributes(), OPERATION_OUTPUT_ATTRIBUTES_IDENTIFIER, operationModel, getDeclarationOutputAttributesFor(operationName));
declareErrorModels(operationDeclarer, xmlDslModel, operationName, operationModel);
}
use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.
the class OperationModelLoaderDelegate method processNonBlockingOperation.
static void processNonBlockingOperation(OperationDeclarer operation, MethodElement operationMethod, boolean allowStreaming) {
List<ExtensionParameter> callbackParameters = operationMethod.getParameters().stream().filter(p -> p.getType().isSameType(CompletionCallback.class)).collect(toList());
checkDefinition(!callbackParameters.isEmpty(), format("Operation '%s' does not declare a '%s' parameter. One is required for a non-blocking operation", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
checkDefinition(callbackParameters.size() <= 1, format("Operation '%s' defines more than one %s parameters. Only one is allowed", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
checkDefinition(isVoid(operationMethod), format("Operation '%s' has a parameter of type %s but is not void. " + "Non-blocking operations have to be declared as void and the " + "return type provided through the callback", operationMethod.getAlias(), CompletionCallback.class.getSimpleName()));
ExtensionParameter callbackParameter = callbackParameters.get(0);
List<MetadataType> genericTypes = callbackParameter.getType().getGenerics().stream().map(generic -> generic.getConcreteType().asMetadataType()).collect(toList());
if (genericTypes.isEmpty()) {
// This is an invalid state, but is better to fail when executing the Extension Model Validators
genericTypes.add(ANY_TYPE);
genericTypes.add(ANY_TYPE);
}
operation.withOutput().ofType(genericTypes.get(0));
operation.withOutputAttributes().ofType(genericTypes.get(1));
operation.blocking(false);
if (allowStreaming) {
handleByteStreaming(operationMethod, operation, genericTypes.get(0));
} else {
operation.supportsStreaming(false);
}
}
Aggregations