use of org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult in project bgpcep by opendaylight.
the class ConfigLoaderImpl method parseDefaultConfigFile.
private NormalizedNode<?, ?> parseDefaultConfigFile(final ConfigFileProcessor config, final String filename) throws IOException, XMLStreamException {
final NormalizedNodeResult result = new NormalizedNodeResult();
final NormalizedNodeStreamWriter streamWriter = ImmutableNormalizedNodeStreamWriter.from(result);
final File newFile = new File(this.path, filename);
FileChannel channel = new RandomAccessFile(newFile, READ).getChannel();
FileLock lock = null;
final Stopwatch stopwatch = Stopwatch.createStarted();
while (lock == null || stopwatch.elapsed(TimeUnit.SECONDS) > TIMEOUT_SECONDS) {
try {
lock = channel.tryLock();
} catch (final IllegalStateException e) {
// Ignore
}
if (lock == null) {
try {
Thread.sleep(100L);
} catch (InterruptedException e) {
LOG.warn("Failed to lock xml", e);
}
}
}
try (InputStream resourceAsStream = new FileInputStream(newFile)) {
final XMLInputFactory factory = XMLInputFactory.newInstance();
final XMLStreamReader reader = factory.createXMLStreamReader(resourceAsStream);
final SchemaNode schemaNode = SchemaContextUtil.findDataSchemaNode(this.schemaContext, config.getSchemaPath());
try (XmlParserStream xmlParser = XmlParserStream.create(streamWriter, this.schemaContext, schemaNode)) {
xmlParser.parse(reader);
} catch (final URISyntaxException | XMLStreamException | IOException | ParserConfigurationException | SAXException e) {
LOG.warn("Failed to parse xml", e);
} finally {
reader.close();
channel.close();
}
}
return result.getResult();
}
use of org.opendaylight.yangtools.yang.data.impl.schema.NormalizedNodeResult in project controller by opendaylight.
the class BindingContext method parseDataElement.
public NormalizedNode<?, ?> parseDataElement(final Element element, final DataSchemaNode dataSchema, final SchemaContext schemaContext) throws XMLStreamException, IOException, ParserConfigurationException, SAXException, URISyntaxException {
final NormalizedNodeResult resultHolder = new NormalizedNodeResult();
final NormalizedNodeStreamWriter writer = ImmutableNormalizedNodeStreamWriter.from(resultHolder);
final XmlParserStream xmlParser = XmlParserStream.create(writer, schemaContext, dataSchema);
xmlParser.traverse(new DOMSource(element));
final NormalizedNode<?, ?> result = resultHolder.getResult();
if (result instanceof MapNode) {
final MapNode mapNode = (MapNode) result;
final MapEntryNode mapEntryNode = mapNode.getValue().iterator().next();
return mapEntryNode;
}
return result;
}
Aggregations