Map identities to proper objects
[mdsal.git] / binding / mdsal-binding-dom-codec-api / src / main / java / org / opendaylight / mdsal / binding / dom / codec / api / BindingIdentityCodec.java
1 /*
2  * Copyright (c) 2019 PANTHEON.tech 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.dom.codec.api;
9
10 import com.google.common.annotations.Beta;
11 import org.eclipse.jdt.annotation.NonNull;
12 import org.opendaylight.yangtools.concepts.Immutable;
13 import org.opendaylight.yangtools.yang.binding.BaseIdentity;
14 import org.opendaylight.yangtools.yang.common.QName;
15
16 /**
17  * A codec capable of translating {@code identity} values between their YANG (QName) and Binding (Class) representation.
18  */
19 @Beta
20 public interface BindingIdentityCodec extends Immutable {
21     /**
22      * Convert a QNname to its corresponding Binding class.
23      *
24      * @param <T> Expected identity type
25      * @param qname Identity QName
26      * @return A binding value corresponding to the QName
27      * @throws IllegalArgumentException if the qname does not map to an identity
28      * @throws NullPointerException if {@code qname} is null
29      */
30     <T extends BaseIdentity> @NonNull T toBinding(@NonNull QName qname);
31
32     /**
33      * Convert a Binding value to its QName equivalent.
34      *
35      * @param bindingValue Binding value to convert
36      * @return QName corresponding to the binding value
37      * @throws IllegalArgumentException if the supplied value does not map to a known identity
38      * @throws NullPointerException if bindingClass is null
39      */
40     @NonNull QName fromBinding(@NonNull BaseIdentity bindingValue);
41 }