use of org.mule.runtime.core.internal.config.ParentMuleContextAwareConfigurationBuilder in project mule by mulesoft.
the class AutoConfigurationBuilder method autoConfigure.
protected void autoConfigure(MuleContext muleContext, ConfigResource[] resources) throws ConfigurationException {
Map<String, List<ConfigResource>> configsMap = new LinkedHashMap<String, List<ConfigResource>>();
for (ConfigResource resource : resources) {
String configExtension = substringAfterLast(resource.getUrl().getPath(), ".");
List<ConfigResource> configs = configsMap.get(configExtension);
if (configs == null) {
configs = new ArrayList<ConfigResource>();
configsMap.put(configExtension, configs);
}
configs.add(resource);
}
try {
Properties props = loadProperties(getResource("configuration-builders.properties", this.getClass()).openStream());
for (Map.Entry<String, List<ConfigResource>> e : configsMap.entrySet()) {
String extension = e.getKey();
List<ConfigResource> configs = e.getValue();
String className = (String) props.get(extension);
if (className == null || !ClassUtils.isClassOnPath(className, this.getClass())) {
throw new ConfigurationException(configurationBuilderNoMatching(createConfigResourcesString()));
}
ConfigurationBuilder cb = (ConfigurationBuilder) ClassUtils.instantiateClass(className, new Object[] { configs.stream().map(ConfigResource::getResourceName).toArray(String[]::new), getArtifactProperties(), artifactType });
if (parentContext != null && cb instanceof ParentMuleContextAwareConfigurationBuilder) {
((ParentMuleContextAwareConfigurationBuilder) cb).setParentContext(parentContext);
} else if (parentContext != null) {
throw new MuleRuntimeException(createStaticMessage(format("ConfigurationBuilder %s does not support domain context", cb.getClass().getCanonicalName())));
}
cb.configure(muleContext);
}
} catch (ConfigurationException e) {
throw e;
} catch (Exception e) {
throw new ConfigurationException(e);
}
}
Aggregations