use of org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata in project netconf by opendaylight.
the class NetconfUtil method writeNormalizedNode.
/**
* Write data specified by {@link YangInstanceIdentifier} along with corresponding {@code metadata}
* into {@link DOMResult}.
*
* @param query path to the root node
* @param metadata metadata to be written
* @param result DOM result holder
* @param schemaPath schema path of the parent node
* @param context mountpoint schema context
* @throws IOException when failed to write data into {@link NormalizedNodeStreamWriter}
* @throws XMLStreamException when failed to serialize data into XML document
*/
public static void writeNormalizedNode(final YangInstanceIdentifier query, @Nullable final NormalizedMetadata metadata, final DOMResult result, final SchemaPath schemaPath, final EffectiveModelContext context) throws IOException, XMLStreamException {
if (metadata == null) {
writeNormalizedNode(query, result, schemaPath, context);
return;
}
final XMLStreamWriter xmlWriter = XML_FACTORY.createXMLStreamWriter(result);
XML_NAMESPACE_SETTER.initializeNamespace(xmlWriter);
try (var streamWriter = XMLStreamNormalizedNodeStreamWriter.create(xmlWriter, context, schemaPath);
var writer = new EmptyListXmlMetadataWriter(streamWriter, xmlWriter, streamWriter.getExtensions().getInstance(StreamWriterMetadataExtension.class), metadata)) {
final Iterator<PathArgument> it = query.getPathArguments().iterator();
final PathArgument first = it.next();
StreamingContext.fromSchemaAndQNameChecked(context, first.getNodeType()).streamToWriter(writer, first, it);
} finally {
xmlWriter.close();
}
}
use of org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata in project yangtools by opendaylight.
the class NormalizedMetadataWriter method write.
/**
* Iterate over the provided {@link NormalizedNode} and {@link NormalizedMetadata} and emit write events to the
* encapsulated {@link NormalizedNodeStreamWriter}.
*
* @param data NormalizedNode data
* @param metadata {@link NormalizedMetadata} metadata
* @return NormalizedNodeWriter this
* @throws NullPointerException if any argument is null
* @throws IllegalArgumentException if metadata does not match data
* @throws IOException when thrown from the backing writer.
*/
@NonNull
public NormalizedMetadataWriter write(final NormalizedNode data, final NormalizedMetadata metadata) throws IOException {
final PathArgument dataId = data.getIdentifier();
final PathArgument metaId = metadata.getIdentifier();
checkArgument(dataId.equals(metaId), "Mismatched data %s and metadata %s", dataId, metaId);
final StreamWriterMetadataExtension metaWriter = writer.getExtensions().getInstance(StreamWriterMetadataExtension.class);
final NormalizedNodeStreamWriter delegate = metaWriter == null ? writer : new NormalizedNodeStreamWriterMetadataDecorator(writer, metaWriter, metadata);
final NormalizedNodeWriter nnWriter = NormalizedNodeWriter.forStreamWriter(delegate, orderKeyLeaves);
nnWriter.write(data);
nnWriter.flush();
return this;
}
use of org.opendaylight.yangtools.rfc7952.data.api.NormalizedMetadata in project netconf by opendaylight.
the class NetconfMessageTransformUtil method leafMetadata.
private static NormalizedMetadata leafMetadata(final YangInstanceIdentifier path, final ModifyAction oper) {
final List<PathArgument> args = path.getPathArguments();
final Deque<Builder> builders = new ArrayDeque<>(args.size());
// Step one: open builders
for (PathArgument arg : args) {
builders.push(ImmutableNormalizedMetadata.builder().withIdentifier(arg));
}
// Step two: set the top builder's metadata
builders.peek().withAnnotation(NETCONF_OPERATION_QNAME_LEGACY, oper.toString().toLowerCase(Locale.US));
// Step three: build the tree
while (true) {
final ImmutableNormalizedMetadata currentMeta = builders.pop().build();
final Builder parent = builders.peek();
if (parent != null) {
parent.withChild(currentMeta);
} else {
return currentMeta;
}
}
}
Aggregations