2dc3b398eeb5c248a0a74a1d724becc6d2a1505a
[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.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
21
22 @Beta
23 public interface BindingDataObjectCodecTreeNode<T extends DataObject> extends BindingObjectCodecTreeNode<T>,
24         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      * @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.
43      */
44     <E extends DataObject> @NonNull BindingDataObjectCodecTreeNode<E> streamChild(@NonNull Class<E> childClass);
45
46     /**
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).
49      *
50      * <p>
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.
54      *
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.
58      */
59     <E extends DataObject> Optional<? extends BindingDataObjectCodecTreeNode<E>> possibleStreamChild(
60             @NonNull Class<E> childClass);
61
62     /**
63      * Returns nested node context using supplied YANG Instance Identifier.
64      *
65      * @param child
66      *            Yang Instance Identifier Argument
67      * @return Context of child
68      * @throws IllegalArgumentException
69      *             If supplied argument does not represent valid child.
70      */
71     @NonNull BindingCodecTreeNode yangPathArgumentChild(YangInstanceIdentifier.@NonNull PathArgument child);
72
73     /**
74      * Returns nested node context using supplied Binding Instance Identifier and adds YANG instance identifiers to
75      * the supplied list.
76      *
77      * @param arg
78      *            Binding Instance Identifier Argument
79      * @param builder
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.
85      */
86     @NonNull BindingDataObjectCodecTreeNode<?> bindingPathArgumentChild(InstanceIdentifier.@NonNull PathArgument arg,
87             @Nullable List<YangInstanceIdentifier.PathArgument> builder);
88
89     /**
90      * Serializes path argument for current node.
91      *
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.
97      */
98     @Beta
99     YangInstanceIdentifier.@Nullable PathArgument serializePathArgument(InstanceIdentifier.@Nullable PathArgument arg);
100
101     /**
102      * Deserializes path argument for current node.
103      *
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.
109      */
110     @Beta
111     InstanceIdentifier.@Nullable PathArgument deserializePathArgument(
112             YangInstanceIdentifier.@Nullable PathArgument arg);
113
114
115     /**
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.
121      *
122      * @return Summary children addressability.
123      */
124     @NonNull ChildAddressabilitySummary getChildAddressabilitySummary();
125
126     /**
127      * Returns codec which uses caches serialization / deserialization results.
128      *
129      * <p>
130      * Caching may introduce performance penalty to serialization / deserialization
131      * but may decrease use of heap for repetitive objects.
132      *
133      * @param cacheSpecifier Set of objects, for which cache may be in place
134      * @return Codec which uses cache for serialization / deserialization.
135      */
136     @NonNull BindingNormalizedNodeCachingCodec<T> createCachingCodec(
137             @NonNull ImmutableCollection<Class<? extends BindingObject>> cacheSpecifier);
138
139     @Beta
140     void writeAsNormalizedNode(T data, NormalizedNodeStreamWriter writer);
141
142     /**
143      * Enumeration of possible addressability attribute of all children.
144      */
145     enum ChildAddressabilitySummary {
146         /**
147          * All children are addressable.
148          */
149         ADDRESSABLE,
150         /**
151          * All children are non-addressable, including the case when this node does not have any children.
152          */
153         UNADDRESSABLE,
154         /**
155          * Mixed children, some are addressable and some are not.
156          */
157         MIXED
158     }
159 }