Search in sources :

Example 1 with StreamWriterMetadataExtension

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;
}
Also used : NormalizedNodeWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter) NormalizedNodeStreamWriter(org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) StreamWriterMetadataExtension(org.opendaylight.yangtools.rfc7952.data.api.StreamWriterMetadataExtension) Objects.requireNonNull(java.util.Objects.requireNonNull) NonNull(org.eclipse.jdt.annotation.NonNull)

Aggregations

Objects.requireNonNull (java.util.Objects.requireNonNull)1 NonNull (org.eclipse.jdt.annotation.NonNull)1 StreamWriterMetadataExtension (org.opendaylight.yangtools.rfc7952.data.api.StreamWriterMetadataExtension)1 PathArgument (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument)1 NormalizedNodeStreamWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter)1 NormalizedNodeWriter (org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter)1