From 278240b02f81dfb74a1937c13336b8ee46e229f3 Mon Sep 17 00:00:00 2001 From: prabathabey Date: Mon, 8 Dec 2014 20:39:35 +0530 Subject: [PATCH] Bridging DeviceManagement core functionalities together with the persistence layer --- .../carbon/device/mgt/core/DeviceManager.java | 147 ++++++++++++++++++ .../carbon/device/mgt/core/dao/DeviceDAO.java | 2 +- .../core/dao/DeviceManagementDAOFactory.java | 2 +- .../mgt/core/dao/impl/DeviceDAOImpl.java | 1 - .../internal/DeviceManagementDataHolder.java | 11 +- .../DeviceManagementServiceComponent.java | 22 ++- .../core/service/DeviceManagementService.java | 50 ++---- ...obileDeviceManagementServiceComponent.java | 69 ++++++++ .../MobileDeviceMgtServiceComponent.java | 64 -------- 9 files changed, 250 insertions(+), 118 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementServiceComponent.java delete mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceMgtServiceComponent.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java new file mode 100644 index 000000000..b196bf802 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManager.java @@ -0,0 +1,147 @@ +/** + * Copyright (c) 2012, 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; + +import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.DeviceIdentifier; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; +import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; + +import java.util.List; + +public class DeviceManager implements DeviceManagerService { + + private DeviceDAO deviceDAO; + private DeviceTypeDAO deviceTypeDAO; + private DeviceManagementConfig config; + private DeviceManagementRepository pluginRepository; + + public DeviceManager(DeviceManagementConfig config, DeviceManagementRepository pluginRepository) { + this.config = config; + this.pluginRepository = pluginRepository; + this.deviceDAO = DeviceManagementDAOFactory.getDeviceDAO(); + this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO(); + } + + @Override + public String getProviderType() { + return null; + } + + @Override + public void enrollDevice(Device device) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(device.getType()); + dms.enrollDevice(device); + try { + this.getDeviceDAO().addDevice(device); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while enrolling the device '" + + device.getId() + "'", e); + } + } + + @Override + public void modifyEnrollment(Device device) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(device.getType()); + dms.modifyEnrollment(device); + try { + this.getDeviceDAO().updateDevice(device); + } catch (DeviceManagementDAOException e) { + throw new DeviceManagementException("Error occurred while modifying the device '" + + device.getId() + "'", e); + } + } + + @Override + public void disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + dms.disenrollDevice(deviceId); + } + + @Override + public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.isRegistered(deviceId); + } + + @Override + public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.isActive(deviceId); + } + + @Override + public void setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + dms.setActive(deviceId, status); + } + + @Override + public List getAllDevices(String type) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(type); + return dms.getAllDevices(type); + } + + @Override + public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + return dms.getDevice(deviceId); + } + + @Override + public void updateDeviceInfo(Device device) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(device.getType()); + dms.updateDeviceInfo(device); + } + + @Override + public void setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { + DeviceManagerService dms = + this.getPluginRepository().getDeviceManagementProvider(deviceId.getType()); + dms.setOwnership(deviceId, ownershipType); + } + + public DeviceDAO getDeviceDAO() { + return deviceDAO; + } + + public DeviceTypeDAO getDeviceTypeDAO() { + return deviceTypeDAO; + } + + public DeviceManagementConfig getDeviceManagementConfig() { + return config; + } + + public DeviceManagementRepository getPluginRepository() { + return pluginRepository; + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java index 5bf4335db..6c17a7d7c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceDAO.java @@ -15,7 +15,7 @@ package org.wso2.carbon.device.mgt.core.dao; -import org.wso2.carbon.device.mgt.core.dto.Device; +import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.core.dto.Status; import java.util.List; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java index 9788bbf12..90255603c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java @@ -50,7 +50,7 @@ public class DeviceManagementDAOFactory { * @param config data source configuration * @return data source resolved from the data source definition */ - public static DataSource resolveDataSource(DataSourceConfig config) { + private static DataSource resolveDataSource(DataSourceConfig config) { DataSource dataSource = null; if (config == null) { throw new RuntimeException("Device Management Repository data source configuration " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java index 950d46cbc..ece6a3ea9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/DeviceDAOImpl.java @@ -38,7 +38,6 @@ public class DeviceDAOImpl implements DeviceDAO { private DataSource dataSource; private static final Log log = LogFactory.getLog(DeviceDAOImpl.class); - public DeviceDAOImpl(DataSource dataSource) { this.dataSource = dataSource; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java index 999a69c23..d368a6af9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.internal; import org.wso2.carbon.device.mgt.core.DeviceManagementRepository; +import org.wso2.carbon.device.mgt.core.DeviceManager; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.user.core.tenant.TenantManager; @@ -27,7 +28,7 @@ public class DeviceManagementDataHolder { private RealmService realmService; private TenantManager tenantManager; - private DeviceManagementRepository repository; + private DeviceManager deviceManager; private static DeviceManagementDataHolder thisInstance = new DeviceManagementDataHolder(); private DeviceManagementDataHolder() {} @@ -56,12 +57,12 @@ public class DeviceManagementDataHolder { return tenantManager; } - public DeviceManagementRepository getDeviceManagementRepository() { - return repository; + public DeviceManager getDeviceManager() { + return deviceManager; } - public void setDeviceManagementRepository(DeviceManagementRepository repository) { - this.repository = repository; + public void setDeviceManager(DeviceManager deviceManager) { + this.deviceManager = deviceManager; } } 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 2fc8e407d..9fa547c87 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 @@ -22,7 +22,9 @@ 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.DeviceManagementRepository; +import org.wso2.carbon.device.mgt.core.DeviceManager; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.service.DeviceManagementService; @@ -47,15 +49,20 @@ import org.wso2.carbon.user.core.service.RealmService; public class DeviceManagementServiceComponent { private static Log log = LogFactory.getLog(DeviceManagementServiceComponent.class); + private DeviceManagementRepository pluginRepository = new DeviceManagementRepository(); protected void activate(ComponentContext componentContext) { try { /* Initializing Device Management Configuration */ DeviceConfigurationManager.getInstance().initConfig(); - DeviceManagementDataHolder.getInstance().setDeviceManagementRepository(new DeviceManagementRepository()); - DataSourceConfig config = DeviceConfigurationManager.getInstance().getDataSourceConfig(); - DeviceManagementDAOFactory.init(config); + DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); + + DeviceManager deviceManager = new DeviceManager(config, this.getPluginRepository()); + DeviceManagementDataHolder.getInstance().setDeviceManager(deviceManager); + + DataSourceConfig dsConfig = config.getDeviceMgtRepository().getDataSourceConfig(); + DeviceManagementDAOFactory.init(dsConfig); /* If -Dsetup option enabled then create device management database schema */ String setupOption = System.getProperty("setup"); @@ -64,7 +71,7 @@ public class DeviceManagementServiceComponent { log.debug("-Dsetup is enabled. Device management repository schema initialization is about " + "to begin"); } - setupDeviceManagementSchema(config); + setupDeviceManagementSchema(dsConfig); } BundleContext bundleContext = componentContext.getBundleContext(); @@ -96,8 +103,7 @@ public class DeviceManagementServiceComponent { if (log.isDebugEnabled()) { log.debug("Setting Device Management Service"); } - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - addDeviceManagementProvider(deviceManager); + this.getPluginRepository().addDeviceManagementProvider(deviceManager); } /** @@ -132,4 +138,8 @@ public class DeviceManagementServiceComponent { DeviceManagementDataHolder.getInstance().setRealmService(null); } + private DeviceManagementRepository getPluginRepository() { + return pluginRepository; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java index 523d798a5..5ec213a33 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementService.java @@ -32,82 +32,52 @@ public class DeviceManagementService implements DeviceManagerService { @Override public void enrollDevice(Device device) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(device.getType()); - dms.enrollDevice(device); + DeviceManagementDataHolder.getInstance().getDeviceManager().enrollDevice(device); } @Override public void modifyEnrollment(Device device) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(device.getType()); - dms.modifyEnrollment(device); + DeviceManagementDataHolder.getInstance().getDeviceManager().modifyEnrollment(device); } @Override public void disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(deviceId.getType()); - dms.disenrollDevice(deviceId); + DeviceManagementDataHolder.getInstance().getDeviceManager().disenrollDevice(deviceId); } @Override public boolean isRegistered(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(deviceId.getType()); - return dms.isRegistered(deviceId); + return DeviceManagementDataHolder.getInstance().getDeviceManager().isRegistered(deviceId); } @Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(deviceId.getType()); - return dms.isActive(deviceId); + return DeviceManagementDataHolder.getInstance().getDeviceManager().isActive(deviceId); } @Override public void setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(deviceId.getType()); - dms.setActive(deviceId, status); + DeviceManagementDataHolder.getInstance().getDeviceManager().setActive(deviceId, status); } @Override public List getAllDevices(String type) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(type); - return dms.getAllDevices(type); + return DeviceManagementDataHolder.getInstance().getDeviceManager().getAllDevices(type); } @Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(deviceId.getType()); - return dms.getDevice(deviceId); + return DeviceManagementDataHolder.getInstance().getDeviceManager().getDevice(deviceId); } @Override public void updateDeviceInfo(Device device) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(device.getType()); - dms.updateDeviceInfo(device); + DeviceManagementDataHolder.getInstance().getDeviceManager().updateDeviceInfo(device); } @Override public void setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException { - DeviceManagerService dms = - DeviceManagementDataHolder.getInstance().getDeviceManagementRepository(). - getDeviceManagementProvider(deviceId.getType()); - dms.setOwnership(deviceId, ownershipType); + DeviceManagementDataHolder.getInstance().getDeviceManager().setOwnership(deviceId, ownershipType); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementServiceComponent.java new file mode 100644 index 000000000..797821496 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceManagementServiceComponent.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2014, 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.mobile.impl.internal; + +import org.apache.commons.logging.LogFactory; +import org.apache.commons.logging.Log; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.ServiceRegistration; +import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; +import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService; +import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService; +import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService; + +public class MobileDeviceManagementServiceComponent implements BundleActivator { + + private static final Log log = LogFactory.getLog(MobileDeviceManagementServiceComponent.class); + private ServiceRegistration androidServiceRegRef; + private ServiceRegistration iOSServiceRegRef; + private ServiceRegistration windowsServiceRegRef; + + @Override + public void start(BundleContext bundleContext) throws Exception { + try { + if (log.isDebugEnabled()) { + log.debug("Activating Mobile Device Management Service bundle"); + } + androidServiceRegRef = + bundleContext.registerService(DeviceManagerService.class.getName(), + new AndroidDeviceManagerService(), null); + iOSServiceRegRef = + bundleContext.registerService(DeviceManagerService.class.getName(), + new IOSDeviceManagerService(), null); + windowsServiceRegRef = + bundleContext.registerService(DeviceManagerService.class.getName(), + new WindowsDeviceManagerService(), null); + if (log.isDebugEnabled()) { + log.debug("Mobile Device Management Service bundle is activated"); + } + } catch (Throwable e) { + log.error("Error occurred while activating Mobile Device Management Service Component", e); + } + } + + @Override + public void stop(BundleContext bundleContext) throws Exception { + if (log.isDebugEnabled()) { + log.debug("Deactivating Mobile Device Management Service"); + } + androidServiceRegRef.unregister(); + iOSServiceRegRef.unregister(); + windowsServiceRegRef.unregister(); + } + +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceMgtServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceMgtServiceComponent.java deleted file mode 100644 index af66453e6..000000000 --- a/components/device-mgt/org.wso2.carbon.device.mgt.mobile.impl/src/main/java/org/wso2/carbon/device/mgt/mobile/impl/internal/MobileDeviceMgtServiceComponent.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2014, 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.mobile.impl.internal; - -import org.apache.commons.logging.LogFactory; -import org.apache.commons.logging.Log; -import org.osgi.framework.ServiceRegistration; -import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService; -import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService; - -/** - * @scr.component name="org.wso2.carbon.device.manager.mobile" immediate="true" - */ -public class MobileDeviceMgtServiceComponent { - - private static final Log log = LogFactory.getLog(MobileDeviceMgtServiceComponent.class); - ServiceRegistration serviceRegistration; - - protected void activate(ComponentContext ctx) { - try { - if (log.isDebugEnabled()) { - log.debug("Activating Mobile Device Management Service"); - } - AndroidDeviceManagerService androidDeviceMgrService = new AndroidDeviceManagerService(); - IOSDeviceManagerService iOSDeviceMgrService = new IOSDeviceManagerService(); - WindowsDeviceManagerService windowsDeviceMgrService = new WindowsDeviceManagerService(); - serviceRegistration = - ctx.getBundleContext().registerService(DeviceManagerService.class.getName(), - androidDeviceMgrService, null); - serviceRegistration = - ctx.getBundleContext().registerService(DeviceManagerService.class.getName(), - iOSDeviceMgrService, null); - serviceRegistration = - ctx.getBundleContext().registerService(DeviceManagerService.class.getName(), - windowsDeviceMgrService, null); - } catch (Throwable e) { - log.error("Unable to activate Mobile Device Management Service Component", e); - } - } - - protected void deactivate(ComponentContext ctx) { - if (log.isDebugEnabled()) { - log.debug("Deactivating Mobile Device Management Service"); - } - serviceRegistration.unregister(); - } -}