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