X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fconfig%2Fconfig-manager%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fconfig%2Fmanager%2Fimpl%2Futil%2FInterfacesHelper.java;h=a6e9b1ba965b8532eb2e688742ca6ec66c5d5e10;hp=76cb64cf9349ae62cc99d7f66eb12e7f66a0ed74;hb=386d8f0ac5fa09ee5514d48284f1a4012f408b52;hpb=089bfc0f3f32322b54dba2bf9402769638c09e06 diff --git a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java index 76cb64cf93..a6e9b1ba96 100644 --- a/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java +++ b/opendaylight/config/config-manager/src/main/java/org/opendaylight/controller/config/manager/impl/util/InterfacesHelper.java @@ -7,17 +7,18 @@ */ package org.opendaylight.controller.config.manager.impl.util; +import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface; +import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation; +import org.opendaylight.controller.config.spi.Module; +import org.opendaylight.controller.config.spi.ModuleFactory; + +import javax.management.JMX; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import javax.management.JMX; - -import org.opendaylight.controller.config.api.annotations.AbstractServiceInterface; -import org.opendaylight.controller.config.api.annotations.ServiceInterfaceAnnotation; -import org.opendaylight.controller.config.spi.Module; - public class InterfacesHelper { public static Set> getAllInterfaces(Class clazz) { @@ -32,16 +33,25 @@ public class InterfacesHelper { // get parent class clazz = clazz.getSuperclass(); } + return getAllSuperInterfaces(toBeInspected); + + } + + private static Set> getAllSuperInterfaces(Set> ifcs) { + ifcs = new HashSet<>(ifcs); // create copy to modify // each interface can extend other interfaces - Set> inspected = new HashSet<>(); - while (toBeInspected.size() > 0) { - Iterator> iterator = toBeInspected.iterator(); + Set> result = new HashSet<>(); + while (ifcs.size() > 0) { + Iterator> iterator = ifcs.iterator(); Class ifc = iterator.next(); iterator.remove(); - toBeInspected.addAll(Arrays.asList(ifc.getInterfaces())); - inspected.add(ifc); + if (ifc.isInterface() == false) { + throw new IllegalArgumentException(ifc + " should be an interface"); + } + ifcs.addAll(Arrays.asList(ifc.getInterfaces())); + result.add(ifc); } - return inspected; + return result; } /** @@ -80,6 +90,18 @@ public class InterfacesHelper { return result; } + public static Set> getAllAbstractServiceClasses(Class configBeanClass) { + + Set> foundGeneratedSIClasses = new HashSet<>(); + for (Class clazz : getAllInterfaces(configBeanClass)) { + if (AbstractServiceInterface.class.isAssignableFrom(clazz) && AbstractServiceInterface.class.equals(clazz) == false) { + foundGeneratedSIClasses.add((Class) clazz); + } + } + return getAllAbstractServiceInterfaceClasses(foundGeneratedSIClasses); + } + + /** * Get OSGi registration types under which config bean instance should be * registered. This is specified in @@ -98,4 +120,44 @@ public class InterfacesHelper { return result; } + public static Set getQNames(Set siAnnotations) { + Set qNames = new HashSet<>(); + for (ServiceInterfaceAnnotation sia: siAnnotations) { + qNames.add(sia.value()); + } + return Collections.unmodifiableSet(qNames); + } + + public static Set getServiceInterfaceAnnotations(ModuleFactory factory) { + Set> implementedServiceIntefaces = Collections.unmodifiableSet(factory.getImplementedServiceIntefaces()); + return getServiceInterfaceAnnotations(implementedServiceIntefaces); + } + + private static Set getServiceInterfaceAnnotations(Set> implementedServiceIntefaces) { + Set> inspected = getAllAbstractServiceInterfaceClasses(implementedServiceIntefaces); + Set result = new HashSet<>(); + // SIs can form hierarchies, inspect superclass until it does not extend AbstractSI + for (Class clazz : inspected) { + ServiceInterfaceAnnotation annotation = clazz.getAnnotation(ServiceInterfaceAnnotation.class); + if (annotation != null) { + result.add(annotation); + } + } + return Collections.unmodifiableSet(result); + } + + static Set> getAllAbstractServiceInterfaceClasses( + Set> directlyImplementedAbstractSIs) { + + Set> allInterfaces = getAllSuperInterfaces((Set) directlyImplementedAbstractSIs); + Set> result = new HashSet<>(); + for(Class ifc: allInterfaces){ + if (AbstractServiceInterface.class.isAssignableFrom(ifc) && + ifc.equals(AbstractServiceInterface.class) == false) { + result.add((Class) ifc); + } + + } + return result; + } }