2 * Copyright (c) 2014 Cisco Systems, Inc. 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 org.eclipse.jdt.annotation.NonNull;
11 import org.eclipse.jdt.annotation.NonNullByDefault;
12 import org.opendaylight.yangtools.concepts.Mutable;
13 import org.opendaylight.yangtools.concepts.PrettyTreeAware;
14 import org.opendaylight.yangtools.yang.common.Ordering;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
18 * Node which is normalized according to the YANG schema
19 * is identifiable by a {@link org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier}.
22 * See subinterfaces of this interface for concretization of node.
25 * FIXME: 8.0.0: NormalizedNode represents the perfectly-compliant view of the data, as evaluated by an implementation,
26 * which is currently singular, with respect of its interpretation of a SchemaContext. This includes
27 * leaf values, which are required to hold normalized representation for a particular implementation,
28 * which may be affected by its understanding of any YANG extensions present -- such as optional type
29 * handling hints and bindings.
31 * Implementations (i.e. the reference implementation and parsers) will need to start using
32 * yang.common.Uint8 and friends and, if possible, express data validation in terms
33 * of yang.common.CanonicalValue and yang.common.CanonicalValueValidator.
35 * This notably means that to efficiently implement any sort of lenient parsing, we need a separate
36 * concept which contains an unverified, potentially non-conformant data tree, which the consumer needs
37 * to check/fixup if it wishes to use it as a NormalizedNode. Such a concept should be called
40 * FIXME: 8.0.0: Once we have UnverifiedData, we should really rename this to "NormalizedData" or similar to unload
41 * some "Node" ambiguity. "Node" should be a generic term reserved for a particular domain -- hence 'node'
42 * can be used to refer to either a 'schema node' in context of yang.model.api, or to
43 * a 'normalized data node' in context of yang.data.api.
45 * FIXME: 8.0.0: Well, not quite. The structure of unverified data is really codec specific -- and JSON and XML
46 * do not agree on details. Furthermore things get way more complicated when we have a cross-schema
47 * boundary -- like RFC8528. Hence we cannot really have a reasonably-structured concept of unverified
48 * data. Nevertheless, this interface should be named 'NormalizedData'.
50 public sealed interface NormalizedNode extends NormalizedData, PrettyTreeAware
51 permits AbstractNormalizedNode, DataContainerChild, NormalizedNodeContainer, ValueNode {
53 Class<? extends NormalizedNode> contract();
59 * A builder of {@link NormalizedNode}s.
61 interface Builder extends Mutable {
63 * Return a builder {@link NormalizedNode} contract.
65 * @return a built NormalizedNode
66 * @throws IllegalStateException if this builder does not have sufficient state
68 @NonNull NormalizedNode build();
72 * A factory for concrete {@link Builder}s.
75 interface BuilderFactory {
77 <T> AnydataNode.Builder<T> newAnydataBuilder(Class<T> objectModel);
79 <T> AnyxmlNode.Builder<T, AnyxmlNode<T>> newAnyxmlBuilder(Class<T> objectModel);
81 ChoiceNode.Builder newChoiceBuilder();
83 ChoiceNode.Builder newChoiceBuilder(int sizeHint);
85 ChoiceNode.Builder newChoiceBuilder(ChoiceNode node);
87 ContainerNode.Builder newContainerBuilder();
89 ContainerNode.Builder newContainerBuilder(int sizeHint);
91 ContainerNode.Builder newContainerBuilder(ContainerNode node);
93 MapEntryNode.Builder newMapEntryBuilder();
95 MapEntryNode.Builder newMapEntryBuilder(int sizeHint);
97 MapEntryNode.Builder newMapEntryBuilder(MapEntryNode node);
99 SystemMapNode.Builder newSystemMapBuilder();
101 SystemMapNode.Builder newSystemMapBuilder(int sizeHint);
103 SystemMapNode.Builder newSystemMapBuilder(SystemMapNode node);
105 UserMapNode.Builder newUserMapBuilder();
107 UserMapNode.Builder newUserMapBuilder(int sizeHint);
109 UserMapNode.Builder newUserMapBuilder(UserMapNode node);
111 default MapNode.Builder<?> newMapBuilder(final Ordering ordering) {
112 return switch (ordering) {
113 case SYSTEM -> newSystemMapBuilder();
114 case USER -> newUserMapBuilder();
118 default MapNode.Builder<?> newMapBuilder(final Ordering ordering, final int sizeHint) {
119 return switch (ordering) {
120 case SYSTEM -> newSystemMapBuilder(sizeHint);
121 case USER -> newUserMapBuilder(sizeHint);
125 UnkeyedListEntryNode.Builder newUnkeyedListEntryBuilder();
127 UnkeyedListEntryNode.Builder newUnkeyedListEntryBuilder(int sizeHint);
129 UnkeyedListEntryNode.Builder newUnkeyedListEntryBuilder(UnkeyedListEntryNode node);
131 UnkeyedListNode.Builder newUnkeyedListBuilder();
133 UnkeyedListNode.Builder newUnkeyedListBuilder(int sizeHint);
135 UnkeyedListNode.Builder newUnkeyedListBuilder(UnkeyedListNode node);
137 <T> LeafNode.Builder<T> newLeafBuilder();
139 <T> LeafSetEntryNode.Builder<T> newLeafSetEntryBuilder();
141 <T> SystemLeafSetNode.Builder<T> newSystemLeafSetBuilder();
143 <T> SystemLeafSetNode.Builder<T> newSystemLeafSetBuilder(int sizeHint);
145 <T> SystemLeafSetNode.Builder<T> newSystemLeafSetBuilder(SystemLeafSetNode<T> node);
147 <T> UserLeafSetNode.Builder<T> newUserLeafSetBuilder();
149 <T> UserLeafSetNode.Builder<T> newUserLeafSetBuilder(int sizeHint);
151 <T> UserLeafSetNode.Builder<T> newUserLeafSetBuilder(UserLeafSetNode<T> node);
153 default <T> LeafSetNode.Builder<T, ?> newLeafSetBuilder(final Ordering ordering) {
154 return switch (ordering) {
155 case SYSTEM -> newSystemLeafSetBuilder();
156 case USER -> newUserLeafSetBuilder();
160 default <T> LeafSetNode.Builder<T, ?> newLeafSetBuilder(final Ordering ordering, final int sizeHint) {
161 return switch (ordering) {
162 case SYSTEM -> newSystemLeafSetBuilder(sizeHint);
163 case USER -> newUserLeafSetBuilder(sizeHint);