Split out BindingDataObjectCodecTreeNode.streamChild()
[mdsal.git] / binding / mdsal-binding-dom-codec-api / src / main / java / org / opendaylight / mdsal / binding / dom / codec / api / BindingDataObjectCodecTreeNode.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.mdsal.binding.dom.codec.api;
9
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.common.Empty;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
22
23 @Beta
24 public interface BindingDataObjectCodecTreeNode<T extends DataObject>
25         extends BindingDataObjectCodecTreeParent<Empty>, BindingObjectCodecTreeNode<T>, BindingNormalizedNodeCodec<T> {
26
27     /**
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.
30      *
31      * @return interface which defines API of binding representation of data.
32      */
33     @Override
34     @NonNull Class<T> getBindingClass();
35
36     /**
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).
39      *
40      * <p>
41      * This method differs from {@link #streamChild(Class)}, that is less strict for interfaces representing
42      * augmentation and cases, that may return {@link BindingCodecTreeNode} even if augmentation interface containing
43      * same data was supplied and does not represent augmentation of this node.
44      *
45      * @param childClass Child class by Binding Stream navigation
46      * @return Context of child or Optional.empty is supplied class is not
47      *         applicable in context.
48      */
49     <E extends DataObject> Optional<? extends BindingDataObjectCodecTreeNode<E>> possibleStreamChild(
50             @NonNull Class<E> childClass);
51
52     /**
53      * Returns nested node context using supplied YANG Instance Identifier.
54      *
55      * @param child
56      *            Yang Instance Identifier Argument
57      * @return Context of child
58      * @throws IllegalArgumentException
59      *             If supplied argument does not represent valid child.
60      */
61     @NonNull BindingCodecTreeNode yangPathArgumentChild(YangInstanceIdentifier.@NonNull PathArgument child);
62
63     /**
64      * Returns nested node context using supplied Binding Instance Identifier and adds YANG instance identifiers to
65      * the supplied list.
66      *
67      * @param arg
68      *            Binding Instance Identifier Argument
69      * @param builder
70      *            Mutable instance of list, which is appended by YangInstanceIdentifiers
71      *            as tree is walked. Use null if such side-product is not needed.
72      * @return Context of child
73      * @throws IllegalArgumentException
74      *             If supplied argument does not represent valid child.
75      */
76     @NonNull BindingDataObjectCodecTreeNode<?> bindingPathArgumentChild(InstanceIdentifier.@NonNull PathArgument arg,
77             @Nullable List<YangInstanceIdentifier.PathArgument> builder);
78
79     /**
80      * Serializes path argument for current node.
81      *
82      * @param arg Binding Path Argument, may be null if Binding Instance Identifier does not have
83      *        representation for current node (e.g. choice or case).
84      * @return Yang Path Argument, may be null if Yang Instance Identifier does not have
85      *         representation for current node (e.g. case).
86      * @throws IllegalArgumentException If supplied {@code arg} is not valid.
87      */
88     @Beta
89     YangInstanceIdentifier.@Nullable PathArgument serializePathArgument(InstanceIdentifier.@Nullable PathArgument arg);
90
91     /**
92      * Deserializes path argument for current node.
93      *
94      * @param arg Yang Path Argument, may be null if Yang Instance Identifier does not have
95      *         representation for current node (e.g. case).
96      * @return Binding Path Argument, may be null if Binding Instance Identifier does not have
97      *        representation for current node (e.g. choice or case).
98      * @throws IllegalArgumentException If supplied {@code arg} is not valid.
99      */
100     @Beta
101     InstanceIdentifier.@Nullable PathArgument deserializePathArgument(
102             YangInstanceIdentifier.@Nullable PathArgument arg);
103
104
105     /**
106      * Return a summary of addressability of potential children. Binding specification does not allow all DOM tree
107      * elements to be directly addressed, which means some recursive tree operations, like data tree changes do not
108      * have a one-to-one mapping from DOM to binding in all cases. This method provides an optimization hint to guide
109      * translation of data structures, allowing for fast paths when all children are known to either be addressable
110      * or non-addressable.
111      *
112      * @return Summary children addressability.
113      */
114     @NonNull ChildAddressabilitySummary getChildAddressabilitySummary();
115
116     /**
117      * Returns codec which uses caches serialization / deserialization results.
118      *
119      * <p>
120      * Caching may introduce performance penalty to serialization / deserialization
121      * but may decrease use of heap for repetitive objects.
122      *
123      * @param cacheSpecifier Set of objects, for which cache may be in place
124      * @return Codec which uses cache for serialization / deserialization.
125      */
126     @NonNull BindingNormalizedNodeCachingCodec<T> createCachingCodec(
127             @NonNull ImmutableCollection<Class<? extends BindingObject>> cacheSpecifier);
128
129     @Beta
130     void writeAsNormalizedNode(T data, NormalizedNodeStreamWriter writer);
131
132     /**
133      * Enumeration of possible addressability attribute of all children.
134      */
135     enum ChildAddressabilitySummary {
136         /**
137          * All children are addressable.
138          */
139         ADDRESSABLE,
140         /**
141          * All children are non-addressable, including the case when this node does not have any children.
142          */
143         UNADDRESSABLE,
144         /**
145          * Mixed children, some are addressable and some are not.
146          */
147         MIXED
148     }
149 }