From 1f587bddf822e742e536394733762b6a9e518364 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Fri, 27 Mar 2015 17:59:12 +0530 Subject: [PATCH] Code cleanup --- .../DeviceManagementServiceComponent.java | 44 ++++++++++++------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 3fe93d1fb4a..d26d4b332fb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -34,6 +34,7 @@ import org.wso2.carbon.device.mgt.core.DeviceManagementServiceProviderImpl; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherService; import org.wso2.carbon.device.mgt.core.api.mgt.APIPublisherServiceImpl; import org.wso2.carbon.device.mgt.core.api.mgt.APIRegistrationStartupObserver; +import org.wso2.carbon.device.mgt.core.app.mgt.AppManagementException; import org.wso2.carbon.device.mgt.core.app.mgt.AppManagerImplHttp; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; @@ -117,20 +118,10 @@ public class DeviceManagementServiceComponent { new DeviceManagementServiceProviderImpl(this.getPluginRepository()); DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProvider); - LicenseConfigurationManager.getInstance().initConfig(); - LicenseConfig licenseConfig = - LicenseConfigurationManager.getInstance().getLicenseConfig(); - - LicenseManager licenseManager = new LicenseManagerImpl(); - DeviceManagementDataHolder.getInstance().setLicenseManager(licenseManager); - DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig); - - AppManagementConfigurationManager.getInstance().initConfig(); - AppManagementConfig appConfig = - AppManagementConfigurationManager.getInstance().getAppManagementConfig(); - DeviceManagementDataHolder.getInstance().setAppManagerConfig(appConfig); - AppManagerImplHttp appManager = new AppManagerImplHttp(appConfig); - DeviceManagementDataHolder.getInstance().setAppManager(appManager); + /* Initializing license manager */ + this.initLicenseManager(); + /* Initializing app manager connector */ + this.initAppManagerConnector(); OperationManagementDAOFactory.init(dsConfig); @@ -143,7 +134,7 @@ public class DeviceManagementServiceComponent { "begin"); } this.setupDeviceManagementSchema(dsConfig); - this.setupDefaultLicenses(licenseConfig); + this.setupDefaultLicenses(DeviceManagementDataHolder.getInstance().getLicenseConfig()); } synchronized (LOCK) { @@ -164,6 +155,25 @@ public class DeviceManagementServiceComponent { } } + private void initLicenseManager() throws LicenseManagementException { + LicenseConfigurationManager.getInstance().initConfig(); + LicenseConfig licenseConfig = + LicenseConfigurationManager.getInstance().getLicenseConfig(); + + LicenseManager licenseManager = new LicenseManagerImpl(); + DeviceManagementDataHolder.getInstance().setLicenseManager(licenseManager); + DeviceManagementDataHolder.getInstance().setLicenseConfig(licenseConfig); + } + + private void initAppManagerConnector() throws AppManagementException { + AppManagementConfigurationManager.getInstance().initConfig(); + AppManagementConfig appConfig = + AppManagementConfigurationManager.getInstance().getAppManagementConfig(); + DeviceManagementDataHolder.getInstance().setAppManagerConfig(appConfig); + AppManagerImplHttp appManager = new AppManagerImplHttp(appConfig); + DeviceManagementDataHolder.getInstance().setAppManager(appManager); + } + protected void deactivate(ComponentContext componentContext) { //do nothing } @@ -197,8 +207,7 @@ public class DeviceManagementServiceComponent { initializer.createRegistryDatabase(); } catch (Exception e) { throw new DeviceManagementException( - "Error occurred while initializing Device Management " + - "database schema", e); + "Error occurred while initializing Device Management database schema", e); } if (log.isDebugEnabled()) { log.debug("Device management metadata repository schema has been successfully initialized"); @@ -330,4 +339,5 @@ public class DeviceManagementServiceComponent { protected void unsetDataSourceService(DataSourceService dataSourceService) { //do nothing } + }