use of org.opendaylight.controller.blueprint.ext.DataStoreAppConfigDefaultXMLReader.ConfigURLProvider in project controller by opendaylight.
the class DataStoreAppConfigMetadata method createDefaultInstance.
private DataObject createDefaultInstance() {
try {
ConfigURLProvider inputStreamProvider = appConfigFileName -> {
File appConfigFile = new File(DEFAULT_APP_CONFIG_FILE_PATH, appConfigFileName);
LOG.debug("{}: parsePossibleDefaultAppConfigXMLFile looking for file {}", logName(), appConfigFile.getAbsolutePath());
if (!appConfigFile.exists()) {
return Optional.absent();
}
LOG.debug("{}: Found file {}", logName(), appConfigFile.getAbsolutePath());
return Optional.of(appConfigFile.toURI().toURL());
};
DataStoreAppConfigDefaultXMLReader<?> reader = new DataStoreAppConfigDefaultXMLReader<>(logName(), defaultAppConfigFileName, getOSGiService(DOMSchemaService.class), bindingSerializer, bindingContext, inputStreamProvider);
return reader.createDefaultInstance((schemaContext, dataSchema) -> {
// Fallback if file cannot be read, try XML from Config
NormalizedNode<?, ?> dataNode = parsePossibleDefaultAppConfigElement(schemaContext, dataSchema);
if (dataNode == null) {
// or, as last resort, defaults from the model
return bindingContext.newDefaultNode(dataSchema);
} else {
return dataNode;
}
});
} catch (final ConfigXMLReaderException | IOException | SAXException | XMLStreamException | ParserConfigurationException | URISyntaxException e) {
if (e.getCause() == null) {
setFailureMessage(e.getMessage());
} else {
setFailure(e.getMessage(), e);
}
return null;
}
}
Aggregations