6943433667a04a005c7de6e52e7ab530a628d400
[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.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.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
22 /**
23  * Subtree codec specific to model subtree between Java Binding and
24  * 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
31      * schema node.
32      *
33      * The result is same as invoking {@link DataObject#getImplementedInterface()}
34      * on instance of data.
35      *
36      * @return interface which defines API of binding representation of data.
37      */
38     @Nonnull
39     Class<T> getBindingClass();
40
41     /**
42      * Returns child context as if it was walked by
43      * {@link BindingStreamEventWriter}. This means that to enter case, one must
44      * issue getChild(ChoiceClass).getChild(CaseClass).
45      *
46      * @param childClass 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 DataObject> BindingCodecTreeNode<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
61      * may return {@link BindingCodecTreeNode} even if augmentation interface
62      * containing same data was supplied and does not represent augmentation
63      * of this node.
64      *
65      * @param childClass
66      * @return Context of child or Optional absent is supplied class is not
67      *         applicable in context.
68      */
69     <E extends DataObject> Optional<? extends BindingCodecTreeNode<E>> possibleStreamChild(@Nonnull Class<E> childClass);
70
71     /**
72      * Returns nested node context using supplied YANG Instance Identifier
73      *
74      * @param child
75      *            Yang Instance Identifier Argument
76      * @return Context of child
77      * @throws IllegalArgumentException
78      *             If supplied argument does not represent valid child.
79      */
80     @Nonnull
81     BindingCodecTreeNode<?> yangPathArgumentChild(@Nonnull YangInstanceIdentifier.PathArgument child);
82
83     /**
84      * Returns nested node context using supplied Binding Instance Identifier
85      * and adds YANG instance identifiers to supplied list.
86      *
87      * @param arg
88      *            Binding Instance Identifier Argument
89      * @param builder
90      *            Mutable instance of list, which is appended by YangInstanceIdentifiers
91      *            as tree is walked. Use null if such side-product is not needed.
92      * @return Context of child
93      * @throws IllegalArgumentException
94      *             If supplied argument does not represent valid child.
95      */
96     @Nonnull
97     BindingCodecTreeNode<?> bindingPathArgumentChild(@Nonnull InstanceIdentifier.PathArgument arg,
98             @Nullable List<YangInstanceIdentifier.PathArgument> builder);
99
100     /**
101      * Returns codec which uses caches serialization / deserialization results
102      *
103      * Caching may introduce performance penalty to serialization / deserialization
104      * but may decrease use of heap for repetitive objects.
105      *
106      *
107      * @param cacheSpecifier Set of objects, for which cache may be in place
108      * @return Codec whihc uses cache for serialization / deserialization.
109      */
110     @Nonnull
111     BindingNormalizedNodeCachingCodec<T> createCachingCodec(@Nonnull
112             ImmutableCollection<Class<? extends DataObject>> cacheSpecifier);
113
114     @Beta
115     void writeAsNormalizedNode(T data, NormalizedNodeStreamWriter writer);
116
117     /**
118      * Serializes path argument for current node.
119      *
120      * @param arg Binding Path Argument, may be null if Binding Instance Identifier does not have
121      *        representation for current node (e.g. choice or case).
122      * @return Yang Path Argument, may be null if Yang Instance Identifier does not have
123      *         representation for current node (e.g. case).
124      * @throws IllegalArgumentException If supplied {@code arg} is not valid.
125      */
126     @Beta
127     @Nullable YangInstanceIdentifier.PathArgument serializePathArgument(@Nullable InstanceIdentifier.PathArgument arg);
128
129     /**
130      * Deserializes path argument for current node.
131      *
132      * @param arg Yang Path Argument, may be null if Yang Instance Identifier does not have
133      *         representation for current node (e.g. case).
134      * @return Binding Path Argument, may be null if Binding Instance Identifier does not have
135      *        representation for current node (e.g. choice or case).
136      * @throws IllegalArgumentException If supplied {@code arg} is not valid.
137      */
138     @Beta
139     @Nullable InstanceIdentifier.PathArgument deserializePathArgument(@Nullable YangInstanceIdentifier.PathArgument arg);
140
141     Object getSchema();
142 }