use of org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer 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);
}
use of org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer in project mule by mulesoft.
the class XmlExtensionLoaderDelegate method addConnectionProvider.
/**
* Adds a connection provider if (a) there's at least one global element that has test connection or (b) there's at least one
* <property/> that has been placed within a <connection/> wrapper in the <module/> element.
*
* @param configurationDeclarer declarer to add the {@link ConnectionProviderDeclarer} if applies.
* @param connectionProperties collection of <property/>s that should be added to the {@link ConnectionProviderDeclarer}.
* @param globalElementsComponentModel collection of global elements where through {@link #getTestConnectionGlobalElement(List, Set)}
* will look for one that supports test connectivity.
* @param extensions used also in {@link #getTestConnectionGlobalElement(List, Set)}, through the {@link #findTestConnectionGlobalElementFrom},
* as the XML of the extensions might change of the values that the {@link ExtensionModel} has (heavily relies
* on {@link DslSyntaxResolver#resolve(NamedObject)}).
*/
private void addConnectionProvider(ConfigurationDeclarer configurationDeclarer, List<ComponentModel> connectionProperties, List<ComponentModel> globalElementsComponentModel, Set<ExtensionModel> extensions) {
final Optional<ComponentModel> testConnectionGlobalElementOptional = getTestConnectionGlobalElement(globalElementsComponentModel, extensions);
if (testConnectionGlobalElementOptional.isPresent() || !connectionProperties.isEmpty()) {
final ConnectionProviderDeclarer connectionProviderDeclarer = configurationDeclarer.withConnectionProvider(MODULE_CONNECTION_GLOBAL_ELEMENT_NAME);
connectionProviderDeclarer.withConnectionManagementType(ConnectionManagementType.NONE);
connectionProperties.stream().forEach(param -> extractProperty(connectionProviderDeclarer, param));
testConnectionGlobalElementOptional.ifPresent(testConnectionGlobalElement -> {
final String testConnectionGlobalElementName = testConnectionGlobalElement.getParameters().get(GLOBAL_ELEMENT_NAME_ATTRIBUTE);
connectionProviderDeclarer.withModelProperty(new TestConnectionGlobalElementModelProperty(testConnectionGlobalElementName));
});
// TODO until MULE-12734, all test connection must be shut down in smart connectors
connectionProviderDeclarer.supportsConnectivityTesting(false);
}
}
use of org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclarer 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);
}
}
Aggregations