use of org.opendaylight.yangtools.rfc7952.data.api.StreamWriterMetadataExtension 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;
}
Aggregations