Search in sources :

Example 1 with MethodElement

use of org.mule.runtime.module.extension.api.loader.java.type.MethodElement in project mule by mulesoft.

the class SourceModelLoaderDelegate method declareSourceCallback.

private void declareSourceCallback(SourceElement sourceType, SourceDeclarer source) {
    final Optional<MethodElement> onResponseMethod = sourceType.getOnResponseMethod();
    final Optional<MethodElement> onErrorMethod = sourceType.getOnErrorMethod();
    final Optional<MethodElement> onTerminateMethod = sourceType.getOnTerminateMethod();
    final Optional<MethodElement> onBackPressureMethod = sourceType.getOnBackPressureMethod();
    // TODO: MULE-9220 add syntax validator to check that none of these use @UseConfig or @Connection
    declareSourceCallbackParameters(source, onResponseMethod, source::onSuccess);
    declareSourceCallbackParameters(source, onErrorMethod, source::onError);
    declareSourceCallbackParameters(source, onTerminateMethod, source::onTerminate);
    declareSourceCallbackParameters(source, onBackPressureMethod, source::onBackPressure);
    source.withModelProperty(new SourceCallbackModelProperty(getMethod(onResponseMethod), getMethod(onErrorMethod), getMethod(onTerminateMethod), getMethod(onBackPressureMethod)));
}
Also used : SourceCallbackModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.SourceCallbackModelProperty) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement)

Example 2 with MethodElement

use of org.mule.runtime.module.extension.api.loader.java.type.MethodElement in project mule by mulesoft.

