2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.dom.codec.api;
10 import com.google.common.annotations.Beta;
11 import java.util.Map.Entry;
12 import org.eclipse.jdt.annotation.NonNull;
13 import org.eclipse.jdt.annotation.Nullable;
14 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
15 import org.opendaylight.yangtools.yang.binding.Action;
16 import org.opendaylight.yangtools.yang.binding.DataContainer;
17 import org.opendaylight.yangtools.yang.binding.DataObject;
18 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
19 import org.opendaylight.yangtools.yang.binding.Notification;
20 import org.opendaylight.yangtools.yang.binding.RpcInput;
21 import org.opendaylight.yangtools.yang.binding.RpcOutput;
22 import org.opendaylight.yangtools.yang.common.YangConstants;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
27 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
30 * Serialization service, which provides two-way serialization between Java
31 * Binding Data representation and NormalizedNode representation.
33 public interface BindingNormalizedNodeSerializer {
35 * Translates supplied Binding Instance Identifier into NormalizedNode instance identifier.
37 * @param binding Binding Instance Identifier
38 * @return DOM Instance Identifier
39 * @throws IllegalArgumentException If supplied Instance Identifier is not valid.
41 YangInstanceIdentifier toYangInstanceIdentifier(@NonNull InstanceIdentifier<?> binding);
44 * Translates supplied YANG Instance Identifier into Binding instance identifier.
46 * @param dom YANG Instance Identifier
47 * @return Binding Instance Identifier, or null if the instance identifier is not representable.
49 <T extends DataObject> @Nullable InstanceIdentifier<T> fromYangInstanceIdentifier(
50 @NonNull YangInstanceIdentifier dom);
53 * Translates supplied Binding Instance Identifier and data into NormalizedNode representation.
55 * @param path Binding Instance Identifier pointing to data
56 * @param data Data object representing data
57 * @return NormalizedNode representation
58 * @throws IllegalArgumentException If supplied Instance Identifier is not valid.
60 <T extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalizedNode(
61 InstanceIdentifier<T> path, T data);
64 * Translates supplied YANG Instance Identifier and NormalizedNode into Binding data.
66 * @param path Binding Instance Identifier
67 * @param data NormalizedNode representing data
68 * @return DOM Instance Identifier
70 @Nullable Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode(@NonNull YangInstanceIdentifier path,
71 NormalizedNode<?, ?> data);
74 * Translates supplied NormalizedNode Notification into Binding data.
76 * @param path Schema Path of Notification, schema path is absolute, and consists of Notification QName.
77 * @param data NormalizedNode representing data
78 * @return Binding representation of Notification
80 @Nullable Notification fromNormalizedNodeNotification(@NonNull SchemaPath path, @NonNull ContainerNode data);
83 * Translates supplied NormalizedNode RPC input or output into Binding data.
85 * @param path Schema path of RPC data, Schema path consists of rpc QName and input / output QName.
86 * @param data NormalizedNode representing data
87 * @return Binding representation of RPC data
89 @Nullable DataObject fromNormalizedNodeRpcData(@NonNull SchemaPath path, @NonNull ContainerNode data);
92 * Translates supplied ContainerNode action input.
94 * @param action Binding action class
95 * @param input ContainerNode representing data
96 * @return Binding representation of action input
97 * @throws NullPointerException if any of the arguments is null
100 <T extends RpcInput> @NonNull T fromNormalizedNodeActionInput(
101 @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull ContainerNode input);
104 * Translates supplied ContainerNode action output.
106 * @param action Binding action class
107 * @param output ContainerNode representing data
108 * @return Binding representation of action output
109 * @throws NullPointerException if any of the arguments is null
112 <T extends RpcOutput> @NonNull T fromNormalizedNodeActionOutput(
113 @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull ContainerNode output);
116 * Translates supplied Binding Notification or output into NormalizedNode notification.
118 * @param data NormalizedNode representing notification data
119 * @return NormalizedNode representation of notification
121 @NonNull ContainerNode toNormalizedNodeNotification(@NonNull Notification data);
124 * Translates supplied Binding RPC input or output into NormalizedNode data.
126 * @param data NormalizedNode representing rpc data
127 * @return NormalizedNode representation of rpc data
129 @NonNull ContainerNode toNormalizedNodeRpcData(@NonNull DataContainer data);
132 * Lazily translates supplied Binding action input into NormalizedNode data.
134 * @param action Binding action class
135 * @param input Binding action input
136 * @return NormalizedNode representation of action input
137 * @throws NullPointerException if any of the arguments is null
140 @NonNull BindingLazyContainerNode<RpcInput> toLazyNormalizedNodeActionInput(
141 @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull NodeIdentifier identifier,
142 @NonNull RpcInput input);
145 * Lazily translates supplied Binding action input into NormalizedNode data.
147 * @param action Binding action class
148 * @param input Binding action input
149 * @return NormalizedNode representation of action input
150 * @throws NullPointerException if any of the arguments is null
152 @Beta default @NonNull BindingLazyContainerNode<RpcInput> toLazyNormalizedNodeActionInput(
153 @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcInput input) {
154 return toLazyNormalizedNodeActionInput(action,
155 new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), input);
159 * Translates supplied Binding action input into NormalizedNode data.
161 * @param action Binding action class
162 * @param input Binding action input
163 * @return NormalizedNode representation of action input
164 * @throws NullPointerException if any of the arguments is null
166 @Beta default @NonNull ContainerNode toNormalizedNodeActionInput(
167 @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcInput input) {
168 return toLazyNormalizedNodeActionInput(action,
169 new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), input)
174 * Lazily translates supplied Binding action output into NormalizedNode data.
176 * @param action Binding action class
177 * @param output Binding action output
178 * @return NormalizedNode representation of action output
181 @NonNull BindingLazyContainerNode<RpcOutput> toLazyNormalizedNodeActionOutput(
182 @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull NodeIdentifier identifier,
183 @NonNull RpcOutput output);
186 * Lazily translates supplied Binding action output into NormalizedNode data.
188 * @param action Binding action class
189 * @param output Binding action output
190 * @return NormalizedNode representation of action output
192 @Beta default @NonNull BindingLazyContainerNode<RpcOutput> toLazyNormalizedNodeActionOutput(
193 @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcOutput output) {
194 return toLazyNormalizedNodeActionOutput(action,
195 new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output);
199 * Translates supplied Binding action output into NormalizedNode data.
201 * @param output Binding action output
202 * @return NormalizedNode representation of action output
204 @Beta default @NonNull ContainerNode toNormalizedNodeActionOutput(
205 @NonNull final Class<? extends Action<?, ?, ?>> action, @NonNull final RpcOutput output) {
206 return toLazyNormalizedNodeActionOutput(action,
207 new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output)