Search in sources :

Example 1 with DefaultMetadataContext

use of org.mule.runtime.module.extension.internal.metadata.DefaultMetadataContext in project mule by mulesoft.

the class ExtensionComponent method getMetadataContext.

private MetadataContext getMetadataContext() throws MetadataResolvingException {
    CoreEvent fakeEvent = null;
    try {
        fakeEvent = getInitialiserEvent(muleContext);
        Optional<ConfigurationInstance> configuration = getConfiguration(fakeEvent);
        if (configuration.isPresent()) {
            ConfigurationProvider configurationProvider = findConfigurationProvider().orElseThrow(() -> new MetadataResolvingException("Failed to create the required configuration for Metadata retrieval", INVALID_CONFIGURATION));
            if (configurationProvider instanceof DynamicConfigurationProvider) {
                throw new MetadataResolvingException("Configuration used for Metadata fetch cannot be dynamic", INVALID_CONFIGURATION);
            }
        }
        String cacheId = configuration.map(ConfigurationInstance::getName).orElseGet(() -> extensionModel.getName() + "|" + componentModel.getName());
        return new DefaultMetadataContext(() -> configuration, connectionManager, metadataService.getMetadataCache(cacheId), typeLoader);
    } finally {
        if (fakeEvent != null) {
            ((BaseEventContext) fakeEvent.getContext()).success();
        }
    }
}
Also used : BaseEventContext(org.mule.runtime.core.privileged.event.BaseEventContext) MetadataResolvingException(org.mule.runtime.api.metadata.MetadataResolvingException) CoreEvent(org.mule.runtime.core.api.event.CoreEvent) ConfigurationProvider(org.mule.runtime.extension.api.runtime.config.ConfigurationProvider) DynamicConfigurationProvider(org.mule.runtime.module.extension.internal.runtime.config.DynamicConfigurationProvider) DynamicConfigurationProvider(org.mule.runtime.module.extension.internal.runtime.config.DynamicConfigurationProvider) DefaultMetadataContext(org.mule.runtime.module.extension.internal.metadata.DefaultMetadataContext) ConfigurationInstance(org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)

Aggregations

MetadataResolvingException (org.mule.runtime.api.metadata.MetadataResolvingException)1 CoreEvent (org.mule.runtime.core.api.event.CoreEvent)1 BaseEventContext (org.mule.runtime.core.privileged.event.BaseEventContext)1 ConfigurationInstance (org.mule.runtime.extension.api.runtime.config.ConfigurationInstance)1 ConfigurationProvider (org.mule.runtime.extension.api.runtime.config.ConfigurationProvider)1 DefaultMetadataContext (org.mule.runtime.module.extension.internal.metadata.DefaultMetadataContext)1 DynamicConfigurationProvider (org.mule.runtime.module.extension.internal.runtime.config.DynamicConfigurationProvider)1