the class NotificationsDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclaration declaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    Optional<ExtensionTypeDescriptorModelProperty> extensionType = declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    String extensionNamespace = getExtensionsNamespace(declaration);
    ClassTypeLoader typeLoader = ExtensionsTypeLoaderFactory.getDefault().createTypeLoader();
    if (extensionType.isPresent() && extensionType.get().getType().getDeclaringClass().isPresent()) {
        Type extensionElement = extensionType.get().getType();
        Optional<NotificationActions> annotation = extensionElement.getAnnotation(NotificationActions.class);
        annotation.ifPresent(actionsAnnotation -> {
            NotificationActionDefinition<?>[] actions = (NotificationActionDefinition<?>[]) actionsAnnotation.value().getEnumConstants();
            Map<NotificationActionDefinition, NotificationModel> notificationModels = new HashMap<>();
            stream(actions).forEach(action -> {
                NotificationModel model = new ImmutableNotificationModel(extensionNamespace, ((Enum) action).name(), typeLoader.load(action.getDataType().getType()));
                declaration.addNotificationModel(model);
                notificationModels.put(action, model);
            });
            new IdempotentDeclarationWalker() {

                @Override
                public void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
                    Optional<ExtensionOperationDescriptorModelProperty> modelProperty = declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class);
                    if (modelProperty.isPresent()) {
                        MethodElement method = modelProperty.get().getOperationMethod();
                        Optional<Fires> emitsNotifications = getOperationNotificationDeclaration(method, extensionElement);
                        includeNotificationDeclarationIfNeeded(declaration, emitsNotifications);
                    }
                }

                @Override
                public void onSource(SourceDeclaration declaration) {
                    Optional<ExtensionTypeDescriptorModelProperty> modelProperty = declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
                    if (modelProperty.isPresent()) {
                        Type sourceContainer = modelProperty.get().getType();
                        Optional<Fires> emitsNotifications = getNotificationDeclaration(sourceContainer, extensionElement);
                        includeNotificationDeclarationIfNeeded(declaration, emitsNotifications);
                    }
                }

                private Optional<Fires> getOperationNotificationDeclaration(MethodElement operationMethod, Type extensionElement) {
                    Type operationContainer = operationMethod.getEnclosingType();
                    return ofNullable(operationMethod.getAnnotation(Fires.class)).orElse(getNotificationDeclaration(operationContainer, extensionElement));
                }

                private Optional<Fires> getNotificationDeclaration(Type container, Type extensionElement) {
                    return ofNullable(container.getAnnotation(Fires.class).orElseGet(() -> extensionElement.getAnnotation(Fires.class).orElse(null)));
                }

                private void includeNotificationDeclarationIfNeeded(ExecutableComponentDeclaration declaration, Optional<Fires> emitsNotifications) {
                    emitsNotifications.ifPresent(emits -> {
                        Class<? extends NotificationActionProvider>[] providers = emits.value();
                        stream(providers).forEach(provider -> {
                            try {
                                NotificationActionProvider notificationActionProvider = provider.newInstance();
                                notificationActionProvider.getNotificationActions().stream().map(action -> validateEmits(actions, action)).forEach(action -> declaration.addNotificationModel(notificationModels.get(action)));
                            } catch (InstantiationException | IllegalAccessException e) {
                                throw new MuleRuntimeException(createStaticMessage("Could not create NotificationActionProvider of type " + provider.getName()), e);
                            }
                        });
                    });
                }

                private NotificationActionDefinition validateEmits(NotificationActionDefinition[] actions, NotificationActionDefinition action) {
                    Class<?> extensionAction = actions.getClass().getComponentType();
                    if (!action.getClass().equals(extensionAction) && !action.getClass().getSuperclass().equals(extensionAction)) {
                        throw new IllegalModelDefinitionException(format("Invalid EmitsNotification detected, the extension declared" + " firing notifications of %s type, but a notification of %s type has been detected", extensionAction, action.getClass()));
                    } else {
                        return action;
                    }
                }
            }.walk(declaration);
        });
    }
}
Also used : ImmutableNotificationModel(org.mule.runtime.extension.api.model.notification.ImmutableNotificationModel) MuleExtensionUtils.getExtensionsNamespace(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getExtensionsNamespace) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) NotificationActionProvider(org.mule.runtime.extension.api.annotation.notification.NotificationActionProvider) ExtensionsTypeLoaderFactory(org.mule.runtime.extension.api.declaration.type.ExtensionsTypeLoaderFactory) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) NotificationActions(org.mule.runtime.extension.api.annotation.notification.NotificationActions) HashMap(java.util.HashMap) NotificationActionDefinition(org.mule.runtime.extension.api.notification.NotificationActionDefinition) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) Map(java.util.Map) NotificationModel(org.mule.runtime.api.meta.model.notification.NotificationModel) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) DeclarationEnricherPhase(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) String.format(java.lang.String.format) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) Fires(org.mule.runtime.extension.api.annotation.notification.Fires) Optional(java.util.Optional) ExecutableComponentDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExecutableComponentDeclaration) Arrays.stream(java.util.Arrays.stream) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) INITIALIZE(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.INITIALIZE) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) NotificationActionProvider(org.mule.runtime.extension.api.annotation.notification.NotificationActionProvider) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) HashMap(java.util.HashMap) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) ImmutableNotificationModel(org.mule.runtime.extension.api.model.notification.ImmutableNotificationModel) NotificationModel(org.mule.runtime.api.meta.model.notification.NotificationModel) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) NotificationActions(org.mule.runtime.extension.api.annotation.notification.NotificationActions) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ClassTypeLoader(org.mule.metadata.api.ClassTypeLoader) Fires(org.mule.runtime.extension.api.annotation.notification.Fires) ExecutableComponentDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExecutableComponentDeclaration) ImmutableNotificationModel(org.mule.runtime.extension.api.model.notification.ImmutableNotificationModel) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) Optional(java.util.Optional) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) NotificationActionDefinition(org.mule.runtime.extension.api.notification.NotificationActionDefinition) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker)

Example 3 with MethodElement

use of org.mule.runtime.module.extension.api.loader.java.type.MethodElement in project mule by mulesoft.

the class InjectedFieldsModelValidator method validate.

@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problemsReporter) {
    final Set<Class<?>> validatedTypes = new HashSet<>();
    // TODO - MULE-14401 - Make InjectedFieldsModelValidator work in AST Mode
    Boolean isASTMode = !extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class).map(mp -> mp.getType().getDeclaringClass().isPresent()).orElse(false);
    if (!isASTMode) {
        extensionModel.getModelProperty(ClassLoaderModelProperty.class).ifPresent(classLoaderModelProperty -> {
            new ExtensionWalker() {

                @Override
                protected void onSource(HasSourceModels owner, SourceModel model) {
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), DefaultEncoding.class);
                }

                @Override
                protected void onConfiguration(ConfigurationModel model) {
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), DefaultEncoding.class);
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), RefName.class);
                }

                @Override
                protected void onOperation(HasOperationModels owner, OperationModel model) {
                    validateArguments(model, model.getModelProperty(ExtensionOperationDescriptorModelProperty.class), DefaultEncoding.class);
                }

                @Override
                protected void onConnectionProvider(HasConnectionProviderModels owner, ConnectionProviderModel model) {
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), DefaultEncoding.class);
                    validateFields(model, model.getModelProperty(ImplementingTypeModelProperty.class), RefName.class);
                }

                @Override
                protected void onParameter(ParameterizedModel owner, ParameterGroupModel groupModel, ParameterModel model) {
                    if (model.getType().getMetadataFormat().equals(JAVA)) {
                        model.getType().accept(new MetadataTypeVisitor() {

                            @Override
                            public void visitObject(ObjectType objectType) {
                                if (!objectType.getAnnotation(InfrastructureTypeAnnotation.class).isPresent()) {
                                    try {
                                        Class<?> type = getType(objectType, classLoaderModelProperty.getClassLoader());
                                        if (validatedTypes.add(type)) {
                                            validateType(model, type, DefaultEncoding.class);
                                        }
                                    } catch (Exception e) {
                                        problemsReporter.addWarning(new Problem(model, "Could not validate Class: " + e.getMessage()));
                                    }
                                }
                            }
                        });
                    }
                }

                private void validateArguments(NamedObject model, Optional<ExtensionOperationDescriptorModelProperty> modelProperty, Class<? extends Annotation> annotationClass) {
                    modelProperty.ifPresent(operationDescriptorModelProperty -> {
                        MethodElement operation = operationDescriptorModelProperty.getOperationMethod();
                        int size = operation.getParametersAnnotatedWith(annotationClass).size();
                        if (size == 0) {
                            return;
                        } else if (size > 1) {
                            problemsReporter.addError(new Problem(model, format("Operation method '%s' has %d arguments annotated with @%s. Only one argument may carry that annotation", operation.getName(), size, annotationClass.getSimpleName())));
                        }
                        ExtensionParameter argument = operation.getParametersAnnotatedWith(annotationClass).get(0);
                        if (!argument.getType().isSameType(String.class)) {
                            problemsReporter.addError(new Problem(model, format("Operation method '%s' declares an argument '%s' which is annotated with @%s and is of type '%s'. Only " + "arguments of type String are allowed to carry such annotation", operation.getName(), argument.getName(), annotationClass.getSimpleName(), argument.getType().getName())));
                        }
                    });
                }

                private void validateFields(NamedObject model, Optional<ImplementingTypeModelProperty> modelProperty, Class<? extends Annotation> annotationClass) {
                    modelProperty.ifPresent(implementingTypeModelProperty -> {
                        validateType(model, implementingTypeModelProperty.getType(), annotationClass);
                    });
                }

                private void validateType(NamedObject model, Class<?> type, Class<? extends Annotation> annotationClass) {
                    List<Field> fields = getAnnotatedFields(type, annotationClass);
                    if (fields.isEmpty()) {
                        return;
                    } else if (fields.size() > 1) {
                        problemsReporter.addError(new Problem(model, format("Class '%s' has %d fields annotated with @%s. Only one field may carry that annotation", type.getName(), fields.size(), annotationClass.getSimpleName())));
                    }
                    Field field = fields.get(0);
                    if (!String.class.equals(field.getType())) {
                        problemsReporter.addError(new Problem(model, format("Class '%s' declares the field '%s' which is annotated with @%s and is of type '%s'. Only " + "fields of type String are allowed to carry such annotation", type.getName(), field.getName(), annotationClass.getSimpleName(), field.getType().getName())));
                    }
                }
            }.walk(extensionModel);
        });
    }
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) IntrospectionUtils.getAnnotatedFields(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getAnnotatedFields) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) NamedObject(org.mule.runtime.api.meta.NamedObject) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) HashSet(java.util.HashSet) InfrastructureTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.InfrastructureTypeAnnotation) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) Problem(org.mule.runtime.extension.api.loader.Problem) HasConnectionProviderModels(org.mule.runtime.api.meta.model.connection.HasConnectionProviderModels) ExtensionModelValidator(org.mule.runtime.extension.api.loader.ExtensionModelValidator) ObjectType(org.mule.metadata.api.model.ObjectType) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ProblemsReporter(org.mule.runtime.extension.api.loader.ProblemsReporter) Set(java.util.Set) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ClassLoaderModelProperty(org.mule.runtime.extension.api.property.ClassLoaderModelProperty) Field(java.lang.reflect.Field) String.format(java.lang.String.format) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DefaultEncoding(org.mule.runtime.extension.api.annotation.param.DefaultEncoding) List(java.util.List) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) RefName(org.mule.runtime.extension.api.annotation.param.RefName) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) JavaTypeUtils.getType(org.mule.metadata.java.api.utils.JavaTypeUtils.getType) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) RefName(org.mule.runtime.extension.api.annotation.param.RefName) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ObjectType(org.mule.metadata.api.model.ObjectType) Field(java.lang.reflect.Field) List(java.util.List) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) HashSet(java.util.HashSet) ClassLoaderModelProperty(org.mule.runtime.extension.api.property.ClassLoaderModelProperty) HasOperationModels(org.mule.runtime.api.meta.model.operation.HasOperationModels) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) NamedObject(org.mule.runtime.api.meta.NamedObject) HasConnectionProviderModels(org.mule.runtime.api.meta.model.connection.HasConnectionProviderModels) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) Problem(org.mule.runtime.extension.api.loader.Problem) HasSourceModels(org.mule.runtime.api.meta.model.source.HasSourceModels) DefaultEncoding(org.mule.runtime.extension.api.annotation.param.DefaultEncoding) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)

Example 4 with MethodElement

use of org.mule.runtime.module.extension.api.loader.java.type.MethodElement 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);
    }
}
Also used : TypeGeneric(org.mule.runtime.module.extension.api.loader.java.type.TypeGeneric) OperationDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclarer) AnyType(org.mule.metadata.api.model.AnyType) CompletionCallback(org.mule.runtime.extension.api.runtime.process.CompletionCallback) Preconditions.checkArgument(org.mule.runtime.api.util.Preconditions.checkArgument) HashMap(java.util.HashMap) BaseTypeBuilder(org.mule.metadata.api.builder.BaseTypeBuilder) JAVA(org.mule.metadata.java.api.JavaTypeLoader.JAVA) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) OperationElement(org.mule.runtime.module.extension.api.loader.java.type.OperationElement) ReflectiveOperationExecutorFactory(org.mule.runtime.module.extension.internal.runtime.execution.ReflectiveOperationExecutorFactory) ModelLoaderUtils.isScope(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isScope) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) WithOperationContainers(org.mule.runtime.module.extension.api.loader.java.type.WithOperationContainers) Map(java.util.Map) Method(java.lang.reflect.Method) ModelLoaderUtils.isNonBlocking(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isNonBlocking) Execution(org.mule.runtime.extension.api.annotation.execution.Execution) PagedOperationModelProperty(org.mule.runtime.extension.internal.property.PagedOperationModelProperty) String.format(java.lang.String.format) ModelLoaderUtils.isRouter(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isRouter) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ModelLoaderUtils.isAutoPaging(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.isAutoPaging) IntrospectionUtils.isVoid(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.isVoid) ComponentExecutorModelProperty(org.mule.runtime.module.extension.api.loader.java.property.ComponentExecutorModelProperty) TransactionalConnection(org.mule.runtime.extension.api.connectivity.TransactionalConnection) OperationContainerElement(org.mule.runtime.module.extension.api.loader.java.type.OperationContainerElement) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) ExtensionDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclarer) IllegalOperationModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalOperationModelDefinitionException) ModelLoaderUtils.handleByteStreaming(org.mule.runtime.module.extension.internal.loader.utils.ModelLoaderUtils.handleByteStreaming) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) Declarer(org.mule.runtime.api.meta.model.declaration.fluent.Declarer) 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) ExtensionParameter(org.mule.runtime.module.extension.api.loader.java.type.ExtensionParameter) MetadataType(org.mule.metadata.api.model.MetadataType)

Example 5 with MethodElement

use of org.mule.runtime.module.extension.api.loader.java.type.MethodElement in project mule by mulesoft.

the class ErrorsDeclarationEnricher method collectErrorOperations.

private List<Pair<ComponentDeclaration, MethodElement>> collectErrorOperations(ExtensionDeclaration declaration) {
    List<Pair<ComponentDeclaration, MethodElement>> operations = new LinkedList<>();
    new IdempotentDeclarationWalker() {

        @Override
        public void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
            addComponent(declaration);
        }

        @Override
        protected void onConstruct(ConstructDeclaration declaration) {
            addComponent(declaration);
        }

        private void addComponent(ComponentDeclaration<?> declaration) {
            declaration.getModelProperty(ExtensionOperationDescriptorModelProperty.class).ifPresent(implementingMethodModelProperty -> operations.add(new Pair<>(declaration, implementingMethodModelProperty.getOperationMethod())));
        }
    }.walk(declaration);
    return operations;
}
Also used : MuleExtensionUtils.getExtensionsNamespace(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getExtensionsNamespace) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) MuleErrors(org.mule.runtime.extension.api.error.MuleErrors) ConstructDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclaration) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) MethodElement(org.mule.runtime.module.extension.api.loader.java.type.MethodElement) Pair(org.mule.runtime.api.util.Pair) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) LinkedList(java.util.LinkedList) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) ComponentDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ComponentDeclaration) Optional.ofNullable(java.util.Optional.ofNullable) I18nMessageFactory.createStaticMessage(org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage) DeclarationEnricherPhase(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) Throws(org.mule.runtime.extension.api.annotation.error.Throws) String.format(java.lang.String.format) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) List(java.util.List) Stream(java.util.stream.Stream) ErrorTypeProvider(org.mule.runtime.extension.api.annotation.error.ErrorTypeProvider) Optional(java.util.Optional) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) ExtensionOperationDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty) INITIALIZE(org.mule.runtime.extension.api.loader.DeclarationEnricherPhase.INITIALIZE) IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) ConstructDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConstructDeclaration) IdempotentDeclarationWalker(org.mule.runtime.extension.api.declaration.fluent.util.IdempotentDeclarationWalker) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) LinkedList(java.util.LinkedList) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) Pair(org.mule.runtime.api.util.Pair)

Aggregations

MethodElement (org.mule.runtime.module.extension.api.loader.java.type.MethodElement)5 String.format (java.lang.String.format)4 Optional (java.util.Optional)4 ExtensionOperationDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionOperationDescriptorModelProperty)4 List (java.util.List)3 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Optional.ofNullable (java.util.Optional.ofNullable)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 I18nMessageFactory.createStaticMessage (org.mule.runtime.api.i18n.I18nMessageFactory.createStaticMessage)2 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)2 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)2 WithOperationsDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration)2 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)2 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)2 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)2 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1