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