Search in sources :

Example 11 with ExtensionWalker

use of org.mule.runtime.api.meta.model.util.ExtensionWalker 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)

Example 12 with ExtensionWalker

use of org.mule.runtime.api.meta.model.util.ExtensionWalker in project mule by mulesoft.

the class IntrospectionUtils method getParameterClasses.

/**
 * Traverses through all the {@link ParameterModel}s of the {@code extensionModel} and returns the {@link Class classes} that
 * are modeled by each parameter's {@link ParameterModel#getType()}.
 * <p>
 * This includes every single {@link ParameterModel} in the model, including configs, providers, operations, etc.
 *
 * @param extensionModel a {@link ExtensionModel}
 * @return a non {@code null} {@link Set}
 */
public static Set<Class<?>> getParameterClasses(ExtensionModel extensionModel, ClassLoader extensionClassLoader) {
    Set<Class<?>> parameterClasses = new HashSet<>();
    new ExtensionWalker() {

        @Override
        public void onParameter(ParameterizedModel owner, ParameterGroupModel groupModel, ParameterModel model) {
            parameterClasses.addAll(collectRelativeClasses(model.getType(), extensionClassLoader));
        }
    }.walk(extensionModel);
    return parameterClasses;
}
Also used : ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) ParameterizedModel(org.mule.runtime.api.meta.model.parameter.ParameterizedModel) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) LinkedHashSet(java.util.LinkedHashSet) HashSet(java.util.HashSet)

Aggregations

ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)12 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)8 ParameterGroupModel (org.mule.runtime.api.meta.model.parameter.ParameterGroupModel)7 ParameterizedModel (org.mule.runtime.api.meta.model.parameter.ParameterizedModel)7 HasOperationModels (org.mule.runtime.api.meta.model.operation.HasOperationModels)6 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)6 HasSourceModels (org.mule.runtime.api.meta.model.source.HasSourceModels)6 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)6 ObjectType (org.mule.metadata.api.model.ObjectType)5 MetadataTypeVisitor (org.mule.metadata.api.visitor.MetadataTypeVisitor)5 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)5 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)5 DslSyntaxResolver (org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver)5 List (java.util.List)4 Optional (java.util.Optional)4 ArrayType (org.mule.metadata.api.model.ArrayType)4 MetadataType (org.mule.metadata.api.model.MetadataType)4 ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)4 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)4 String.format (java.lang.String.format)3