Remove yang-test
[controller.git] / opendaylight / config / config-manager / src / main / java / org / opendaylight / controller / config / manager / impl / util / ModuleQNameUtil.java
1 /*
2  * Copyright (c) 2013, 2017 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.controller.config.manager.impl.util;
9
10 import java.util.HashSet;
11 import java.util.Map;
12 import java.util.Map.Entry;
13 import java.util.Set;
14 import org.opendaylight.controller.config.spi.ModuleFactory;
15 import org.opendaylight.yangtools.yang.binding.annotations.ModuleQName;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.osgi.framework.BundleContext;
18
19 public final class ModuleQNameUtil {
20
21     private ModuleQNameUtil() {
22     }
23
24     public static Set<String> getQNames(final Map<String, Entry<ModuleFactory, BundleContext>> resolved) {
25         final Set<String> result = new HashSet<>();
26         for (final Entry<ModuleFactory, BundleContext> entry : resolved.values()) {
27             Class<?> inspected = entry.getKey().getClass();
28             if (inspected.isInterface()) {
29                 throw new IllegalArgumentException("Unexpected interface " + inspected);
30             }
31             ModuleQName annotation = null;
32             while (annotation == null && inspected != null) {
33                 annotation = inspected.getAnnotation(ModuleQName.class);
34                 inspected = inspected.getSuperclass();
35             }
36             if (annotation != null) {
37                 result.add(QName.create(annotation.namespace(), annotation.revision(), annotation.name()).toString());
38             }
39         }
40         return result;
41     }
42 }