Merge "On openflow plugin restart, NPE in tx poller"
[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.osgi.framework.BundleContext;
13
14 import java.util.HashSet;
15 import java.util.Map;
16 import java.util.Map.Entry;
17 import java.util.Set;
18
19 public class ModuleQNameUtil {
20
21     public static Set<String> getQNames(Map<String, Entry<ModuleFactory, BundleContext>> resolved) {
22         Set<String> result = new HashSet<>();
23         for (Entry<ModuleFactory, BundleContext> entry : resolved.values()) {
24             Class<?> inspected = entry.getKey().getClass();
25             if (inspected.isInterface()) {
26                 throw new IllegalArgumentException("Unexpected interface " + inspected);
27             }
28             ModuleQName annotation = null;
29             while(annotation == null && inspected != null) {
30                 annotation = inspected.getAnnotation(ModuleQName.class);
31                 inspected = inspected.getSuperclass();
32             }
33             if (annotation != null) {
34                 // FIXME
35                 String qName = "(" + annotation.namespace() + "?revision=" + annotation.revision() + ")" + annotation.name();
36                 result.add(qName);
37             }
38         }
39         return result;
40     }
41
42 }