use of org.mule.runtime.module.extension.internal.loader.java.property.ConfigurationFactoryModelProperty 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);
}
use of org.mule.runtime.module.extension.internal.loader.java.property.ConfigurationFactoryModelProperty in project mule by mulesoft.
the class ExtensionsTestUtils method mockConfigurationInstance.
public static void mockConfigurationInstance(ConfigurationModel configurationModel, Object config) {
ConfigurationFactory configurationFactory = mock(ConfigurationFactory.class);
when(configurationFactory.newInstance()).thenReturn(config);
when(configurationFactory.getObjectType()).thenReturn((Class) config.getClass());
when(configurationModel.getModelProperty(any())).thenAnswer(invocationOnMock -> {
Class<? extends ModelProperty> propertyType = (Class<? extends ModelProperty>) invocationOnMock.getArguments()[0];
if (ConfigurationFactoryModelProperty.class.equals(propertyType)) {
return of(new ConfigurationFactoryModelProperty(configurationFactory));
}
return empty();
});
}
use of org.mule.runtime.module.extension.internal.loader.java.property.ConfigurationFactoryModelProperty in project mule by mulesoft.
the class SoapModelLoaderDelegate method getConfigDeclarer.
private ConfigurationDeclarer getConfigDeclarer(ExtensionDeclarer declarer, SoapExtensionTypeWrapper<?> extension, Set<ErrorModel> soapErrors) {
// TODO - MULE-14311 - Make loader work in compile time
Class<?> clazz = extension.getDeclaringClass().get();
TypeAwareConfigurationFactory configurationFactory = new TypeAwareConfigurationFactory(clazz, clazz.getClassLoader());
ConfigurationDeclarer configDeclarer = declarer.withConfig(DEFAULT_CONFIG_NAME).describedAs(DEFAULT_CONFIG_DESCRIPTION).withModelProperty(new ConfigurationFactoryModelProperty(configurationFactory)).withModelProperty(new ImplementingTypeModelProperty(clazz));
operationDeclarer.declare(configDeclarer, typeLoader, soapErrors);
return configDeclarer;
}
Aggregations