Move BindingReflections to mdsal-binding-spec-util
[mdsal.git] / binding / mdsal-binding-dom-codec / src / main / java / org / opendaylight / mdsal / binding / dom / codec / api / BindingNormalizedNodeSerializer.java
1 /*
2  * Copyright (c) 2014 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 java.util.Map.Entry;
12 import javax.annotation.Nonnull;
13 import javax.annotation.Nullable;
14 import org.eclipse.jdt.annotation.NonNull;
15 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
16 import org.opendaylight.yangtools.yang.binding.Action;
17 import org.opendaylight.yangtools.yang.binding.DataContainer;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
20 import org.opendaylight.yangtools.yang.binding.Notification;
21 import org.opendaylight.yangtools.yang.binding.RpcInput;
22 import org.opendaylight.yangtools.yang.binding.RpcOutput;
23 import org.opendaylight.yangtools.yang.common.YangConstants;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
27 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
28 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
29
30 /**
31  * Serialization service, which provides two-way serialization between Java
32  * Binding Data representation and NormalizedNode representation.
33  */
34 public interface BindingNormalizedNodeSerializer {
35     /**
36      * Translates supplied Binding Instance Identifier into NormalizedNode instance identifier.
37      *
38      * @param binding Binding Instance Identifier
39      * @return DOM Instance Identifier
40      * @throws IllegalArgumentException If supplied Instance Identifier is not valid.
41      */
42     YangInstanceIdentifier toYangInstanceIdentifier(@Nonnull InstanceIdentifier<?> binding);
43
44     /**
45      * Translates supplied YANG Instance Identifier into Binding instance identifier.
46      *
47      * @param dom YANG Instance Identifier
48      * @return Binding Instance Identifier, or null if the instance identifier is not representable.
49      */
50     @Nullable
51     <T extends DataObject> InstanceIdentifier<T> fromYangInstanceIdentifier(@Nonnull YangInstanceIdentifier dom);
52
53     /**
54      * Translates supplied Binding Instance Identifier and data into NormalizedNode representation.
55      *
56      * @param path Binding Instance Identifier pointing to data
57      * @param data Data object representing data
58      * @return NormalizedNode representation
59      * @throws IllegalArgumentException If supplied Instance Identifier is not valid.
60      */
61     <T extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalizedNode(
62             InstanceIdentifier<T> path, T data);
63
64     /**
65      * Translates supplied YANG Instance Identifier and NormalizedNode into Binding data.
66      *
67      * @param path Binding Instance Identifier
68      * @param data NormalizedNode representing data
69      * @return DOM Instance Identifier
70      */
71     @Nullable
72     Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode(@Nonnull YangInstanceIdentifier path,
73             NormalizedNode<?, ?> data);
74
75     /**
76      * Translates supplied NormalizedNode Notification into Binding data.
77      *
78      * @param path Schema Path of Notification, schema path is absolute, and consists of Notification QName.
79      * @param data NormalizedNode representing data
80      * @return Binding representation of Notification
81      */
82     @Nullable Notification fromNormalizedNodeNotification(@Nonnull SchemaPath path,@Nonnull ContainerNode data);
83
84     /**
85      * Translates supplied NormalizedNode RPC input or output into Binding data.
86      *
87      * @param path Schema path of RPC data, Schema path consists of rpc QName and input / output QName.
88      * @param data NormalizedNode representing data
89      * @return Binding representation of RPC data
90      */
91     @Nullable DataObject fromNormalizedNodeRpcData(@Nonnull SchemaPath path,@Nonnull ContainerNode data);
92
93     /**
94      * Translates supplied ContainerNode action input.
95      *
96      * @param action Binding action class
97      * @param input ContainerNode representing data
98      * @return Binding representation of action input
99      * @throws NullPointerException if any of the arguments is null
100      */
101     @Beta
102     <T extends RpcInput> @NonNull T fromNormalizedNodeActionInput(
103             @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull ContainerNode input);
104
105     /**
106      * Translates supplied ContainerNode action output.
107      *
108      * @param action Binding action class
109      * @param output ContainerNode representing data
110      * @return Binding representation of action output
111      * @throws NullPointerException if any of the arguments is null
112      */
113     @Beta
114     <T extends RpcOutput> @NonNull T fromNormalizedNodeActionOutput(
115             @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull ContainerNode output);
116
117     /**
118      * Translates supplied Binding Notification or output into NormalizedNode notification.
119      *
120      * @param data NormalizedNode representing notification data
121      * @return NormalizedNode representation of notification
122      */
123     @Nonnull ContainerNode toNormalizedNodeNotification(@Nonnull Notification data);
124
125     /**
126      * Translates supplied Binding RPC input or output into NormalizedNode data.
127      *
128      * @param data NormalizedNode representing rpc data
129      * @return NormalizedNode representation of rpc data
130      */
131     @Nonnull ContainerNode toNormalizedNodeRpcData(@Nonnull DataContainer data);
132
133     /**
134      * Lazily translates supplied Binding action input into NormalizedNode data.
135      *
136      * @param action Binding action class
137      * @param input Binding action input
138      * @return NormalizedNode representation of action input
139      * @throws NullPointerException if any of the arguments is null
140      */
141     @Beta
142     @NonNull BindingLazyContainerNode<RpcInput> toLazyNormalizedNodeActionInput(
143             @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull NodeIdentifier identifier,
144                     @NonNull RpcInput input);
145
146     /**
147      * Lazily translates supplied Binding action input into NormalizedNode data.
148      *
149      * @param action Binding action class
150      * @param input Binding action input
151      * @return NormalizedNode representation of action input
152      * @throws NullPointerException if any of the arguments is null
153      */
154     @Beta default @NonNull BindingLazyContainerNode<RpcInput> toLazyNormalizedNodeActionInput(
155             @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcInput input) {
156         return toLazyNormalizedNodeActionInput(action,
157             new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), input);
158     }
159
160     /**
161      * Translates supplied Binding action input into NormalizedNode data.
162      *
163      * @param action Binding action class
164      * @param input Binding action input
165      * @return NormalizedNode representation of action input
166      * @throws NullPointerException if any of the arguments is null
167      */
168     @Beta default @NonNull ContainerNode toNormalizedNodeActionInput(
169             @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcInput input) {
170         return toLazyNormalizedNodeActionInput(action,
171             new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), input)
172                 .getDelegate();
173     }
174
175     /**
176      * Lazily translates supplied Binding action output into NormalizedNode data.
177      *
178      * @param action Binding action class
179      * @param output Binding action output
180      * @return NormalizedNode representation of action output
181      */
182     @Beta
183     @NonNull BindingLazyContainerNode<RpcOutput> toLazyNormalizedNodeActionOutput(
184             @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull NodeIdentifier identifier,
185                     @NonNull RpcOutput output);
186
187     /**
188      * Lazily translates supplied Binding action output into NormalizedNode data.
189      *
190      * @param action Binding action class
191      * @param output Binding action output
192      * @return NormalizedNode representation of action output
193      */
194     @Beta default @NonNull BindingLazyContainerNode<RpcOutput> toLazyNormalizedNodeActionOutput(
195             @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcOutput output) {
196         return toLazyNormalizedNodeActionOutput(action,
197             new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output);
198     }
199
200     /**
201      * Translates supplied Binding action output into NormalizedNode data.
202      *
203      * @param output Binding action output
204      * @return NormalizedNode representation of action output
205      */
206     @Beta default @NonNull ContainerNode toNormalizedNodeActionOutput(
207             @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcOutput output) {
208         return toLazyNormalizedNodeActionOutput(action,
209             new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output)
210                 .getDelegate();
211     }
212 }