Make neutron a simple osgi app
[controller.git] / opendaylight / networkconfiguration / neutron / northbound / src / main / java / org / opendaylight / controller / networkconfig / neutron / northbound / NeutronUtil.java
diff --git a/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronUtil.java b/opendaylight/networkconfiguration/neutron/northbound/src/main/java/org/opendaylight/controller/networkconfig/neutron/northbound/NeutronUtil.java
new file mode 100644 (file)
index 0000000..481d95a
--- /dev/null
@@ -0,0 +1,32 @@
+package org.opendaylight.controller.networkconfig.neutron.northbound;
+
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+import org.osgi.framework.ServiceReference;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NeutronUtil {
+    private static final Logger logger = LoggerFactory
+            .getLogger(NeutronUtil.class);
+    public static Object[] getInstances(Class<?> clazz,Object bundle) {
+        Object instances[] = null;
+        try {
+            BundleContext bCtx = FrameworkUtil.getBundle(bundle.getClass())
+                    .getBundleContext();
+
+            ServiceReference<?>[] services = null;
+                services = bCtx.getServiceReferences(clazz.getName(),
+                        null);
+            if (services != null) {
+                instances = new Object[services.length];
+                for (int i = 0; i < services.length; i++) {
+                    instances[i] = bCtx.getService(services[i]);
+                }
+            }
+        } catch (Exception e) {
+            logger.error("Instance reference is NULL");
+        }
+        return instances;
+    }
+}