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