2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.data.api.schema;
10 import com.google.common.annotations.Beta;
11 import java.io.IOException;
12 import org.eclipse.jdt.annotation.NonNullByDefault;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.yangtools.concepts.Immutable;
15 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
16 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
17 import org.opendaylight.yangtools.yang.model.api.EffectiveStatementInference;
20 * The contents of an {@code anydata} node in a normalized format. This representation acts as a schema-bound bridge
21 * between the various (mostly parser-based) representations. Implementations of this interface are usually created
22 * from an instance of {@link NormalizableAnydata}.
25 * Note this interface does not have an equality contract and implementations are expected to default to identity
26 * equality (or in Valhalla-speak: be plain data).
30 public interface NormalizedAnydata extends Immutable {
32 * Return the {@link EffectiveStatementInference} which describes the structure returned by {@link #getData()}.
34 * @return An {@link EffectiveStatementInference}
36 EffectiveStatementInference getInference();
39 * Return the {@link NormalizedNode} representation of this node's data. Information about the corresponding schema
40 * is available via {@link #getInference()}.
42 * @return A {@link NormalizedNode}
44 NormalizedNode getData();
46 default void writeTo(final NormalizedNodeStreamWriter writer) throws IOException {
47 writeTo(writer, true);
50 default void writeTo(final NormalizedNodeStreamWriter writer, final boolean orderKeyLeaves) throws IOException {
51 NormalizedNodeWriter.forStreamWriter(writer, orderKeyLeaves).write(getData()).flush();
54 static NormalizedAnydata of(final EffectiveStatementInference inference, final NormalizedNode data) {
55 return new ImmutableNormalizedAnydata(inference, data);
58 static NormalizedAnydata of(final EffectiveStatementInference inference, final NormalizedNode data,
59 final @Nullable NormalizedMetadata metadata) {
60 return metadata != null ? MetadataNormalizedAnydata.of(inference, data, metadata) : of(inference, data);