2 * Copyright (c) 2023 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.mdsal.binding.dom.codec.api;
10 import java.util.List;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.eclipse.jdt.annotation.Nullable;
13 import org.opendaylight.yangtools.binding.Augmentation;
14 import org.opendaylight.yangtools.binding.BindingContract;
15 import org.opendaylight.yangtools.binding.DataContainer;
16 import org.opendaylight.yangtools.binding.DataObject;
17 import org.opendaylight.yangtools.binding.DataObjectStep;
18 import org.opendaylight.yangtools.yang.common.Empty;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
22 * A {@link BindingObjectCodecTreeNode} which corresponds to a {@link DataContainer} construct.
24 * @param <T> DataContainer type
26 public non-sealed interface BindingDataContainerCodecTreeNode<T extends DataContainer>
27 extends BindingObjectCodecTreeNode, BindingDataObjectCodecTreeParent<Empty> {
29 * Returns binding class of interface which represents API of current schema node. The result is same as invoking
30 * {@link BindingContract#implementedInterface()} on instance of data.
32 * @return interface which defines API of binding representation of data.
35 Class<T> getBindingClass();
38 * Returns child context as if it was walked by {@link BindingStreamEventWriter}. This means that to enter case,
39 * one must issue getChild(ChoiceClass).getChild(CaseClass).
42 * This method differs from {@link #getStreamChild(Class)}, that is less strict for interfaces representing
43 * augmentation and cases, that may return {@link BindingCodecTreeNode} even if augmentation interface containing
44 * same data was supplied and does not represent augmentation of this node.
46 * @param childClass Child class by Binding Stream navigation
47 * @return Context of child or {@code null} is supplied class is not applicable in context.
48 * @throws NullPointerException if {@code childClass} is {@code null}
50 <E extends DataObject> @Nullable BindingDataContainerCodecTreeNode<E> streamChild(@NonNull Class<E> childClass);
52 default <A extends Augmentation<?>> @Nullable BindingAugmentationCodecTreeNode<A> streamAugmentation(
53 final @NonNull Class<A> childClass) {
54 final var result = streamChild(childClass);
55 if (result instanceof BindingAugmentationCodecTreeNode) {
56 return (BindingAugmentationCodecTreeNode<A>) result;
57 } else if (result == null) {
60 throw new IllegalArgumentException(
61 "Child " + childClass.getName() + " results in non-Augmentation " + result);
65 default <E extends DataObject> @Nullable BindingDataObjectCodecTreeNode<E> streamDataObject(
66 final @NonNull Class<E> childClass) {
67 final var result = streamChild(childClass);
68 if (result instanceof BindingDataObjectCodecTreeNode) {
69 return (BindingDataObjectCodecTreeNode<E>) result;
70 } else if (result == null) {
73 throw new IllegalArgumentException(
74 "Child " + childClass.getName() + " results in non-DataObject " + result);
79 * Returns nested node context using supplied {@link PathArgument}.
81 * @param child a {@link PathArgument}
82 * @return Context of child
83 * @throws IllegalArgumentException If supplied argument does not represent valid child.
85 @NonNull BindingCodecTreeNode yangPathArgumentChild(@NonNull PathArgument child);
88 * Returns nested node context using supplied DataObjectStep and adds YANG instance identifiers to
91 * @param step A {@link DataObjectStep}
92 * @param builder a mutable List to receive {@link PathArgument}s. Use {@code null} if such side-product is not
94 * @return A {@link CommonDataObjectCodecTreeNode}
95 * @throws IllegalArgumentException if supplied argument does not represent valid child.
97 @NonNull CommonDataObjectCodecTreeNode<?> bindingPathArgumentChild(@NonNull DataObjectStep<?> step,
98 @Nullable List<PathArgument> builder);
101 * Return a summary of addressability of potential children. Binding specification does not allow all DOM tree
102 * elements to be directly addressed, which means some recursive tree operations, like data tree changes do not
103 * have a one-to-one mapping from DOM to binding in all cases. This method provides an optimization hint to guide
104 * translation of data structures, allowing for fast paths when all children are known to either be addressable
105 * or non-addressable.
107 * @return Summary children addressability.
109 @NonNull ChildAddressabilitySummary getChildAddressabilitySummary();
112 * Enumeration of possible addressability attribute of all children.
114 enum ChildAddressabilitySummary {
116 * All children are addressable.
120 * All children are non-addressable, including the case when this node does not have any children.
124 * Mixed children, some are addressable and some are not.