Search in sources :

Example 1 with IdempotentExtensionWalker

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

the class DefaultExtensionBuildingDefinitionProvider method registerExtensionParsers.

private void registerExtensionParsers(ExtensionModel extensionModel) {
    XmlDslModel xmlDslModel = extensionModel.getXmlDslModel();
    final ExtensionParsingContext parsingContext = createParsingContext(extensionModel);
    final Builder definitionBuilder = new Builder().withNamespace(xmlDslModel.getPrefix());
    final DslSyntaxResolver dslSyntaxResolver = DslSyntaxResolver.getDefault(extensionModel, DslResolvingContext.getDefault(extensions));
    if (extensionModel.getModelProperty(CustomBuildingDefinitionProviderModelProperty.class).isPresent()) {
        return;
    }
    if (extensionModel.getModelProperty(XmlExtensionModelProperty.class).isPresent()) {
        registerXmlExtensionParsers(definitionBuilder, extensionModel, dslSyntaxResolver);
    } else {
        final ClassLoader extensionClassLoader = getClassLoader(extensionModel);
        withContextClassLoader(extensionClassLoader, () -> {
            ReflectionCache reflectionCache = new ReflectionCache();
            new IdempotentExtensionWalker() {

                @Override
                public void onConfiguration(ConfigurationModel model) {
                    parseWith(new ConfigurationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                protected void onConstruct(ConstructModel model) {
                    parseWith(new ConstructDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                public void onOperation(OperationModel model) {
                    parseWith(new OperationDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                public void onConnectionProvider(ConnectionProviderModel model) {
                    parseWith(new ConnectionProviderDefinitionParser(definitionBuilder, model, extensionModel, dslSyntaxResolver, parsingContext));
                }

                @Override
                public void onSource(SourceModel model) {
                    parseWith(new SourceDefinitionParser(definitionBuilder, extensionModel, model, dslSyntaxResolver, parsingContext));
                }

                @Override
                protected void onParameter(ParameterGroupModel groupModel, ParameterModel model) {
                    registerTopLevelParameter(model.getType(), definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
                }
            }.walk(extensionModel);
            registerExportedTypesTopLevelParsers(extensionModel, definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
            registerSubTypes(definitionBuilder, extensionClassLoader, dslSyntaxResolver, parsingContext, reflectionCache);
        });
    }
}
Also used : ConfigurationModel(org.mule.runtime.api.meta.model.config.ConfigurationModel) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) Builder(org.mule.runtime.dsl.api.component.ComponentBuildingDefinition.Builder) ModuleOperationMessageProcessorChainBuilder(org.mule.runtime.core.internal.processor.chain.ModuleOperationMessageProcessorChainBuilder) DslSyntaxResolver(org.mule.runtime.extension.api.dsl.syntax.resolver.DslSyntaxResolver) CustomBuildingDefinitionProviderModelProperty(org.mule.runtime.core.internal.extension.CustomBuildingDefinitionProviderModelProperty) ConnectionProviderDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.connection.ConnectionProviderDefinitionParser) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ConstructModel(org.mule.runtime.api.meta.model.construct.ConstructModel) XmlExtensionModelProperty(org.mule.runtime.extension.api.property.XmlExtensionModelProperty) ConstructDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.construct.ConstructDefinitionParser) ParameterModel(org.mule.runtime.api.meta.model.parameter.ParameterModel) SourceDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.source.SourceDefinitionParser) ParameterGroupModel(org.mule.runtime.api.meta.model.parameter.ParameterGroupModel) XmlDslModel(org.mule.runtime.api.meta.model.XmlDslModel) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) ConfigurationDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.config.ConfigurationDefinitionParser) 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) OperationDefinitionParser(org.mule.runtime.module.extension.internal.config.dsl.operation.OperationDefinitionParser)

Example 2 with IdempotentExtensionWalker

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

the class ConnectionProviderModelValidator method validateGlobalConnectionTypes.

private void validateGlobalConnectionTypes(ExtensionModel extensionModel, Set<ConnectionProviderModel> globalConnectionProviders, ProblemsReporter problemsReporter) {
    if (globalConnectionProviders.isEmpty()) {
        return;
    }
    for (ConnectionProviderModel connectionProviderModel : globalConnectionProviders) {
        final Type connectionType = MuleExtensionUtils.getConnectionType(connectionProviderModel);
        new IdempotentExtensionWalker() {

            @Override
            protected void onOperation(OperationModel operationModel) {
                validateConnectionTypes(connectionProviderModel, operationModel, connectionType, problemsReporter);
            }

            @Override
            protected void onSource(SourceModel sourceModel) {
                validateConnectionTypes(connectionProviderModel, sourceModel, connectionType, problemsReporter);
            }
        }.walk(extensionModel);
    }
}
Also used : SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) 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 3 with IdempotentExtensionWalker

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

the class InputParametersTypeModelValidator method validate.

