Search in sources :

Example 6 with IdempotentExtensionWalker

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

the class DefaultExtensionSchemaGenerator method generate.

/**
 * {@inheritDoc}
 */
@Override
public String generate(ExtensionModel extensionModel, DslResolvingContext dslContext) {
    XmlDslModel xmlDslModel = extensionModel.getXmlDslModel();
    validate(extensionModel, xmlDslModel);
    SchemaBuilder schemaBuilder = SchemaBuilder.newSchema(extensionModel, xmlDslModel, dslContext);
    new IdempotentExtensionWalker() {

        @Override
        public void onConfiguration(ConfigurationModel model) {
            schemaBuilder.registerConfigElement(model);
        }

        @Override
        protected void onConstruct(ConstructModel model) {
            schemaBuilder.registerOperation(model);
        }

        @Override
        public void onOperation(OperationModel model) {
            schemaBuilder.registerOperation(model);
        }

        @Override
        public void onConnectionProvider(ConnectionProviderModel model) {
            schemaBuilder.registerConnectionProviderElement(model);
        }

        @Override
        public void onSource(SourceModel model) {
            schemaBuilder.registerMessageSource(model);
        }
    }.walk(extensionModel);
    schemaBuilder.registerEnums();
    // Make sure the XML libs use the container classloader internally
    return withContextClassLoader(DefaultExtensionSchemaGenerator.class.getClassLoader(), () -> renderSchema(schemaBuilder.build()));
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) SchemaBuilder(org.mule.runtime.module.extension.internal.capability.xml.schema.builder.SchemaBuilder) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 7 with IdempotentExtensionWalker

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

the class DefaultExtensionModelFactoryTestCase method blockingExecutionTypes.

@Test
public void blockingExecutionTypes() {
    final List<String> nonBlockingOperations = Arrays.asList("killMany", "executeAnything", "alwaysFailsWrapper", "getChain", "exceptionOnCallbacks", "neverFailsWrapper", "payloadModifier");
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    Reference<Boolean> cpuIntensive = new Reference<>(false);
    Reference<Boolean> blocking = new Reference<>(false);
    new IdempotentExtensionWalker() {

        @Override
        protected void onOperation(OperationModel operation) {
            String operationName = operation.getName();
            assertThat(operation.isBlocking(), is(!nonBlockingOperations.contains(operationName)));
            if (operationName.equals("approve")) {
                assertThat(operation.getExecutionType(), is(CPU_INTENSIVE));
                cpuIntensive.set(true);
            } else if (operation.requiresConnection()) {
                assertThat(operation.getExecutionType(), is(BLOCKING));
                blocking.set(true);
            } else {
                assertThat(operation.getExecutionType(), is(CPU_LITE));
            }
        }
    }.walk(extensionModel);
    assertThat(cpuIntensive.get(), is(true));
    assertThat(blocking.get(), is(true));
}
Also used : Reference(org.mule.runtime.api.util.Reference) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 8 with IdempotentExtensionWalker

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

the class DefaultExtensionModelFactoryTestCase method exportedLibraries.

@Test
public void exportedLibraries() {
    ExtensionModel extensionModel = createExtension(HeisenbergExtension.class);
    assertExternalLibraries(extensionModel);
    new IdempotentExtensionWalker() {

        @Override
        protected void onConfiguration(ConfigurationModel model) {
            assertExternalLibraries(model);
        }

        @Override
        protected void onConnectionProvider(ConnectionProviderModel model) {
            assertExternalLibraries(model);
        }
    }.walk(extensionModel);
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 9 with IdempotentExtensionWalker

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

IdempotentExtensionWalker (org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker)9 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)7 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)5 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)4 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)3 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)3 ConstructModel (org.mule.runtime.api.meta.model.construct.ConstructModel)3 Reference (org.mule.runtime.api.util.Reference)3 Test (org.junit.Test)2 ComponentModel (org.mule.runtime.api.meta.model.ComponentModel)2 XmlDslModel (org.mule.runtime.api.meta.model.XmlDslModel)2 ExtensionWalker (org.mule.runtime.api.meta.model.util.ExtensionWalker)2 DslSyntaxResolver (org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver)2 ReflectionCache (org.mule.runtime.module.extension.internal.util.ReflectionCache)2 SmallTest (org.mule.tck.size.SmallTest)2 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Optional (java.util.Optional)1 Optional.empty (java.util.Optional.empty)1