Update DataObjectStep class hierarchy
[yangtools.git] / data / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / schema / NormalizedNode.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. 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 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;
16
17 /**
18  * Node which is normalized according to the YANG schema
19  * is identifiable by a {@link org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier}.
20  *
21  * <p>
22  * See subinterfaces of this interface for concretization of node.
23  */
24 /*
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.
30  *
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.
34  *
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
38  *               "UnverifiedData".
39  *
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.
44  *
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'.
49  */
50 public sealed interface NormalizedNode extends NormalizedData, PrettyTreeAware
51         permits AbstractNormalizedNode, DataContainerChild, NormalizedNodeContainer, ValueNode {
52     @Override
53     Class<? extends NormalizedNode> contract();
54
55     @Override
56     PathArgument name();
57
58     /**
59      * A builder of {@link NormalizedNode}s.
60      */
61     interface Builder extends Mutable {
62         /**
63          * Return a builder {@link NormalizedNode} contract.
64          *
65          * @return a built NormalizedNode
66          * @throws IllegalStateException if this builder does not have sufficient state
67          */
68         @NonNull NormalizedNode build();
69     }
70
71     /**
72      * A factory for concrete {@link Builder}s.
73      */
74     @NonNullByDefault
75     interface BuilderFactory {
76
77         <T> AnydataNode.Builder<T> newAnydataBuilder(Class<T> objectModel);
78
79         <T> AnyxmlNode.Builder<T, AnyxmlNode<T>> newAnyxmlBuilder(Class<T> objectModel);
80
81         ChoiceNode.Builder newChoiceBuilder();
82
83         ChoiceNode.Builder newChoiceBuilder(int sizeHint);
84
85         ChoiceNode.Builder newChoiceBuilder(ChoiceNode node);
86
87         ContainerNode.Builder newContainerBuilder();
88
89         ContainerNode.Builder newContainerBuilder(int sizeHint);
90
91         ContainerNode.Builder newContainerBuilder(ContainerNode node);
92
93         MapEntryNode.Builder newMapEntryBuilder();
94
95         MapEntryNode.Builder newMapEntryBuilder(int sizeHint);
96
97         MapEntryNode.Builder newMapEntryBuilder(MapEntryNode node);
98
99         SystemMapNode.Builder newSystemMapBuilder();
100
101         SystemMapNode.Builder newSystemMapBuilder(int sizeHint);
102
103         SystemMapNode.Builder newSystemMapBuilder(SystemMapNode node);
104
105         UserMapNode.Builder newUserMapBuilder();
106
107         UserMapNode.Builder newUserMapBuilder(int sizeHint);
108
109         UserMapNode.Builder newUserMapBuilder(UserMapNode node);
110
111         default MapNode.Builder<?> newMapBuilder(final Ordering ordering) {
112             return switch (ordering) {
113                 case SYSTEM -> newSystemMapBuilder();
114                 case USER -> newUserMapBuilder();
115             };
116         }
117
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);
122             };
123         }
124
125         UnkeyedListEntryNode.Builder newUnkeyedListEntryBuilder();
126
127         UnkeyedListEntryNode.Builder newUnkeyedListEntryBuilder(int sizeHint);
128
129         UnkeyedListEntryNode.Builder newUnkeyedListEntryBuilder(UnkeyedListEntryNode node);
130
131         UnkeyedListNode.Builder newUnkeyedListBuilder();
132
133         UnkeyedListNode.Builder newUnkeyedListBuilder(int sizeHint);
134
135         UnkeyedListNode.Builder newUnkeyedListBuilder(UnkeyedListNode node);
136
137         <T> LeafNode.Builder<T> newLeafBuilder();
138
139         <T> LeafSetEntryNode.Builder<T> newLeafSetEntryBuilder();
140
141         <T> SystemLeafSetNode.Builder<T> newSystemLeafSetBuilder();
142
143         <T> SystemLeafSetNode.Builder<T> newSystemLeafSetBuilder(int sizeHint);
144
145         <T> SystemLeafSetNode.Builder<T> newSystemLeafSetBuilder(SystemLeafSetNode<T> node);
146
147         <T> UserLeafSetNode.Builder<T> newUserLeafSetBuilder();
148
149         <T> UserLeafSetNode.Builder<T> newUserLeafSetBuilder(int sizeHint);
150
151         <T> UserLeafSetNode.Builder<T> newUserLeafSetBuilder(UserLeafSetNode<T> node);
152
153         default <T> LeafSetNode.Builder<T, ?> newLeafSetBuilder(final Ordering ordering) {
154             return switch (ordering) {
155                 case SYSTEM -> newSystemLeafSetBuilder();
156                 case USER -> newUserLeafSetBuilder();
157             };
158         }
159
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);
164             };
165         }
166     }
167 }