private void registerServices(ComponentContext componentContext) {
    if (log.isDebugEnabled()) {
      log.debug("Registering OSGi service DeviceManagementProviderServiceImpl");
    }
    /* Registering Device Management Service */
    BundleContext bundleContext = componentContext.getBundleContext();
    DeviceManagementProviderService deviceManagementProvider =
        new DeviceManagementProviderServiceImpl();
    DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider);
    bundleContext.registerService(
        DeviceManagementProviderService.class.getName(), deviceManagementProvider, null);

    /* Registering Group Management Service */
    GroupManagementProviderService groupManagementProvider =
        new GroupManagementProviderServiceImpl();
    DeviceManagementDataHolder.getInstance()
        .setGroupManagementProviderService(groupManagementProvider);
    bundleContext.registerService(
        GroupManagementProviderService.class.getName(), groupManagementProvider, null);

    /* Registering Tenant Configuration Management Service */
    PlatformConfigurationManagementService tenantConfiguration =
        new PlatformConfigurationManagementServiceImpl();
    bundleContext.registerService(
        PlatformConfigurationManagementService.class.getName(), tenantConfiguration, null);

    /* Registering Notification Service */
    NotificationManagementService notificationManagementService =
        new NotificationManagementServiceImpl();
    bundleContext.registerService(
        NotificationManagementService.class.getName(), notificationManagementService, null);

    /* Registering Scope Management Service */
    ScopeManagementService scopeManagementService = new ScopeManagementServiceImpl();
    bundleContext.registerService(
        ScopeManagementService.class.getName(), scopeManagementService, null);

    /* Registering DeviceAccessAuthorization Service */
    DeviceAccessAuthorizationService deviceAccessAuthorizationService =
        new DeviceAccessAuthorizationServiceImpl();
    DeviceManagementDataHolder.getInstance()
        .setDeviceAccessAuthorizationService(deviceAccessAuthorizationService);
    bundleContext.registerService(
        DeviceAccessAuthorizationService.class.getName(), deviceAccessAuthorizationService, null);

    /* Registering App Management service */
    try {
      AppManagementConfigurationManager.getInstance().initConfig();
      AppManagementConfig appConfig =
          AppManagementConfigurationManager.getInstance().getAppManagementConfig();
      bundleContext.registerService(
          ApplicationManagementProviderService.class.getName(),
          new ApplicationManagerProviderServiceImpl(appConfig),
          null);
    } catch (ApplicationManagementException e) {
      log.error("Application management service not registered.", e);
    }
  }
 protected void unsetConfigurationContextService(
     ConfigurationContextService configurationContextService) {
   if (log.isDebugEnabled()) {
     log.debug("Un-setting ConfigurationContextService");
   }
   DeviceManagementDataHolder.getInstance().setConfigurationContextService(null);
 }
 protected void unsetEmailSenderService(EmailSenderService emailSenderService) {
   if (log.isDebugEnabled()) {
     log.debug("Un-setting Email Sender Service");
   }
   DeviceManagementDataHolder.getInstance().setEmailSenderService(null);
 }
 /**
  * Unsets Registry Service.
  *
  * @param registryService An instance of RegistryService
  */
 protected void unsetRegistryService(RegistryService registryService) {
   if (log.isDebugEnabled()) {
     log.debug("Un setting Registry Service");
   }
   DeviceManagementDataHolder.getInstance().setRegistryService(null);
 }
 /**
  * Sets Realm Service.
  *
  * @param realmService An instance of RealmService
  */
 protected void setRealmService(RealmService realmService) {
   if (log.isDebugEnabled()) {
     log.debug("Setting Realm Service");
   }
   DeviceManagementDataHolder.getInstance().setRealmService(realmService);
 }
 private void initOperationsManager() throws OperationManagementException {
   OperationManager operationManager = new OperationManagerImpl();
   DeviceManagementDataHolder.getInstance().setOperationManager(operationManager);
 }
  @SuppressWarnings("unused")
  protected void activate(ComponentContext componentContext) {
    try {
      if (log.isDebugEnabled()) {
        log.debug("Initializing device management core bundle");
      }
      /* Initializing Device Management Configuration */
      DeviceConfigurationManager.getInstance().initConfig();
      DeviceManagementConfig config =
          DeviceConfigurationManager.getInstance().getDeviceManagementConfig();

      DataSourceConfig dsConfig =
          config.getDeviceManagementConfigRepository().getDataSourceConfig();

      APIManagerConfiguration apiManagerConfiguration = new APIManagerConfiguration();
      apiManagerConfiguration.load(APIM_CONFIGURATION_PATH);
      DeviceManagementDataHolder.getInstance().setApiManagerConfiguration(apiManagerConfiguration);

      DeviceManagementDAOFactory.init(dsConfig);
      GroupManagementDAOFactory.init(dsConfig);
      NotificationManagementDAOFactory.init(dsConfig);
      OperationManagementDAOFactory.init(dsConfig);

      String apiManagerDataSource = apiManagerConfiguration.getFirstProperty(DATA_SOURCE_NAME);
      ScopeManagementDAOFactory.init(apiManagerDataSource);

      /* Initialize Operation Manager */
      this.initOperationsManager();

      PushNotificationProviderRepository pushNotificationRepo =
          new PushNotificationProviderRepository();
      List<String> pushNotificationProviders = config.getPushNotificationProviders();
      if (pushNotificationProviders != null) {
        for (String pushNoteProvider : pushNotificationProviders) {
          pushNotificationRepo.addProvider(pushNoteProvider);
        }
      }
      DeviceManagementDataHolder.getInstance()
          .setPushNotificationProviderRepository(pushNotificationRepo);

      /* If -Dsetup option enabled then create device management database schema */
      String setupOption = System.getProperty(DeviceManagementConstants.Common.SETUP_PROPERTY);
      if (setupOption != null) {
        if (log.isDebugEnabled()) {
          log.debug(
              "-Dsetup is enabled. Device management repository schema initialization is about to "
                  + "begin");
        }
        this.setupDeviceManagementSchema(dsConfig);
      }

      /* Registering declarative service instances exposed by DeviceManagementServiceComponent */
      this.registerServices(componentContext);

      /* This is a workaround to initialize all Device Management Service Providers after the initialization
       * of Device Management Service component in order to avoid bundle start up order related complications */
      notifyStartupListeners();
      if (log.isDebugEnabled()) {
        log.debug("Device management core bundle has been successfully initialized");
      }
    } catch (Throwable e) {
      log.error("Error occurred while initializing device management core bundle", e);
    }
  }