1 package org.onap.ccsdk.sli.core.sli.provider;
3 import org.osgi.framework.Bundle;
4 import org.osgi.framework.BundleContext;
5 import org.osgi.framework.FrameworkUtil;
6 import org.osgi.framework.ServiceReference;
7 import org.slf4j.Logger;
8 import org.slf4j.LoggerFactory;
10 public class SvcLogicClassResolver {
11 private static final Logger LOG = LoggerFactory.getLogger(SvcLogicClassResolver.class);
13 public static Object resolve(String className) {
15 Bundle bundle = FrameworkUtil.getBundle(SvcLogicClassResolver.class);
18 // Running outside OSGi container (e.g. jUnit). Use Reflection
21 return(Class.forName(className).newInstance());
22 } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
24 LOG.error("Could not resolve class "+className, e);
29 BundleContext bctx = bundle.getBundleContext();
30 ServiceReference sref = bctx.getServiceReference(className);
32 return bctx.getService(sref);
35 LOG.warn("Could not find service reference object for class " + className);