More code cleanups

revert-dabc3590
prabathabey 10 years ago
parent 5f242d6165
commit 29bfc6f09f

@ -0,0 +1,27 @@
/**
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wso2.carbon.device.mgt.core;
public final class DeviceManagementConstants {
public static final class Common {
private Common() {
throw new AssertionError();
}
public static final String PROPERTY_SETUP = "setup";
}
}

@ -23,6 +23,7 @@ import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext; import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; import org.wso2.carbon.device.mgt.core.DeviceManagementRepository;
import org.wso2.carbon.device.mgt.core.DeviceManager; import org.wso2.carbon.device.mgt.core.DeviceManager;
import org.wso2.carbon.device.mgt.core.DeviceManagerImpl; import org.wso2.carbon.device.mgt.core.DeviceManagerImpl;
@ -51,12 +52,14 @@ import org.wso2.carbon.user.core.service.RealmService;
*/ */
public class DeviceManagementServiceComponent { public class DeviceManagementServiceComponent {
public static final String SETUP_OPTION = "setup";
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
private DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); private DeviceManagementRepository pluginRepository = new DeviceManagementRepository();
protected void activate(ComponentContext componentContext) { protected void activate(ComponentContext componentContext) {
try { try {
if (log.isDebugEnabled()) {
log.debug("Initializing device management core bundle");
}
/* Initializing Device Management Configuration */ /* Initializing Device Management Configuration */
DeviceConfigurationManager.getInstance().initConfig(); DeviceConfigurationManager.getInstance().initConfig();
DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
@ -68,19 +71,24 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager); DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager);
/* If -Dsetup option enabled then create device management database schema */ /* If -Dsetup option enabled then create device management database schema */
String setupOption = System.getProperty(SETUP_OPTION); String setupOption = System.getProperty(DeviceManagementConstants.Common.PROPERTY_SETUP);
if (setupOption != null) { if (setupOption != null) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("-Dsetup is enabled. Device management repository schema initialization is about " + log.debug("-Dsetup is enabled. Device management repository schema initialization is about " +
"to begin"); "to begin");
} }
setupDeviceManagementSchema(dsConfig); this.setupDeviceManagementSchema(dsConfig);
} }
if (log.isDebugEnabled()) {
log.debug("Registering OSGi service DeviceManagementService");
}
BundleContext bundleContext = componentContext.getBundleContext(); BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(DeviceManagementService.class.getName(), bundleContext.registerService(DeviceManagementService.class.getName(),
new DeviceManagementService(), null); new DeviceManagementService(), null);
if (log.isDebugEnabled()) {
log.debug("Device management core bundle has been successfully initialized");
}
} catch (Throwable e) { } catch (Throwable e) {
String msg = "Error occurred while initializing device management core bundle"; String msg = "Error occurred while initializing device management core bundle";
log.error(msg, e); log.error(msg, e);
@ -91,38 +99,43 @@ public class DeviceManagementServiceComponent {
DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config); DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config);
log.info("Initializing device management repository database schema"); log.info("Initializing device management repository database schema");
// catch generic exception. If any error occurs wrap and throw DeviceManagementException
try { try {
initializer.createRegistryDatabase(); initializer.createRegistryDatabase();
} catch (Exception e) { } catch (Exception e) {
throw new DeviceManagementException("Error occurred while initializing Device Management " + throw new DeviceManagementException("Error occurred while initializing Device Management " +
"database schema", e); "database schema", e);
} }
if (log.isDebugEnabled()) {
log.debug("Device management metadata repository schema has been successfully initialized");
}
} }
/** /**
* Sets Device Manager services * Sets Device Manager service.
* @param deviceManager An instance of DeviceManagerService * @param deviceManagerService An instance of DeviceManagerService
*/ */
protected void setDeviceManagerService(DeviceManagerService deviceManager) { protected void setDeviceManagerService(DeviceManagerService deviceManagerService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Setting Device Management Service"); log.debug("Setting Device Management Service Provider : '" +
deviceManagerService.getProviderType() + "'");
} }
this.getPluginRepository().addDeviceManagementProvider(deviceManager); this.getPluginRepository().addDeviceManagementProvider(deviceManagerService);
} }
/** /**
* Unsets Device Management services * Unsets Device Management service.
* @param deviceManager An instance of DeviceManagerService * @param deviceManagerService An Instance of DeviceManagerService
*/ */
protected void unsetDeviceManagerService(DeviceManagerService deviceManager) { protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Unsetting Device Management Service"); log.debug("Unsetting Device Management Service Provider : '" +
deviceManagerService.getProviderType() + "'");
} }
this.getPluginRepository().removeDeviceManagementProvider(deviceManagerService);
} }
/** /**
* Sets Realm Service * Sets Realm Service.
* @param realmService An instance of RealmService * @param realmService An instance of RealmService
*/ */
protected void setRealmService(RealmService realmService) { protected void setRealmService(RealmService realmService) {
@ -133,7 +146,7 @@ public class DeviceManagementServiceComponent {
} }
/** /**
* Unsets Realm Service * Unsets Realm Service.
* @param realmService An instance of RealmService * @param realmService An instance of RealmService
*/ */
protected void unsetRealmService(RealmService realmService) { protected void unsetRealmService(RealmService realmService) {

@ -47,6 +47,7 @@ public class DeviceManagementRepositoryTests {
DeviceManagerService targetProvider = DeviceManagerService targetProvider =
this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST); this.getRepository().getDeviceManagementProvider(TestDeviceManagerService.DEVICE_TYPE_TEST);
Assert.assertNull(targetProvider); Assert.assertNull(targetProvider);
} }

Loading…
Cancel
Save