Search in sources :

Example 1 with SingleExtensionImportTypesStrategy

use of org.mule.runtime.extension.api.dsl.syntax.resolver.SingleExtensionImportTypesStrategy in project mule by mulesoft.

the class ExtensionErrorsRegistrant method registerErrors.

/**
 * Registers the found {@link ErrorModel} from each {@link OperationModel} into the {@link ErrorTypeRepository} and creates an
 * {@link ExceptionMapper} for each {@link OperationModel} that declares {@link ErrorModel}s.
 *
 * @param extensionModel from where get the {@link ErrorModel} from each {@link OperationModel}
 */
void registerErrors(ExtensionModel extensionModel) {
    Set<ErrorModel> errorTypes = extensionModel.getErrorModels();
    String extensionNamespace = extensionModel.getXmlDslModel().getPrefix();
    String errorExtensionNamespace = MuleExtensionUtils.getExtensionsNamespace(extensionModel);
    DslSyntaxResolver syntaxResolver = DslSyntaxResolver.getDefault(extensionModel, new SingleExtensionImportTypesStrategy());
    ErrorModel connectivityErrorModel = newError(CONNECTIVITY_ERROR_IDENTIFIER, errorExtensionNamespace).withParent(newError(CONNECTIVITY_ERROR_IDENTIFIER, MULE).build()).build();
    ErrorModel retryExhaustedError = newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, errorExtensionNamespace).withParent(newError(RETRY_EXHAUSTED_ERROR_IDENTIFIER, MULE).build()).build();
    errorTypes.forEach(errorModel -> getErrorType(errorModel, extensionModel));
    ExtensionWalker extensionWalker = new IdempotentExtensionWalker() {

        @Override
        protected void onOperation(OperationModel model) {
            registerErrors(model);
        }

        @Override
        protected void onConstruct(ConstructModel model) {
            registerErrors(model);
        }

        private void registerErrors(ComponentModel model) {
            if (!errorTypes.isEmpty()) {
                ExceptionMapper.Builder builder = ExceptionMapper.builder();
                builder.addExceptionMapping(ConnectionException.class, getErrorType(connectivityErrorModel, extensionModel));
                builder.addExceptionMapping(RetryPolicyExhaustedException.class, getErrorType(retryExhaustedError, extensionModel));
                String elementName = syntaxResolver.resolve(model).getElementName();
                errorTypeLocator.addComponentExceptionMapper(createIdentifier(elementName, extensionNamespace), builder.build());
            }
        }
    };
    extensionWalker.walk(extensionModel);
}
Also used : ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ExceptionMapper(org.mule.runtime.core.api.exception.ExceptionMapper) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) ErrorModel(org.mule.runtime.api.meta.model.error.ErrorModel) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) SingleExtensionImportTypesStrategy(org.mule.runtime.extension.api.dsl.syntax.resolver.SingleExtensionImportTypesStrategy) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Aggregations

ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)1 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)1 ErrorModel (org.mule.runtime.api.meta.model.error.ErrorModel)1 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)1 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)1 IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)1 ExceptionMapper (org.mule.runtime.core.api.exception.ExceptionMapper)1 DslSyntaxResolver (org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver)1 SingleExtensionImportTypesStrategy (org.mule.runtime.extension.api.dsl.syntax.resolver.SingleExtensionImportTypesStrategy)1