use of org.mule.runtime.extension.api.exception.IllegalConnectionProviderModelDefinitionException 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);
}
Aggregations