|
|
@ -40,129 +40,136 @@ import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerServic
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* BundleActivator of MobileDeviceManagement component.
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener {
|
|
|
|
public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener {
|
|
|
|
|
|
|
|
|
|
|
|
private ServiceRegistration androidServiceRegRef;
|
|
|
|
private ServiceRegistration androidServiceRegRef;
|
|
|
|
private ServiceRegistration iOSServiceRegRef;
|
|
|
|
private ServiceRegistration iOSServiceRegRef;
|
|
|
|
private ServiceRegistration windowsServiceRegRef;
|
|
|
|
private ServiceRegistration windowsServiceRegRef;
|
|
|
|
|
|
|
|
|
|
|
|
private static List<DataSourceListener> dataSourceListeners = new ArrayList<DataSourceListener>();
|
|
|
|
private static List<DataSourceListener> dataSourceListeners =
|
|
|
|
|
|
|
|
new ArrayList<DataSourceListener>();
|
|
|
|
|
|
|
|
|
|
|
|
private static final String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT = "org.wso2.carbon.ndatasource.core";
|
|
|
|
private static final String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT =
|
|
|
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
|
|
|
|
"org.wso2.carbon.ndatasource.core";
|
|
|
|
|
|
|
|
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void start(BundleContext bundleContext) throws Exception {
|
|
|
|
public void start(BundleContext bundleContext) throws Exception {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Activating Mobile Device Management Service bundle");
|
|
|
|
log.debug("Activating Mobile Device Management Service bundle");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bundleContext.addBundleListener(this);
|
|
|
|
bundleContext.addBundleListener(this);
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize the datasource configuration */
|
|
|
|
/* Initialize the datasource configuration */
|
|
|
|
MobileDeviceConfigurationManager.getInstance().initConfig();
|
|
|
|
MobileDeviceConfigurationManager.getInstance().initConfig();
|
|
|
|
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
|
|
|
|
MobileDeviceManagementConfig config = MobileDeviceConfigurationManager.getInstance()
|
|
|
|
.getMobileDeviceManagementConfig();
|
|
|
|
.getMobileDeviceManagementConfig();
|
|
|
|
MobileDataSourceConfig dsConfig =
|
|
|
|
MobileDataSourceConfig dsConfig =
|
|
|
|
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
|
|
|
|
config.getMobileDeviceMgtRepository().getMobileDataSourceConfig();
|
|
|
|
|
|
|
|
|
|
|
|
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
|
|
|
|
MobileDeviceManagementDAOFactory.setMobileDataSourceConfig(dsConfig);
|
|
|
|
|
|
|
|
|
|
|
|
androidServiceRegRef =
|
|
|
|
androidServiceRegRef =
|
|
|
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
|
|
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
|
|
|
new AndroidDeviceManagerService(), null);
|
|
|
|
new AndroidDeviceManagerService(), null);
|
|
|
|
iOSServiceRegRef =
|
|
|
|
iOSServiceRegRef =
|
|
|
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
|
|
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
|
|
|
new IOSDeviceManagerService(), null);
|
|
|
|
new IOSDeviceManagerService(), null);
|
|
|
|
windowsServiceRegRef =
|
|
|
|
windowsServiceRegRef =
|
|
|
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
|
|
|
bundleContext.registerService(DeviceManagerService.class.getName(),
|
|
|
|
new WindowsDeviceManagerService(), null);
|
|
|
|
new WindowsDeviceManagerService(), null);
|
|
|
|
|
|
|
|
|
|
|
|
/* Initialize all API configurations with corresponding API Providers */
|
|
|
|
/* Initialize all API configurations with corresponding API Providers */
|
|
|
|
this.initAPIConfigs();
|
|
|
|
this.initAPIConfigs();
|
|
|
|
/* Publish all mobile device management related JAX-RS services as APIs */
|
|
|
|
/* Publish all mobile device management related JAX-RS services as APIs */
|
|
|
|
this.publishAPIs();
|
|
|
|
this.publishAPIs();
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Mobile Device Management Service bundle is activated");
|
|
|
|
log.debug("Mobile Device Management Service bundle is activated");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (Throwable e) {
|
|
|
|
} catch (Throwable e) {
|
|
|
|
log.error("Error occurred while activating Mobile Device Management bundle", e);
|
|
|
|
log.error("Error occurred while activating Mobile Device Management bundle", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void stop(BundleContext bundleContext) throws Exception {
|
|
|
|
public void stop(BundleContext bundleContext) throws Exception {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Deactivating Mobile Device Management Service");
|
|
|
|
log.debug("Deactivating Mobile Device Management Service");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
androidServiceRegRef.unregister();
|
|
|
|
androidServiceRegRef.unregister();
|
|
|
|
iOSServiceRegRef.unregister();
|
|
|
|
iOSServiceRegRef.unregister();
|
|
|
|
windowsServiceRegRef.unregister();
|
|
|
|
windowsServiceRegRef.unregister();
|
|
|
|
|
|
|
|
|
|
|
|
bundleContext.removeBundleListener(this);
|
|
|
|
bundleContext.removeBundleListener(this);
|
|
|
|
|
|
|
|
|
|
|
|
/* Removing all APIs published upon start-up for mobile device management related JAX-RS
|
|
|
|
/* Removing all APIs published upon start-up for mobile device management related JAX-RS
|
|
|
|
services */
|
|
|
|
services */
|
|
|
|
this.removeAPIs();
|
|
|
|
this.removeAPIs();
|
|
|
|
} catch (Throwable e) {
|
|
|
|
} catch (Throwable e) {
|
|
|
|
log.error("Error occurred while de-activating Mobile Device Management bundle", e);
|
|
|
|
log.error("Error occurred while de-activating Mobile Device Management bundle", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void bundleChanged(BundleEvent bundleEvent) {
|
|
|
|
public void bundleChanged(BundleEvent bundleEvent) {
|
|
|
|
int eventType = bundleEvent.getType();
|
|
|
|
int eventType = bundleEvent.getType();
|
|
|
|
String bundleSymbolicName = bundleEvent.getBundle().getSymbolicName();
|
|
|
|
String bundleSymbolicName = bundleEvent.getBundle().getSymbolicName();
|
|
|
|
|
|
|
|
|
|
|
|
if (SYMBOLIC_NAME_DATA_SOURCE_COMPONENT.equals(bundleSymbolicName) &&
|
|
|
|
if (SYMBOLIC_NAME_DATA_SOURCE_COMPONENT.equals(bundleSymbolicName) &&
|
|
|
|
eventType == BundleEvent.STARTED) {
|
|
|
|
eventType == BundleEvent.STARTED) {
|
|
|
|
for (DataSourceListener listener : this.getDataSourceListeners()) {
|
|
|
|
for (DataSourceListener listener : this.getDataSourceListeners()) {
|
|
|
|
listener.notifyObserver();
|
|
|
|
listener.notifyObserver();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void registerDataSourceListener(DataSourceListener listener) {
|
|
|
|
public static void registerDataSourceListener(DataSourceListener listener) {
|
|
|
|
dataSourceListeners.add(listener);
|
|
|
|
dataSourceListeners.add(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private List<DataSourceListener> getDataSourceListeners() {
|
|
|
|
private List<DataSourceListener> getDataSourceListeners() {
|
|
|
|
return dataSourceListeners;
|
|
|
|
return dataSourceListeners;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void initAPIConfigs() throws DeviceManagementException {
|
|
|
|
private void initAPIConfigs() throws DeviceManagementException {
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|
getApiPublisherConfig().getAPIs();
|
|
|
|
getApiPublisherConfig().getAPIs();
|
|
|
|
for (APIConfig apiConfig : apiConfigs) {
|
|
|
|
for (APIConfig apiConfig : apiConfigs) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
APIProvider provider = APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
|
|
|
|
APIProvider provider =
|
|
|
|
apiConfig.init(provider);
|
|
|
|
APIManagerFactory.getInstance().getAPIProvider(apiConfig.getOwner());
|
|
|
|
} catch (APIManagementException e) {
|
|
|
|
apiConfig.init(provider);
|
|
|
|
throw new DeviceManagementException("Error occurred while initializing API Config '" +
|
|
|
|
} catch (APIManagementException e) {
|
|
|
|
apiConfig.getName() + "'", e);
|
|
|
|
throw new DeviceManagementException(
|
|
|
|
}
|
|
|
|
"Error occurred while initializing API Config '" +
|
|
|
|
}
|
|
|
|
apiConfig.getName() + "'", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
private void publishAPIs() throws DeviceManagementException {
|
|
|
|
}
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|
private void publishAPIs() throws DeviceManagementException {
|
|
|
|
getApiPublisherConfig().getAPIs();
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
for (APIConfig apiConfig : apiConfigs) {
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
|
|
|
|
getApiPublisherConfig().getAPIs();
|
|
|
|
}
|
|
|
|
for (APIConfig apiConfig : apiConfigs) {
|
|
|
|
}
|
|
|
|
DeviceManagementAPIPublisherUtil.publishAPI(apiConfig);
|
|
|
|
|
|
|
|
}
|
|
|
|
private void removeAPIs() throws DeviceManagementException {
|
|
|
|
}
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|
private void removeAPIs() throws DeviceManagementException {
|
|
|
|
getApiPublisherConfig().getAPIs();
|
|
|
|
List<APIConfig> apiConfigs =
|
|
|
|
for (APIConfig apiConfig : apiConfigs) {
|
|
|
|
MobileDeviceConfigurationManager.getInstance().getMobileDeviceManagementConfig().
|
|
|
|
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
|
|
|
|
getApiPublisherConfig().getAPIs();
|
|
|
|
}
|
|
|
|
for (APIConfig apiConfig : apiConfigs) {
|
|
|
|
}
|
|
|
|
DeviceManagementAPIPublisherUtil.removeAPI(apiConfig);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|