Search in sources :

Example 1 with ConnectionTypeModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.property.ConnectionTypeModelProperty 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)

Example 2 with ConnectionTypeModelProperty

use of org.mule.runtime.module.extension.internal.loader.java.property.ConnectionTypeModelProperty in project mule by mulesoft.

the class SoapServiceProviderDeclarer method declare.

/**
 * Declares a new connection provider for a configuration given a {@link SoapServiceProviderWrapper} declaration.
 *
 * @param configDeclarer      the configuration declarer that will own the provider
 * @param provider            a {@link SoapServiceProviderWrapper} that describes the {@link SoapServiceProvider} Type.
 * @param hasCustomTransports if declares custom transport or not.
 */
public void declare(ConfigurationDeclarer configDeclarer, SoapServiceProviderWrapper provider, boolean hasCustomTransports) {
    String description = provider.getDescription();
    // Declares the Service Provider as a Connection Provider.
    ConnectionProviderDeclarer providerDeclarer = configDeclarer.withConnectionProvider(provider.getAlias()).describedAs(description).withModelProperty(new ConnectionTypeModelProperty(ForwardingSoapClient.class)).withModelProperty(new ImplementingTypeModelProperty(provider.getDeclaringClass().get())).withConnectionManagementType(POOLING).supportsConnectivityTesting(provider.supportsConnectivityTesting());
    ParameterDeclarationContext context = new ParameterDeclarationContext("Service Provider", providerDeclarer.getDeclaration());
    parametersLoader.declare(providerDeclarer, provider.getParameters(), context);
    if (hasCustomTransports) {
        providerDeclarer.onParameterGroup(TRANSPORT_GROUP).withRequiredParameter(TRANSPORT_PARAM).withDisplayModel(DisplayModel.builder().displayName(TRANSPORT_GROUP).build()).ofType(typeLoader.load(MessageDispatcherProvider.class)).withLayout(LayoutModel.builder().order(1).tabName(TRANSPORT).build()).withExpressionSupport(NOT_SUPPORTED);
    }
}
Also used : ParameterDeclarationContext(org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext) ConnectionProviderDeclarer(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer) ConnectionTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ConnectionTypeModelProperty) ImplementingTypeModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty) MessageDispatcherProvider(org.mule.runtime.extension.api.soap.MessageDispatcherProvider)

Aggregations

ConnectionProviderDeclarer (org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer)2 ConnectionTypeModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ConnectionTypeModelProperty)2 ImplementingTypeModelProperty (org.mule.runtime.module.extension.internal.loader.java.property.ImplementingTypeModelProperty)2 ParameterDeclarationContext (org.mule.runtime.module.extension.internal.loader.utils.ParameterDeclarationContext)2 CachedConnectionProvider (org.mule.runtime.api.connection.CachedConnectionProvider)1 ConnectionManagementType (org.mule.runtime.api.meta.model.connection.ConnectionManagementType)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 MessageDispatcherProvider (org.mule.runtime.extension.api.soap.MessageDispatcherProvider)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 ExtensionTypeDescriptorModelProperty (org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty)1