aboutsummaryrefslogtreecommitdiffstats
path: root/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java
diff options
context:
space:
mode:
Diffstat (limited to 'sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java')
-rw-r--r--sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java41
1 files changed, 41 insertions, 0 deletions
diff --git a/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java
new file mode 100644
index 00000000..d2b733fc
--- /dev/null
+++ b/sli/provider/src/main/java/org/onap/ccsdk/sli/core/sli/provider/SvcLogicClassResolver.java
@@ -0,0 +1,41 @@
+package org.onap.ccsdk.sli.core.sli.provider;
+
+import org.osgi.framework.Bundle;
+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 SvcLogicClassResolver {
+ private static final Logger LOG = LoggerFactory.getLogger(SvcLogicClassResolver.class);
+
+ public static Object resolve(String className) {
+
+ Bundle bundle = FrameworkUtil.getBundle(SvcLogicClassResolver.class);
+
+ if (bundle == null) {
+ // Running outside OSGi container (e.g. jUnit). Use Reflection
+ // to resolve class
+ try {
+ return(Class.forName(className).newInstance());
+ } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
+
+ LOG.error("Could not resolve class "+className, e);
+ return null;
+ }
+
+ } else {
+ BundleContext bctx = bundle.getBundleContext();
+ ServiceReference sref = bctx.getServiceReference(className);
+ if (sref != null) {
+ return bctx.getService(sref);
+ } else {
+
+ LOG.warn("Could not find service reference object for class " + className);
+ return null;
+ }
+ }
+ }
+
+}