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 static com.google.common.base.Verify.verifyNotNull;
12 import com.google.common.annotations.Beta;
13 import com.google.common.base.VerifyException;
14 import java.util.Map.Entry;
15 import org.eclipse.jdt.annotation.NonNull;
16 import org.eclipse.jdt.annotation.Nullable;
17 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
18 import org.opendaylight.yangtools.yang.binding.Action;
19 import org.opendaylight.yangtools.yang.binding.DataContainer;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
22 import org.opendaylight.yangtools.yang.binding.Notification;
23 import org.opendaylight.yangtools.yang.binding.RpcInput;
24 import org.opendaylight.yangtools.yang.binding.RpcOutput;
25 import org.opendaylight.yangtools.yang.common.YangConstants;
26 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
29 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
30 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
33 * Serialization service, which provides two-way serialization between Java
34 * Binding Data representation and NormalizedNode representation.
36 public interface BindingNormalizedNodeSerializer {
38 * Translates supplied Binding Instance Identifier into NormalizedNode instance identifier.
40 * @param binding Binding Instance Identifier
41 * @return DOM Instance Identifier
42 * @throws IllegalArgumentException If supplied Instance Identifier is not valid.
44 YangInstanceIdentifier toYangInstanceIdentifier(@NonNull InstanceIdentifier<?> binding);
47 * Translates supplied YANG Instance Identifier into Binding instance identifier. This method can return null
48 * if the instance identifier is not representable in Binding. If it is statically known this is not the case,
49 * use {@link #coerceFromYangInstanceIdentifier(YangInstanceIdentifier)}.
51 * @param dom YANG Instance Identifier
52 * @return Binding Instance Identifier, or null if the instance identifier is not representable.
54 <T extends DataObject> @Nullable InstanceIdentifier<T> fromYangInstanceIdentifier(
55 @NonNull YangInstanceIdentifier dom);
58 * Translates supplied YANG Instance Identifier into Binding instance identifier.
60 * @param dom YANG Instance Identifier
61 * @return Binding Instance Identifier
62 * @throws VerifyException if the instance identifier is not representable.
65 default <T extends DataObject> @NonNull InstanceIdentifier<T> coerceFromYangInstanceIdentifier(
66 final @NonNull YangInstanceIdentifier dom) {
67 return verifyNotNull(fromYangInstanceIdentifier(dom), "%s is not representable", dom);
71 * Translates supplied Binding Instance Identifier and data into NormalizedNode representation.
73 * @param path Binding Instance Identifier pointing to data
74 * @param data Data object representing data
75 * @return NormalizedNode representation
76 * @throws IllegalArgumentException If supplied Instance Identifier is not valid.
78 <T extends DataObject> Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> toNormalizedNode(
79 InstanceIdentifier<T> path, T data);
82 * Translates supplied YANG Instance Identifier and NormalizedNode into Binding data.
84 * @param path Binding Instance Identifier
85 * @param data NormalizedNode representing data
86 * @return DOM Instance Identifier
88 @Nullable Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode(@NonNull YangInstanceIdentifier path,
89 NormalizedNode<?, ?> data);
92 * Translates supplied NormalizedNode Notification into Binding data.
94 * @param path Schema Path of Notification, schema path is absolute, and consists of Notification QName.
95 * @param data NormalizedNode representing data
96 * @return Binding representation of Notification
98 @Nullable Notification fromNormalizedNodeNotification(@NonNull SchemaPath path, @NonNull ContainerNode data);
101 * Translates supplied NormalizedNode RPC input or output into Binding data.
103 * @param path Schema path of RPC data, Schema path consists of rpc QName and input / output QName.
104 * @param data NormalizedNode representing data
105 * @return Binding representation of RPC data
107 @Nullable DataObject fromNormalizedNodeRpcData(@NonNull SchemaPath path, @NonNull ContainerNode data);
110 * Translates supplied ContainerNode action input.
112 * @param action Binding action class
113 * @param input ContainerNode representing data
114 * @return Binding representation of action input
115 * @throws NullPointerException if any of the arguments is null
118 <T extends RpcInput> @NonNull T fromNormalizedNodeActionInput(
119 @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull ContainerNode input);
122 * Translates supplied ContainerNode action output.
124 * @param action Binding action class
125 * @param output ContainerNode representing data
126 * @return Binding representation of action output
127 * @throws NullPointerException if any of the arguments is null
130 <T extends RpcOutput> @NonNull T fromNormalizedNodeActionOutput(
131 @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull ContainerNode output);
134 * Translates supplied Binding Notification or output into NormalizedNode notification.
136 * @param data NormalizedNode representing notification data
137 * @return NormalizedNode representation of notification
139 @NonNull ContainerNode toNormalizedNodeNotification(@NonNull Notification data);
142 * Translates supplied Binding RPC input or output into NormalizedNode data.
144 * @param data NormalizedNode representing rpc data
145 * @return NormalizedNode representation of rpc data
147 @NonNull ContainerNode toNormalizedNodeRpcData(@NonNull DataContainer data);
150 * Lazily translates supplied Binding action input into NormalizedNode data.
152 * @param action Binding action class
153 * @param input Binding action input
154 * @return NormalizedNode representation of action input
155 * @throws NullPointerException if any of the arguments is null
158 @NonNull BindingLazyContainerNode<RpcInput> toLazyNormalizedNodeActionInput(
159 @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull NodeIdentifier identifier,
160 @NonNull RpcInput input);
163 * Lazily translates supplied Binding action input into NormalizedNode data.
165 * @param action Binding action class
166 * @param input Binding action input
167 * @return NormalizedNode representation of action input
168 * @throws NullPointerException if any of the arguments is null
171 default @NonNull BindingLazyContainerNode<RpcInput> toLazyNormalizedNodeActionInput(
172 final @NonNull Class<? extends Action<?, ?, ?>> action, final @NonNull RpcInput input) {
173 return toLazyNormalizedNodeActionInput(action,
174 new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), input);
178 * Translates supplied Binding action input into NormalizedNode data.
180 * @param action Binding action class
181 * @param input Binding action input
182 * @return NormalizedNode representation of action input
183 * @throws NullPointerException if any of the arguments is null
186 default @NonNull ContainerNode toNormalizedNodeActionInput(final @NonNull Class<? extends Action<?, ?, ?>> action,
187 @NonNull final RpcInput input) {
188 return toLazyNormalizedNodeActionInput(action,
189 new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), input)
194 * Lazily translates supplied Binding action output into NormalizedNode data.
196 * @param action Binding action class
197 * @param output Binding action output
198 * @return NormalizedNode representation of action output
201 @NonNull BindingLazyContainerNode<RpcOutput> toLazyNormalizedNodeActionOutput(
202 @NonNull Class<? extends Action<?, ?, ?>> action, @NonNull NodeIdentifier identifier,
203 @NonNull RpcOutput output);
206 * Lazily translates supplied Binding action output into NormalizedNode data.
208 * @param action Binding action class
209 * @param output Binding action output
210 * @return NormalizedNode representation of action output
213 default @NonNull BindingLazyContainerNode<RpcOutput> toLazyNormalizedNodeActionOutput(
214 final @NonNull Class<? extends Action<?, ?, ?>> action, final @NonNull RpcOutput output) {
215 return toLazyNormalizedNodeActionOutput(action,
216 new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output);
220 * Translates supplied Binding action output into NormalizedNode data.
222 * @param output Binding action output
223 * @return NormalizedNode representation of action output
226 default @NonNull ContainerNode toNormalizedNodeActionOutput(final @NonNull Class<? extends Action<?, ?, ?>> action,
227 final @NonNull RpcOutput output) {
228 return toLazyNormalizedNodeActionOutput(action,
229 new NodeIdentifier(YangConstants.operationInputQName(BindingReflections.getQNameModule(action))), output)