Refactor anydata-related interfaces
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / NormalizedAnydata.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.api.schema;
9
10 import com.google.common.annotations.Beta;
11 import java.io.IOException;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.NonNullByDefault;
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.DataSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContextProvider;
20
21 /**
22  * The contents of an {@code anydata} node in a normalized format. This representation acts as a schema-bound bridge
23  * between the various (mostly parser-based) representations. Implementations of this interface are usually created
24  * from an instance of {@link NormalizableAnydata}.
25  *
26  * <p>
27  * Note this interface does not have an equality contract and implementations are expected to default to identity
28  * equality (or in Valhalla-speak: be plain data).
29  */
30 @Beta
31 @NonNullByDefault
32 public interface NormalizedAnydata extends Immutable, SchemaContextProvider {
33
34     @Override
35     // FIXME: remove this override when SchemaContextProvider's method has sane semantics.
36     @NonNull SchemaContext getSchemaContext();
37
38     DataSchemaNode getContextNode();
39
40     NormalizedNode<?, ?> getData();
41
42     default void writeTo(final NormalizedNodeStreamWriter writer) throws IOException {
43         writeTo(writer, true);
44     }
45
46     default void writeTo(final NormalizedNodeStreamWriter writer, final boolean orderKeyLeaves) throws IOException {
47         NormalizedNodeWriter.forStreamWriter(writer, orderKeyLeaves).write(getData()).flush();
48     }
49 }