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.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
23 public interface BindingDataObjectCodecTreeNode<T extends DataObject> extends BindingObjectCodecTreeNode<T>,
24 BindingNormalizedNodeCodec<T> {
27 * Returns binding class of interface which represents API of current schema node. The result is same as invoking
28 * {@link DataObject#implementedInterface()} on instance of data.
30 * @return interface which defines API of binding representation of data.
33 @NonNull Class<T> getBindingClass();
36 * Returns child context as if it was walked by {@link BindingStreamEventWriter}. This means that to enter case,
37 * one must issue getChild(ChoiceClass).getChild(CaseClass).
39 * @param childClass Child class by Binding Stream navigation
40 * @return Context of child
41 * @throws IllegalArgumentException
42 * If supplied child class is not valid in specified context.
44 <E extends DataObject> @NonNull BindingDataObjectCodecTreeNode<E> streamChild(@NonNull Class<E> childClass);
47 * Returns child context as if it was walked by {@link BindingStreamEventWriter}. This means that to enter case,
48 * one must issue getChild(ChoiceClass).getChild(CaseClass).
51 * This method differs from {@link #streamChild(Class)}, that is less strict for interfaces representing
52 * augmentation and cases, that may return {@link BindingCodecTreeNode} even if augmentation interface containing
53 * same data was supplied and does not represent augmentation of this node.
55 * @param childClass Child class by Binding Stream navigation
56 * @return Context of child or Optional.empty is supplied class is not
57 * applicable in context.
59 <E extends DataObject> Optional<? extends BindingDataObjectCodecTreeNode<E>> possibleStreamChild(
60 @NonNull Class<E> childClass);
63 * Returns nested node context using supplied YANG Instance Identifier.
66 * Yang Instance Identifier Argument
67 * @return Context of child
68 * @throws IllegalArgumentException
69 * If supplied argument does not represent valid child.
71 @NonNull BindingCodecTreeNode yangPathArgumentChild(YangInstanceIdentifier.@NonNull PathArgument child);
74 * Returns nested node context using supplied Binding Instance Identifier and adds YANG instance identifiers to
78 * Binding Instance Identifier Argument
80 * Mutable instance of list, which is appended by YangInstanceIdentifiers
81 * as tree is walked. Use null if such side-product is not needed.
82 * @return Context of child
83 * @throws IllegalArgumentException
84 * If supplied argument does not represent valid child.
86 @NonNull BindingDataObjectCodecTreeNode<?> bindingPathArgumentChild(InstanceIdentifier.@NonNull PathArgument arg,
87 @Nullable List<YangInstanceIdentifier.PathArgument> builder);
90 * Serializes path argument for current node.
92 * @param arg Binding Path Argument, may be null if Binding Instance Identifier does not have
93 * representation for current node (e.g. choice or case).
94 * @return Yang Path Argument, may be null if Yang Instance Identifier does not have
95 * representation for current node (e.g. case).
96 * @throws IllegalArgumentException If supplied {@code arg} is not valid.
99 YangInstanceIdentifier.@Nullable PathArgument serializePathArgument(InstanceIdentifier.@Nullable PathArgument arg);
102 * Deserializes path argument for current node.
104 * @param arg Yang Path Argument, may be null if Yang Instance Identifier does not have
105 * representation for current node (e.g. case).
106 * @return Binding Path Argument, may be null if Binding Instance Identifier does not have
107 * representation for current node (e.g. choice or case).
108 * @throws IllegalArgumentException If supplied {@code arg} is not valid.
111 InstanceIdentifier.@Nullable PathArgument deserializePathArgument(
112 YangInstanceIdentifier.@Nullable PathArgument arg);
116 * Return a summary of addressability of potential children. Binding specification does not allow all DOM tree
117 * elements to be directly addressed, which means some recursive tree operations, like data tree changes do not
118 * have a one-to-one mapping from DOM to binding in all cases. This method provides an optimization hint to guide
119 * translation of data structures, allowing for fast paths when all children are known to either be addressable
120 * or non-addressable.
122 * @return Summary children addressability.
124 @NonNull ChildAddressabilitySummary getChildAddressabilitySummary();
127 * Returns codec which uses caches serialization / deserialization results.
130 * Caching may introduce performance penalty to serialization / deserialization
131 * but may decrease use of heap for repetitive objects.
133 * @param cacheSpecifier Set of objects, for which cache may be in place
134 * @return Codec which uses cache for serialization / deserialization.
136 @NonNull BindingNormalizedNodeCachingCodec<T> createCachingCodec(
137 @NonNull ImmutableCollection<Class<? extends BindingObject>> cacheSpecifier);
140 void writeAsNormalizedNode(T data, NormalizedNodeStreamWriter writer);
143 * Enumeration of possible addressability attribute of all children.
145 enum ChildAddressabilitySummary {
147 * All children are addressable.
151 * All children are non-addressable, including the case when this node does not have any children.
155 * Mixed children, some are addressable and some are not.