Binding v2 DOM Codec - codecs API - Part 1
[mdsal.git] / binding2 / mdsal-binding2-dom-codec / src / main / java / org / opendaylight / mdsal / binding / javav2 / dom / codec / api / codecs / BindingTreeNodeCodec.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies 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.javav2.dom.codec.api.codecs;
9
10 import com.google.common.annotations.Beta;
11 import com.google.common.base.Optional;
12 import com.google.common.collect.ImmutableCollection;
13 import java.util.List;
14 import javax.annotation.Nonnull;
15 import javax.annotation.Nullable;
16 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeArgument;
17 import org.opendaylight.mdsal.binding.javav2.spec.base.TreeNode;
18 import org.opendaylight.mdsal.binding.javav2.spec.runtime.BindingStreamEventWriter;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeStreamWriter;
21
22 /**
23  * Specific subtree codec to model subtree between Java Binding and DOM.
24  *
25  * @param <T>
26  *            - Binding representation of data
27  */
28 @Beta
29 public interface BindingTreeNodeCodec<T extends TreeNode> extends BindingNormalizedNodeCodec<T> {
30
31     /**
32      * Returns binding class of interface which represents API of current schema
33      * node.
34      *
35      * @return interface which defines API of binding representation of data.
36      */
37     @Nonnull
38     Class<T> getBindingClass();
39
40     /**
41      * Returns child context as if it was walked by
42      * {@link BindingStreamEventWriter}. This means that to enter case, one must
43      * issue getChild(ChoiceClass).getChild(CaseClass).
44      *
45      * @param childClass
46      *            - child class by Biding Stream navigation
47      * @return context of child
48      * @throws IllegalArgumentException
49      *             - if supplied child class is not valid in specified context
50      */
51     @Nonnull
52     <E extends TreeNode> BindingTreeNodeCodec<E> streamChild(@Nonnull Class<E> childClass);
53
54     /**
55      * Returns child context as if it was walked by
56      * {@link BindingStreamEventWriter}. This means that to enter case, one must
57      * issue getChild(ChoiceClass).getChild(CaseClass).
58      *
59      * This method differs from {@link #streamChild(Class)}, that is less
60      * stricter for interfaces representing augmentation and cases, that may
61      * return {@link BindingTreeNodeCodec} even if augmentation interface
62      * containing same data was supplied and does not represent augmentation of
63      * this node.
64      *
65      * @param childClass
66      *            - child class by Binding Stream navigation
67      * @return context of child or Optional absent if supplied is not applicable
68      *         in context
69      */
70     <E extends TreeNode> Optional<? extends BindingTreeNodeCodec<E>> possibleStreamChild(@Nonnull Class<E> childClass);
71
72     /**
73      * Returns nested node context using supplied YANG Instance Identifier.
74      *
75      * @param child
76      *            - Yang Instance Identifier Argument
77      * @return context of child
78      * @throws IllegalArgumentException
79      *             - if supplied argument does not represent valid child
80      */
81     @Nonnull
82     BindingTreeNodeCodec<?> yangPathArgumentChild(@Nonnull YangInstanceIdentifier.PathArgument child);
83
84     /**
85      * Returns nested node context using supplied Binding Instance Identifier
86      * and adds YANG instance identifiers to supplied list.
87      *
88      * @param arg
89      *            - Binding Instance Identifier Argument
90      * @param builder
91      *            - mutable instance of list, which is appended by
92      *            YangInstanceIdentifiers as tree is walked, use null if such
93      *            side-product is not needed
94      * @return context of child
95      * @throws IllegalArgumentException
96      *             - if supplied argument does not represent valid child.
97      */
98     @Nonnull
99     BindingTreeNodeCodec<?> bindingPathArgumentChild(@Nonnull TreeArgument<?> arg,
100             @Nullable List<YangInstanceIdentifier.PathArgument> builder);
101
102     /**
103      * Returns codec which uses caches serialization / deserialization results.
104      *
105      * Caching may introduce performance penalty to serialization /
106      * deserialization but may decrease use of heap for repetitive objects.
107      *
108      * @param cacheSpecifier
109      *            - set of objects, for which cache may be in place
110      * @return codec which uses cache for serialization / deserialization
111      */
112     @Nonnull
113     BindingNormalizedNodeCachingCodec<T>
114             createCachingCodec(@Nonnull ImmutableCollection<Class<? extends TreeNode>> cacheSpecifier);
115
116     /**
117      * Writes data representing object to supplied stream.
118      *
119      * @param data
120      *            - representing object
121      * @param writer
122      *            - supplied stream
123      */
124     void writeAsNormalizedNode(T data, NormalizedNodeStreamWriter writer);
125
126     /**
127      * Serializes path argument for current node.
128      *
129      * @param arg
130      *            - Binding Path Argument, may be null if Binding Instance
131      *            Identifier does not have representation for current node (e.g.
132      *            choice or case)
133      * @return Yang Path Argument, may be null if Yang Instance Identifier does
134      *         not have representation for current node (e.g. case).
135      * @throws IllegalArgumentException
136      *             - if supplied {@code arg} is not valid.
137      */
138     @Nullable
139     YangInstanceIdentifier.PathArgument serializePathArgument(@Nullable TreeArgument<?> arg);
140
141     /**
142      * Deserializes path argument for current node.
143      *
144      * @param arg
145      *            - Yang Path Argument, may be null if Yang Instance Identifier
146      *            does not have representation for current node (e.g. case)
147      * @return Binding Path Argument, may be null if Binding Instance Identifier
148      *         does not have representation for current node (e.g. choice or
149      *         case)
150      * @throws IllegalArgumentException
151      *             - if supplied {@code arg} is not valid.
152      */
153     @Nullable
154     TreeArgument<?> deserializePathArgument(@Nullable YangInstanceIdentifier.PathArgument arg);
155
156     /**
157      * Return schema of node codec context.
158      *
159      * @return {@link Object} as schema of specific node context
160      */
161     @Nonnull
162     Object getSchema();
163 }