code: public static BundleContext getBundleContext(Class<?> clazz) {
          BundleContext context = null; //we'll return null if not running inside an OSGi framework (e.g. unit test)
          if (FrameworkState.isValid()) {
              Bundle bundle = FrameworkUtil.getBundle(clazz);
  
              if (bundle != null) {
                  context = bundle.getBundleContext();
              }
          }
          return context;
      }
docs: Get the OSGi bundle context for the given class
  
  @param clazz the class to find the context for
  @return the bundle context