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.wso2.carbon.device.mgt.common.DeviceManagementException;
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.DeviceManager;
import org.wso2.carbon.device.mgt.core.DeviceManagerImpl;
@ -51,12 +52,14 @@ import org.wso2.carbon.user.core.service.RealmService;
*/
public class DeviceManagementServiceComponent {
public static final String SETUP_OPTION = "setup";
private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class);
private DeviceManagementRepository pluginRepository = new DeviceManagementRepository();
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();
@ -68,19 +71,24 @@ public class DeviceManagementServiceComponent {
DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager);
/* 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 (log.isDebugEnabled()) {
log.debug("-Dsetup is enabled. Device management repository schema initialization is about " +
"to begin");
}
setupDeviceManagementSchema(dsConfig);
this.setupDeviceManagementSchema(dsConfig);
}
if (log.isDebugEnabled()) {
log.debug("Registering OSGi service DeviceManagementService");
}
BundleContext bundleContext = componentContext.getBundleContext();
bundleContext.registerService(DeviceManagementService.class.getName(),
new DeviceManagementService(), null);
if (log.isDebugEnabled()) {
log.debug("Device management core bundle has been successfully initialized");
}
} catch (Throwable e) {
String msg = "Error occurred while initializing device management core bundle";
log.error(msg, e);
@ -91,38 +99,43 @@ public class DeviceManagementServiceComponent {
DeviceManagementSchemaInitializer initializer = new DeviceManagementSchemaInitializer(config);
log.info("Initializing device management repository database schema");
// catch generic exception. If any error occurs wrap and throw DeviceManagementException
try {
initializer.createRegistryDatabase();
} catch (Exception e) {
throw new DeviceManagementException("Error occurred while initializing Device Management " +
"database schema", e);
}
if (log.isDebugEnabled()) {
log.debug("Device management metadata repository schema has been successfully initialized");
}
}
/**
* Sets Device Manager services
* @param deviceManager An instance of DeviceManagerService
* Sets Device Manager service.
* @param deviceManagerService An instance of DeviceManagerService
*/
protected void setDeviceManagerService(DeviceManagerService deviceManager) {
protected void setDeviceManagerService(DeviceManagerService deviceManagerService) {
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
* @param deviceManager An instance of DeviceManagerService
* Unsets Device Management service.
* @param deviceManagerService An Instance of DeviceManagerService
*/
protected void unsetDeviceManagerService(DeviceManagerService deviceManager) {
protected void unsetDeviceManagerService(DeviceManagerService deviceManagerService) {
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
*/
protected void setRealmService(RealmService realmService) {
@ -133,7 +146,7 @@ public class DeviceManagementServiceComponent {
}
/**
* Unsets Realm Service
* Unsets Realm Service.
* @param realmService An instance of RealmService
*/
protected void unsetRealmService(RealmService realmService) {

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

Loading…
Cancel
Save