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.mdsal.binding.dom.codec.api;
10 import com.google.common.annotations.Beta;
11 import com.google.common.collect.ImmutableCollection;
12 import java.util.List;
13 import java.util.Optional;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.eclipse.jdt.annotation.Nullable;
16 import org.opendaylight.yangtools.yang.binding.BindingObject;
17 import org.opendaylight.yangtools.yang.binding.BindingStreamEventWriter;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
24 public interface BindingDataObjectCodecTreeNode<T extends DataObject> extends BindingObjectCodecTreeNode<T>,
25 BindingNormalizedNodeCodec<T> {
28 * Returns binding class of interface which represents API of current schema node. The result is same as invoking
29 * {@link DataObject#implementedInterface()} on instance of data.
31 * @return interface which defines API of binding representation of data.
34 @NonNull Class<T> getBindingClass();
37 * Returns child context as if it was walked by {@link BindingStreamEventWriter}. This means that to enter case,
38 * one must issue getChild(ChoiceClass).getChild(CaseClass).
40 * @param childClass Child class by Binding Stream navigation
41 * @return Context of child
42 * @throws IllegalArgumentException
43 * If supplied child class is not valid in specified context.
45 <E extends DataObject> @NonNull BindingDataObjectCodecTreeNode<E> streamChild(@NonNull Class<E> childClass);
48 * Returns child context as if it was walked by {@link BindingStreamEventWriter}. This means that to enter case,
49 * one must issue getChild(ChoiceClass).getChild(CaseClass).
52 * This method differs from {@link #streamChild(Class)}, that is less strict for interfaces representing
53 * augmentation and cases, that may return {@link BindingCodecTreeNode} even if augmentation interface containing
54 * same data was supplied and does not represent augmentation of this node.
56 * @param childClass Child class by Binding Stream navigation
57 * @return Context of child or Optional.empty is supplied class is not
58 * applicable in context.
60 <E extends DataObject> Optional<? extends BindingDataObjectCodecTreeNode<E>> possibleStreamChild(
61 @NonNull Class<E> childClass);
64 * Returns nested node context using supplied YANG Instance Identifier.
67 * Yang Instance Identifier Argument
68 * @return Context of child
69 * @throws IllegalArgumentException
70 * If supplied argument does not represent valid child.
72 @NonNull BindingCodecTreeNode yangPathArgumentChild(YangInstanceIdentifier.@NonNull PathArgument child);
75 * Returns nested node context using supplied Binding Instance Identifier and adds YANG instance identifiers to
79 * Binding Instance Identifier Argument
81 * Mutable instance of list, which is appended by YangInstanceIdentifiers
82 * as tree is walked. Use null if such side-product is not needed.
83 * @return Context of child
84 * @throws IllegalArgumentException
85 * If supplied argument does not represent valid child.
87 @NonNull BindingDataObjectCodecTreeNode<?> bindingPathArgumentChild(InstanceIdentifier.@NonNull PathArgument arg,
88 @Nullable List<YangInstanceIdentifier.PathArgument> builder);
91 * Serializes path argument for current node.
93 * @param arg Binding Path Argument, may be null if Binding Instance Identifier does not have
94 * representation for current node (e.g. choice or case).
95 * @return Yang Path Argument, may be null if Yang Instance Identifier does not have
96 * representation for current node (e.g. case).
97 * @throws IllegalArgumentException If supplied {@code arg} is not valid.
100 YangInstanceIdentifier.@Nullable PathArgument serializePathArgument(InstanceIdentifier.@Nullable PathArgument arg);
103 * Deserializes path argument for current node.
105 * @param arg Yang Path Argument, may be null if Yang Instance Identifier does not have
106 * representation for current node (e.g. case).
107 * @return Binding Path Argument, may be null if Binding Instance Identifier does not have
108 * representation for current node (e.g. choice or case).
109 * @throws IllegalArgumentException If supplied {@code arg} is not valid.
112 InstanceIdentifier.@Nullable PathArgument deserializePathArgument(
113 YangInstanceIdentifier.@Nullable PathArgument arg);
117 * Return a summary of addressability of potential children. Binding specification does not allow all DOM tree
118 * elements to be directly addressed, which means some recursive tree operations, like data tree changes do not
119 * have a one-to-one mapping from DOM to binding in all cases. This method provides an optimization hint to guide
120 * translation of data structures, allowing for fast paths when all children are known to either be addressable
121 * or non-addressable.
123 * @return Summary children addressability.
125 @NonNull ChildAddressabilitySummary getChildAddressabilitySummary();
128 * Returns codec which uses caches serialization / deserialization results.
131 * Caching may introduce performance penalty to serialization / deserialization
132 * but may decrease use of heap for repetitive objects.
134 * @param cacheSpecifier Set of objects, for which cache may be in place
135 * @return Codec which uses cache for serialization / deserialization.
137 @NonNull BindingNormalizedNodeCachingCodec<T> createCachingCodec(
138 @NonNull ImmutableCollection<Class<? extends BindingObject>> cacheSpecifier);
141 void writeAsNormalizedNode(T data, NormalizedNodeStreamWriter writer);
144 * Enumeration of possible addressability attribute of all children.
146 enum ChildAddressabilitySummary {
148 * All children are addressable.
152 * All children are non-addressable, including the case when this node does not have any children.
156 * Mixed children, some are addressable and some are not.