+ public static YangModuleInfo getModuleInfo(final Class<?> cls) throws Exception {
+ checkArgument(cls != null);
+ String packageName = getModelRootPackageName(cls.getPackage());
+ final String potentialClassName = getModuleInfoClassName(packageName);
+ return withClassLoader(cls.getClassLoader(), new Callable<YangModuleInfo>() {
+
+ @Override
+ public YangModuleInfo call() throws Exception {
+ Class<?> moduleInfoClass = Thread.currentThread().getContextClassLoader().loadClass(potentialClassName);
+ return (YangModuleInfo) moduleInfoClass.getMethod("getInstance").invoke(null);
+ }
+ });
+ }
+
+ public static String getModuleInfoClassName(String packageName) {
+ return packageName + "." + BindingMapping.MODULE_INFO_CLASS_NAME;
+ }
+
+ public static boolean isBindingClass(Class<?> cls) {
+ if (DataContainer.class.isAssignableFrom(cls) || Augmentation.class.isAssignableFrom(cls)) {
+ return true;
+ }
+ return (cls.getName().startsWith(BindingMapping.PACKAGE_PREFIX));
+ }
+
+ public static boolean isNotificationCallback(Method method) {
+ checkArgument(method != null);
+ if (method.getName().startsWith("on") && method.getParameterTypes().length == 1) {
+ Class<?> potentialNotification = method.getParameterTypes()[0];
+ if (isNotification(potentialNotification)
+ && method.getName().equals("on" + potentialNotification.getSimpleName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public static boolean isNotification(Class<?> potentialNotification) {
+ checkArgument(potentialNotification != null);
+ return Notification.class.isAssignableFrom(potentialNotification);
+ }
+
+ public static ImmutableSet<YangModuleInfo> loadModuleInfos() {
+ return loadModuleInfos(Thread.currentThread().getContextClassLoader());
+ }
+
+ public static ImmutableSet<YangModuleInfo> loadModuleInfos(ClassLoader loader) {
+ Builder<YangModuleInfo> moduleInfoSet = ImmutableSet.<YangModuleInfo>builder();
+ ServiceLoader<YangModelBindingProvider> serviceLoader = ServiceLoader.load(YangModelBindingProvider.class, loader);
+ for(YangModelBindingProvider bindingProvider : serviceLoader) {
+ collectYangModuleInfo(bindingProvider.getModuleInfo(),moduleInfoSet);
+ }
+ return moduleInfoSet.build();
+ }
+
+ private static void collectYangModuleInfo(YangModuleInfo moduleInfo, Builder<YangModuleInfo> moduleInfoSet) {
+ moduleInfoSet.add(moduleInfo);
+ for(YangModuleInfo dependency : moduleInfo.getImportedModules()) {
+ collectYangModuleInfo(dependency, moduleInfoSet);
+ }
+ }
+