Search in sources :

Example 1 with HasConnectionProviderDeclarer

use of org.mule.runtime.api.meta.model.declaration.fluent.HasConnectionProviderDeclarer in project mule by mulesoft.

the class ConnectionProviderModelLoaderDelegate method declareConnectionProvider.

private void declareConnectionProvider(HasConnectionProviderDeclarer declarer, ConnectionProviderElement providerType) {
    ConnectionProviderDeclarer providerDeclarer = connectionProviderDeclarers.get(providerType);
    if (providerDeclarer != null) {
        declarer.withConnectionProvider(providerDeclarer);
        return;
    }
    String name = providerType.getAlias();
    String description = providerType.getDescription();
    if (providerType.getName().equals(providerType.getAlias())) {
        name = DEFAULT_CONNECTION_PROVIDER_NAME;
    }
    List<Type> providerGenerics = providerType.getInterfaceGenerics(ConnectionProvider.class);
    if (providerGenerics.size() != 1) {
        // TODO: MULE-9220: Add a syntax validator for this
        throw new IllegalConnectionProviderModelDefinitionException(format("Connection provider class '%s' was expected to have 1 generic type " + "(for the connection type) but %d were found", providerType.getName(), providerGenerics.size()));
    }
    providerDeclarer = declarer.withConnectionProvider(name).describedAs(description);
    ConnectionProviderDeclarer finalProviderDeclarer = providerDeclarer;
    providerType.getDeclaringClass().ifPresent(clazz -> finalProviderDeclarer.withModelProperty(new ConnectionProviderFactoryModelProperty(new DefaultConnectionProviderFactory<>(clazz, getExtensionClassLoader()))).withModelProperty(new ImplementingTypeModelProperty(clazz)));
    providerDeclarer.withModelProperty(new ConnectionTypeModelProperty(providerGenerics.get(0))).withModelProperty(new ExtensionTypeDescriptorModelProperty(providerType));
    loader.parseExternalLibs(providerType, providerDeclarer);
    ConnectionManagementType managementType = NONE;
    if (providerType.isAssignableTo(PoolingConnectionProvider.class)) {
        managementType = POOLING;
    } else if (providerType.isAssignableTo(CachedConnectionProvider.class)) {
        managementType = CACHED;
    }
    parseOAuthGrantType(providerType, providerDeclarer);
    providerDeclarer.withConnectionManagementType(managementType);
    providerDeclarer.supportsConnectivityTesting(!providerType.isAssignableTo(NoConnectivityTest.class));
    connectionProviderDeclarers.put(providerType, providerDeclarer);
    ParameterDeclarationContext context = new ParameterDeclarationContext(CONNECTION_PROVIDER, providerDeclarer.getDeclaration());
    loader.getFieldParametersLoader().declare(providerDeclarer, providerType.getParameters(), context);
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) ConnectionManagementType(org.mule.runtime.api.meta.model.connection.ConnectionManagementType) CachedConnectionProvider(org.mule.runtime.api.connection.CachedConnectionProvider) IllegalConnectionProviderModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalConnectionProviderModelDefinitionException) Type(org.mule.runtime.module.extension.api.loader.java.type.Type) ConnectionManagementType(org.mule.runtime.api.meta.model.connection.ConnectionManagementType) AuthorizationCodeGrantType(org.mule.runtime.extension.api.connectivity.oauth.AuthorizationCodeGrantType) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) HasConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.HasConnectionProviderDeclarer) ConnectionProviderFactoryModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConnectionProviderFactoryModelProperty) ConnectionTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConnectionTypeModelProperty) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)

Aggregations

CachedConnectionProvider (org.mule.runtime.api.connection.CachedConnectionProvider)1 ConnectionManagementType (org.mule.runtime.api.meta.model.connection.ConnectionManagementType)1 ConnectionProviderDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer)1 HasConnectionProviderDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.HasConnectionProviderDeclarer)1 AuthorizationCodeGrantType (org.mule.runtime.extension.api.connectivity.oauth.AuthorizationCodeGrantType)1 IllegalConnectionProviderModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalConnectionProviderModelDefinitionException)1 Type (org.mule.runtime.module.extension.api.loader.java.type.Type)1 ConnectionProviderFactoryModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ConnectionProviderFactoryModelProperty)1 ConnectionTypeModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ConnectionTypeModelProperty)1 ImplementingTypeModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)1 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)1 ParameterDeclarationContext (org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext)1