Use BindingReflections.getQName()
[bgpcep.git] / bmp / bmp-impl / src / main / java / org / opendaylight / protocol / bmp / impl / app / TablesUtil.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.protocol.bmp.impl.app;
9
10 import com.google.common.collect.ImmutableMap;
11 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.rib.rev180329.rib.TablesKey;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.AddressFamily;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.types.rev200120.SubsequentAddressFamily;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bmp.monitor.rev200120.BmpMonitor;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
18
19 public final class TablesUtil {
20     public static final QName BMP_TABLES_QNAME = QName.create(BmpMonitor.QNAME, "tables").intern();
21     public static final QName BMP_ATTRIBUTES_QNAME = QName.create(BmpMonitor.QNAME, "attributes").intern();
22     public static final QName BMP_ROUTES_QNAME = QName.create(BmpMonitor.QNAME, "routes").intern();
23     public static final QName BMP_AFI_QNAME = QName.create(BMP_TABLES_QNAME, "afi").intern();
24     public static final QName BMP_SAFI_QNAME = QName.create(BMP_TABLES_QNAME, "safi").intern();
25
26     private TablesUtil() {
27         // Hidden on purpose
28     }
29
30     /**
31      * Creates Yang Instance Identifier path argument from supplied AFI and SAFI.
32      *
33      * @param afi Class representing AFI
34      * @param safi Class representing SAFI
35      * @return NodeIdentifierWithPredicates for specified AFI, SAFI combination.
36      */
37     public static NodeIdentifierWithPredicates toYangTablesKey(final AddressFamily afi,
38             final SubsequentAddressFamily safi) {
39         return NodeIdentifierWithPredicates.of(BMP_TABLES_QNAME,
40             ImmutableMap.of(
41                 BMP_AFI_QNAME, BindingReflections.getQName(afi),
42                 BMP_SAFI_QNAME, BindingReflections.getQName(safi)));
43     }
44
45     /**
46      * Creates Yang Instance Identifier path argument from supplied QNAMES and AFI and SAFI.
47      *
48      * @param nodeName QName reprenting node
49      * @param afi Class representing AFI
50      * @param safi Class representing SAFI
51      * @return NodeIdentifierWithPredicates for specified AFI, SAFI combination.
52      */
53     public static NodeIdentifierWithPredicates toYangTablesKey(final QName nodeName,
54             final AddressFamily afi, final SubsequentAddressFamily safi) {
55         return NodeIdentifierWithPredicates.of(nodeName,
56             ImmutableMap.of(
57                 BMP_AFI_QNAME.bindTo(nodeName.getModule()).intern(), BindingReflections.getQName(afi),
58                 BMP_SAFI_QNAME.bindTo(nodeName.getModule()).intern(), BindingReflections.getQName(safi)));
59     }
60
61     /**
62      * Creates Yang Instance Identifier path argument from supplied {@link TablesKey}.
63      *
64      * @param tablesKey Tables key representing table.
65      * @return NodeIdentifierWithPredicates of for specified AFI, SAFI combination.
66      */
67     public static NodeIdentifierWithPredicates toYangTablesKey(final TablesKey tablesKey) {
68         return toYangTablesKey(tablesKey.getAfi(), tablesKey.getSafi());
69     }
70 }