use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.
the class OperationModelLoaderDelegate method declareOperations.
void declareOperations(ExtensionDeclarer extensionDeclarer, HasOperationDeclarer ownerDeclarer, OperationContainerElement methodOwnerClass, List<OperationElement> operations, boolean supportsConfig) {
for (OperationElement operationMethod : operations) {
OperationContainerElement methodOwner = operationMethod.getEnclosingType();
OperationContainerElement enclosingType = methodOwnerClass != null ? methodOwnerClass : methodOwner;
checkOperationIsNotAnExtension(methodOwner);
final Optional<ExtensionParameter> configParameter = loader.getConfigParameter(operationMethod);
final Optional<ExtensionParameter> connectionParameter = loader.getConnectionParameter(operationMethod);
if (isScope(operationMethod)) {
scopesDelegate.declareScope(extensionDeclarer, ownerDeclarer, enclosingType, operationMethod, configParameter, connectionParameter);
continue;
} else if (isRouter(operationMethod)) {
routersDelegate.declareRouter(extensionDeclarer, ownerDeclarer, enclosingType, operationMethod, configParameter, connectionParameter);
continue;
}
checkDefinition(!loader.isInvalidConfigSupport(supportsConfig, configParameter, connectionParameter), format("Operation '%s' is defined at the extension level but it requires a config. " + "Remove such parameter or move the operation to the proper config", operationMethod.getName()));
HasOperationDeclarer actualDeclarer = selectDeclarer(extensionDeclarer, (Declarer) ownerDeclarer, operationMethod, configParameter, connectionParameter);
if (operationDeclarers.containsKey(operationMethod)) {
actualDeclarer.withOperation(operationDeclarers.get(operationMethod));
continue;
}
final OperationDeclarer operationDeclarer = actualDeclarer.withOperation(operationMethod.getAlias());
operationDeclarer.withModelProperty(new ExtensionOperationDescriptorModelProperty(operationMethod));
Optional<Method> method = operationMethod.getMethod();
Optional<Class<?>> declaringClass = enclosingType.getDeclaringClass();
if (method.isPresent() && declaringClass.isPresent()) {
operationDeclarer.withModelProperty(new ImplementingMethodModelProperty(method.get())).withModelProperty(new ComponentExecutorModelProperty(new ReflectiveOperationExecutorFactory<>(declaringClass.get(), method.get())));
}
loader.addExceptionEnricher(operationMethod, operationDeclarer);
final List<ExtensionParameter> fieldParameters = methodOwner.getParameters();
processComponentConnectivity(operationDeclarer, operationMethod, operationMethod);
if (isNonBlocking(operationMethod)) {
processNonBlockingOperation(operationDeclarer, operationMethod, true);
} else {
processBlockingOperation(supportsConfig, operationMethod, operationDeclarer);
}
addExecutionType(operationDeclarer, operationMethod);
ParameterDeclarationContext declarationContext = new ParameterDeclarationContext(OPERATION, operationDeclarer.getDeclaration());
processMimeType(operationDeclarer, operationMethod);
declareParameters(operationDeclarer, operationMethod.getParameters(), fieldParameters, declarationContext);
operationDeclarers.put(operationMethod, operationDeclarer);
}
}
use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer 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);
}
use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method declareErrorModels.
private void declareErrorModels(OperationDeclarer operationDeclarer, XmlDslModel xmlDslModel, String operationName, ComponentModel operationModel) {
Optional<ComponentModel> optionalParametersComponentModel = operationModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_ERRORS_IDENTIFIER)).findAny();
optionalParametersComponentModel.ifPresent(componentModel -> componentModel.getInnerComponents().stream().filter(child -> child.getIdentifier().equals(OPERATION_ERROR_IDENTIFIER)).forEach(param -> {
final String namespace = xmlDslModel.getPrefix().toUpperCase();
final String typeName = param.getParameters().get(ERROR_TYPE_ATTRIBUTE);
if (StringUtils.isBlank(typeName)) {
throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> with an empty 'type' attribute", operationName));
}
if (typeName.contains(NAMESPACE_SEPARATOR)) {
throw new IllegalModelDefinitionException(format("The operation [%s] cannot have an <error> [%s] that contains a reserved character [%s]", operationName, typeName, NAMESPACE_SEPARATOR));
}
operationDeclarer.withErrorModel(ErrorModelBuilder.newError(typeName, namespace).withParent(ErrorModelBuilder.newError(ANY).build()).build());
}));
}
use of org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer in project mule by mulesoft.
the class MuleExtensionModelDeclarer method declareSetVariable.
private void declareSetVariable(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
OperationDeclarer setVariable = extensionDeclarer.withOperation("setVariable").describedAs("A processor that adds variables.");
setVariable.withOutput().ofType(typeLoader.load(void.class));
setVariable.withOutputAttributes().ofType(typeLoader.load(void.class));
setVariable.onDefaultParameterGroup().withOptionalParameter("variableName").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The variable name.");
setVariable.onDefaultParameterGroup().withRequiredParameter("value").ofType(typeLoader.load(String.class)).withExpressionSupport(SUPPORTED).describedAs("The variable value.");
setVariable.onDefaultParameterGroup().withOptionalParameter("encoding").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The encoding of the value assigned to the payload.");
setVariable.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 declareRaiseError.
private void declareRaiseError(ExtensionDeclarer extensionDeclarer, ClassTypeLoader typeLoader) {
OperationDeclarer raiseError = extensionDeclarer.withOperation("raiseError").describedAs("Throws an error with the specified type and description.");
raiseError.withOutput().ofType(typeLoader.load(void.class));
raiseError.withOutputAttributes().ofType(typeLoader.load(void.class));
raiseError.onDefaultParameterGroup().withRequiredParameter("type").ofType(typeLoader.load(String.class)).withExpressionSupport(NOT_SUPPORTED).describedAs("The error type to raise.");
raiseError.onDefaultParameterGroup().withOptionalParameter("description").ofType(typeLoader.load(String.class)).describedAs("The description of this error.");
}
Aggregations