parent
fce61a59e2
commit
278240b02f
@ -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<Device> 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;
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue