Search in sources :

Example 1 with ErrorTypes

use of org.mule.runtime.extension.api.annotation.error.ErrorTypes in project mule by mulesoft.

the class ErrorsDeclarationEnricher method enrich.

@Override
public void enrich(ExtensionLoadingContext extensionLoadingContext) {
    ExtensionDeclaration declaration = extensionLoadingContext.getExtensionDeclarer().getDeclaration();
    String extensionNamespace = getExtensionsNamespace(declaration);
    Optional<ExtensionTypeDescriptorModelProperty> implementingType = declaration.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
    ErrorsModelFactory errorModelDescriber = new ErrorsModelFactory(extensionNamespace);
    errorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
    if (implementingType.isPresent() && implementingType.get().getType().getDeclaringClass().isPresent()) {
        Type extensionElement = implementingType.get().getType();
        Optional<ErrorTypes> errorAnnotation = extensionElement.getAnnotation(ErrorTypes.class);
        List<Pair<ComponentDeclaration, MethodElement>> errorOperations = collectErrorOperations(declaration);
        if (errorAnnotation.isPresent()) {
            ErrorTypeDefinition<?>[] errorTypes = (ErrorTypeDefinition<?>[]) errorAnnotation.get().value().getEnumConstants();
            if (errorTypes.length > 0) {
                ErrorsModelFactory operationErrorModelDescriber = new ErrorsModelFactory(errorTypes, extensionNamespace);
                operationErrorModelDescriber.getErrorModels().forEach(declaration::addErrorModel);
                errorOperations.stream().forEach(pair -> registerOperationErrorTypes(pair.getSecond(), pair.getFirst(), operationErrorModelDescriber, errorTypes, extensionElement));
            } else {
                handleNoErrorTypes(extensionElement, errorOperations);
            }
        } else {
            handleNoErrorTypes(extensionElement, errorOperations);
        }
    }
}
Also used : ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ErrorTypeDefinition(org.mule.runtime.extension.api.error.ErrorTypeDefinition) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ErrorTypes(org.mule.runtime.extension.api.annotation.error.ErrorTypes) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) Pair(org.mule.runtime.api.util.Pair)

Aggregations

ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)1 Pair (org.mule.runtime.api.util.Pair)1 ErrorTypes (org.mule.runtime.extension.api.annotation.error.ErrorTypes)1 ErrorTypeDefinition (org.mule.runtime.extension.api.error.ErrorTypeDefinition)1 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)1 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)1