@Override
public void validate(ExtensionModel extensionModel, ProblemsReporter problems) {
    final Set<Class<?>> validatedTypes = new HashSet<>();
    new IdempotentExtensionWalker() {

        @Override
        public void onOperation(OperationModel model) {
            model.getAllParameterModels().forEach(parameterModel -> validateJavaType(model, parameterModel.getType(), problems, validatedTypes));
        }

        @Override
        public void onSource(SourceModel model) {
            validateCallback(model, model.getSuccessCallback());
            validateCallback(model, model.getErrorCallback());
            validateCallback(model, model.getTerminateCallback());
        }

        private void validateCallback(SourceModel model, Optional<SourceCallbackModel> callback) {
            callback.ifPresent(cb -> cb.getAllParameterModels().forEach(parameterModel -> validateJavaType(model, parameterModel.getType(), problems, validatedTypes)));
        }
    }.walk(extensionModel);
    extensionModel.getSubTypes().forEach(subTypesModel -> getClassForValidation(subTypesModel.getBaseType()).filter(validatedTypes::contains).ifPresent(type -> {
        subTypesModel.getSubTypes().forEach(subtype -> validateSubtypesHaveGetters(extensionModel, subtype, problems, validatedTypes));
    }));
}
Also used : Optional.empty(java.util.Optional.empty) StereotypeTypeAnnotation(org.mule.runtime.extension.api.declaration.type.annotation.StereotypeTypeAnnotation) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel) NamedObject(org.mule.runtime.api.meta.NamedObject) ComponentModel(org.mule.runtime.api.meta.model.ComponentModel) JAVA(org.mule.metadata.api.model.MetadataFormat.JAVA) HashSet(java.util.HashSet) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) ArrayType(org.mule.metadata.api.model.ArrayType) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) Problem(org.mule.runtime.extension.api.loader.Problem) Collectors.toSet(java.util.stream.Collectors.toSet) IntrospectionUtils.getFieldsWithGetters(org.mule.runtime.module.extension.internal.util.IntrospectionUtils.getFieldsWithGetters) TypeUtils(org.mule.runtime.extension.api.declaration.type.TypeUtils) ExtensionModelValidator(org.mule.runtime.extension.api.loader.ExtensionModelValidator) ObjectType(org.mule.metadata.api.model.ObjectType) ProblemsReporter(org.mule.runtime.extension.api.loader.ProblemsReporter) Collection(java.util.Collection) Set(java.util.Set) ReflectionCache(org.mule.runtime.module.extension.internal.util.ReflectionCache) String.format(java.lang.String.format) Collectors.joining(java.util.stream.Collectors.joining) MetadataTypeVisitor(org.mule.metadata.api.visitor.MetadataTypeVisitor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ExtensionMetadataTypeUtils.getType(org.mule.runtime.extension.api.util.ExtensionMetadataTypeUtils.getType) SourceCallbackModel(org.mule.runtime.api.meta.model.source.SourceCallbackModel) ObjectFieldType(org.mule.metadata.api.model.ObjectFieldType) NameUtils.getComponentModelTypeName(org.mule.runtime.extension.api.util.NameUtils.getComponentModelTypeName) MetadataType(org.mule.metadata.api.model.MetadataType) Optional(java.util.Optional) SourceModel(org.mule.runtime.api.meta.model.source.SourceModel) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) SourceCallbackModel(org.mule.runtime.api.meta.model.source.SourceCallbackModel) HashSet(java.util.HashSet) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 4 with IdempotentExtensionWalker

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

the class DefaultExtensionsClient method findOperation.

private OperationModel findOperation(ExtensionModel extensionModel, String operationName) {
    Reference<OperationModel> operation = new Reference<>();
    ExtensionWalker walker = new IdempotentExtensionWalker() {

        @Override
        protected void onOperation(OperationModel operationModel) {
            if (operationName.equals(operationModel.getName())) {
                operation.set(operationModel);
                stop();
            }
        }
    };
    walker.walk(extensionModel);
    if (operation.get() == null) {
        throw new MuleRuntimeException(createStaticMessage("No Operation [" + operationName + "] Found"));
    }
    return operation.get();
}
Also used : Reference(org.mule.runtime.api.util.Reference) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ExtensionWalker(org.mule.runtime.api.meta.model.util.ExtensionWalker) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) OperationModel(org.mule.runtime.api.meta.model.operation.OperationModel)

Example 5 with IdempotentExtensionWalker

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

the class MuleExtensionUtils method supportsOAuth.

/**
 * Whether at least one {@link ConnectionProviderModel} in the given {@cod extensionModel} supports OAuth authentication
 *
 * @param extensionModel a {@link ExtensionModel}
 * @return {@code true} if a {@link ConnectionProviderModel} exist which is OAuth enabled
 */
public static boolean supportsOAuth(ExtensionModel extensionModel) {
    Reference<ConnectionProviderModel> connectionProvider = new Reference<>();
    new IdempotentExtensionWalker() {

        @Override
        protected void onConnectionProvider(ConnectionProviderModel model) {
            if (model.getModelProperty(OAuthModelProperty.class).isPresent()) {
                connectionProvider.set(model);
                stop();
            }
        }
    }.walk(extensionModel);
    return connectionProvider.get() != null;
}
Also used : Reference(org.mule.runtime.api.util.Reference) IdempotentExtensionWalker(org.mule.runtime.api.meta.model.util.IdempotentExtensionWalker) ConnectionProviderModel(org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)

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