use of org.mule.runtime.extension.api.annotation.Configuration in project mule by mulesoft.
the class ConfigModelLoaderDelegate method declareConfiguration.
private void declareConfiguration(ExtensionDeclarer declarer, ExtensionElement extensionType, ComponentElement configType) {
checkConfigurationIsNotAnOperation(extensionType, configType);
ConfigurationDeclarer configurationDeclarer;
Optional<Configuration> configurationAnnotation = configType.getAnnotation(Configuration.class);
if (configurationAnnotation.isPresent()) {
final Configuration configuration = configurationAnnotation.get();
String configName = isBlank(configuration.name()) ? DEFAULT_CONFIG_NAME : configuration.name();
configurationDeclarer = declarer.withConfig(configName);
} else {
configurationDeclarer = declarer.withConfig(DEFAULT_CONFIG_NAME).describedAs(DEFAULT_CONFIG_DESCRIPTION);
}
Class<?> extensionClass = extensionType.getDeclaringClass().orElse(Object.class);
Class<?> configClass = configType.getDeclaringClass().orElse(Object.class);
ClassLoader classLoader = extensionClass.getClassLoader() != null ? extensionClass.getClassLoader() : Thread.currentThread().getContextClassLoader();
TypeAwareConfigurationFactory typeAwareConfigurationFactory = new TypeAwareConfigurationFactory(configClass, classLoader);
configurationDeclarer.withModelProperty(new ConfigurationFactoryModelProperty(typeAwareConfigurationFactory)).withModelProperty(new ImplementingTypeModelProperty(configClass));
configurationDeclarer.withModelProperty(new ExtensionTypeDescriptorModelProperty(configType));
loader.parseExternalLibs(configType, configurationDeclarer);
ParameterDeclarationContext context = new ParameterDeclarationContext(CONFIGURATION, configurationDeclarer.getDeclaration());
loader.getFieldParametersLoader().declare(configurationDeclarer, configType.getParameters(), context);
getOperationLoaderDelegate().declareOperations(declarer, configurationDeclarer, configType);
getSourceModelLoaderDelegate().declareMessageSources(declarer, configurationDeclarer, configType);
getFunctionModelLoaderDelegate().declareFunctions(declarer, configurationDeclarer, configType);
getConnectionProviderModelLoaderDelegate().declareConnectionProviders(configurationDeclarer, configType);
}
Aggregations