Search in sources :

Example 1 with ImplicitConnectionProviderValueResolver

use of org.mule.runtime.module.extension.internal.runtime.resolver.ImplicitConnectionProviderValueResolver in project mule by mulesoft.

the class DefaultImplicitConfigurationProviderFactory method createImplicitConfigurationProvider.

/**
 * {@inheritDoc}
 */
@Override
public ConfigurationProvider createImplicitConfigurationProvider(ExtensionModel extensionModel, ConfigurationModel implicitConfigurationModel, CoreEvent event, ReflectionCache reflectionCache, MuleContext muleContext) {
    if (implicitConfigurationModel == null || !canBeUsedImplicitly(implicitConfigurationModel)) {
        throw new IllegalStateException("Could not find a config for extension '" + extensionModel.getName() + "' and none can be created automatically. Please define one");
    }
    final String providerName = getImplicitConfigurationProviderName(extensionModel, implicitConfigurationModel);
    Callable<ResolverSet> resolverSetCallable = () -> buildImplicitResolverSet(implicitConfigurationModel, reflectionCache, muleContext);
    ClassLoader pluginClassloader = getClassLoader(extensionModel);
    final ResolverSet resolverSet = withContextClassLoader(pluginClassloader, resolverSetCallable);
    try {
        ImplicitConnectionProviderValueResolver implicitConnectionProviderValueResolver = new ImplicitConnectionProviderValueResolver(implicitConfigurationModel.getName(), extensionModel, implicitConfigurationModel, reflectionCache, muleContext);
        ConfigurationInstance configurationInstance = withContextClassLoader(pluginClassloader, () -> new ConfigurationInstanceFactory(extensionModel, implicitConfigurationModel, resolverSet, reflectionCache, muleContext).createConfiguration(providerName, event, implicitConnectionProviderValueResolver));
        if (resolverSet.isDynamic() || needsDynamicConnectionProvider(extensionModel, implicitConfigurationModel, implicitConnectionProviderValueResolver)) {
            return new DynamicConfigurationProvider(providerName, extensionModel, implicitConfigurationModel, resolverSet, implicitConnectionProviderValueResolver, ImmutableExpirationPolicy.getDefault(new LocalTimeSupplier()), reflectionCache, muleContext);
        }
        return new ConfigurationProviderToolingAdapter(providerName, extensionModel, implicitConfigurationModel, configurationInstance, reflectionCache, muleContext);
    } catch (Exception e) {
        throw new MuleRuntimeException(createStaticMessage(format("Could not create an implicit configuration '%s' for the extension '%s'", implicitConfigurationModel.getName(), extensionModel.getName())), e);
    }
}
Also used : ResolverSet(org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet) ImplicitObjectUtils.buildImplicitResolverSet(org.mule.runtime.module.extension.internal.loader.utils.ImplicitObjectUtils.buildImplicitResolverSet) ImplicitConnectionProviderValueResolver(org.mule.runtime.module.extension.internal.runtime.resolver.ImplicitConnectionProviderValueResolver) LocalTimeSupplier(org.mule.runtime.core.internal.time.LocalTimeSupplier) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) MuleExtensionUtils.getClassLoader(org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Aggregations

MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)1 LocalTimeSupplier (org.mule.runtime.core.internal.time.LocalTimeSupplier)1 ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)1 ImplicitObjectUtils.buildImplicitResolverSet (org.mule.runtime.module.extension.internal.loader.utils.ImplicitObjectUtils.buildImplicitResolverSet)1 ImplicitConnectionProviderValueResolver (org.mule.runtime.module.extension.internal.runtime.resolver.ImplicitConnectionProviderValueResolver)1 ResolverSet (org.mule.runtime.module.extension.internal.runtime.resolver.ResolverSet)1 MuleExtensionUtils.getClassLoader (org.mule.runtime.module.extension.internal.util.MuleExtensionUtils.getClassLoader)1