use of org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter in project mule by mulesoft.
the class FunctionModelLoaderDelegate method declareFunctions.
void declareFunctions(ExtensionDeclarer extensionDeclarer, HasFunctionDeclarer declarer, FunctionContainerElement methodOwnerClass, List<FunctionElement> functions) {
for (FunctionElement function : functions) {
FunctionContainerElement functionOwner = methodOwnerClass != null ? methodOwnerClass : function.getEnclosingType();
checkIsNotAnExtension(functionOwner);
final Optional<ExtensionParameter> configParameter = loader.getConfigParameter(function);
if (configParameter.isPresent()) {
throw new IllegalModelDefinitionException(format("Function '%s' requires a config parameter, but that is not allowed. " + "Remove such parameter.", function.getName()));
}
HasFunctionDeclarer actualDeclarer = (HasFunctionDeclarer) loader.selectDeclarerBasedOnConfig(extensionDeclarer, (Declarer) declarer, configParameter, empty());
if (functionDeclarers.containsKey(function)) {
actualDeclarer.withFunction(functionDeclarers.get(function));
continue;
}
final FunctionDeclarer functionDeclarer = actualDeclarer.withFunction(function.getAlias());
function.getMethod().ifPresent(method -> {
functionDeclarer.withModelProperty(new ImplementingMethodModelProperty(method));
function.getDeclaringClass().ifPresent(clazz -> functionDeclarer.withModelProperty(new FunctionExecutorModelProperty(new ReflectiveFunctionExecutorFactory<>(clazz, method))));
});
functionDeclarer.withOutput().ofType(function.getReturnMetadataType());
ParameterDeclarationContext declarationContext = new ParameterDeclarationContext(FUNCTION, functionDeclarer.getDeclaration());
loader.getMethodParametersLoader().declare(functionDeclarer, function.getParameters(), declarationContext);
functionDeclarers.put(function, functionDeclarer);
}
}
use of org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter 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.module.extension.api.loader.java.type.ExtensionParameter in project mule by mulesoft.
the class ParameterModelsLoaderDelegate method declare.
public List<ParameterDeclarer> declare(HasParametersDeclarer component, List<? extends ExtensionParameter> parameters, ParameterDeclarationContext declarationContext, ParameterGroupDeclarer parameterGroupDeclarer) {
List<ParameterDeclarer> declarerList = new ArrayList<>();
checkAnnotationsNotUsedMoreThanOnce(parameters, Connection.class, Config.class, MetadataKeyId.class);
boolean supportsNestedElements = component instanceof HasNestedComponentsDeclarer;
for (ExtensionParameter extensionParameter : parameters) {
// Both nested components and parameters are declared using the @Parameter annotation in order to simplify the API
if (supportsNestedElements && declaredAsNestedComponent((HasNestedComponentsDeclarer) component, extensionParameter)) {
continue;
}
if (!extensionParameter.shouldBeAdvertised()) {
continue;
}
if (isParameterGroup(extensionParameter)) {
List<ParameterDeclarer> groupParams = declaredAsGroup(component, declarationContext, extensionParameter);
declarerList.addAll(groupParams);
continue;
}
ParameterGroupDeclarer groupDeclarer = parameterGroupDeclarer != null ? parameterGroupDeclarer : component.onDefaultParameterGroup();
ParameterDeclarer parameter;
if (extensionParameter.isRequired()) {
parameter = groupDeclarer.withRequiredParameter(extensionParameter.getAlias());
} else {
parameter = groupDeclarer.withOptionalParameter(extensionParameter.getAlias()).defaultingTo(extensionParameter.defaultValue().isPresent() ? extensionParameter.defaultValue().get() : null);
}
parameter.ofType(extensionParameter.getType().asMetadataType()).describedAs(extensionParameter.getDescription());
parseParameterRole(extensionParameter, parameter);
parseExpressionSupport(extensionParameter, parameter);
parseConfigOverride(extensionParameter, parameter);
parseNullSafe(extensionParameter, parameter);
parseLayout(extensionParameter, parameter);
parseExclusiveOptional(extensionParameter, groupDeclarer, parameter);
parameter.withModelProperty(new ExtensionParameterDescriptorModelProperty(extensionParameter));
extensionParameter.getDeclaringElement().ifPresent(element -> addImplementingTypeModelProperty(element, parameter));
parseParameterDsl(extensionParameter, parameter);
contributors.forEach(contributor -> contributor.contribute(extensionParameter, parameter, declarationContext));
declarerList.add(parameter);
}
return declarerList;
}
use of org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter 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);
}
use of org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter 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);
}
Aggregations