mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
Fixing issues spotted as a result of the bundle getting activated before the datasources used underneath are registered in JNDI
This commit is contained in:
parent
fceccb3280
commit
a69fc9dc4c
@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 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;
|
||||
|
||||
public interface DataSourceListener {
|
||||
|
||||
void notifyObserver();
|
||||
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
/**
|
||||
* 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.dao;
|
||||
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.DataSourceListener;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceModelImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileDeviceVendorDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.impl.MobileOSVersionDAOImpl;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.util.MobileDeviceManagementDAOUtil;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.internal.MobileDeviceManagementBundleActivator;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
public class MobileDeviceDAOFactory implements DataSourceListener {
|
||||
|
||||
private DataSource dataSource;
|
||||
|
||||
public MobileDeviceDAOFactory() {
|
||||
MobileDeviceManagementBundleActivator.registerDataSourceListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyObserver() {
|
||||
this.dataSource = MobileDeviceManagementDAOUtil.resolveDataSource();
|
||||
}
|
||||
|
||||
private DataSource getDataSource() {
|
||||
return dataSource;
|
||||
}
|
||||
|
||||
public static MobileDeviceDAO getMobileDeviceDAO() {
|
||||
return new MobileDeviceDAOImpl();
|
||||
}
|
||||
|
||||
public static MobileDeviceModelDAO getMobileDeviceModelDAO() {
|
||||
return new MobileDeviceModelImpl();
|
||||
}
|
||||
|
||||
public static MobileDeviceVendorDAO getMobileDeviceVendorDAO() {
|
||||
return new MobileDeviceVendorDAOImpl();
|
||||
}
|
||||
|
||||
public static MobileOSVersionDAO getMobileOSVersionDAO() {
|
||||
return new MobileOSVersionDAOImpl();
|
||||
}
|
||||
|
||||
}
|
||||
@ -16,8 +16,15 @@
|
||||
|
||||
package org.wso2.carbon.device.mgt.mobile.impl.dao.util;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
/**
|
||||
* Utility method required by MobileDeviceManagement DAO classes.
|
||||
*/
|
||||
public class MobileDeviceManagementDAOUtil {
|
||||
|
||||
public static DataSource resolveDataSource() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -18,20 +18,26 @@ 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.osgi.framework.*;
|
||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.DataSourceListener;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.android.AndroidDeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.dao.MobileDeviceDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.ios.IOSDeviceManagerService;
|
||||
import org.wso2.carbon.device.mgt.mobile.impl.windows.WindowsDeviceManagerService;
|
||||
|
||||
public class MobileDeviceManagementBundleActivator implements BundleActivator {
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
|
||||
private ServiceRegistration androidServiceRegRef;
|
||||
private ServiceRegistration iOSServiceRegRef;
|
||||
private ServiceRegistration windowsServiceRegRef;
|
||||
public class MobileDeviceManagementBundleActivator implements BundleActivator, BundleListener {
|
||||
|
||||
private ServiceRegistration androidServiceRegRef;
|
||||
private ServiceRegistration iOSServiceRegRef;
|
||||
private ServiceRegistration windowsServiceRegRef;
|
||||
private static List<DataSourceListener> dataSourceListeners = new ArrayList<DataSourceListener>();
|
||||
|
||||
private static final Log log = LogFactory.getLog(MobileDeviceManagementBundleActivator.class);
|
||||
private static final String SYMBOLIC_NAME_DATA_SOURCE_COMPONENT = "org.wso2.carbon.ndatasource.core";
|
||||
|
||||
@Override
|
||||
public void start(BundleContext bundleContext) throws Exception {
|
||||
@ -39,6 +45,11 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Activating Mobile Device Management Service bundle");
|
||||
}
|
||||
bundleContext.addBundleListener(this);
|
||||
|
||||
MobileDeviceDAOFactory daoFactory = new MobileDeviceDAOFactory();
|
||||
//TODO Register this dao to an appropriate config file
|
||||
|
||||
androidServiceRegRef =
|
||||
bundleContext.registerService(DeviceManagerService.class.getName(),
|
||||
new AndroidDeviceManagerService(), null);
|
||||
@ -64,6 +75,27 @@ public class MobileDeviceManagementBundleActivator implements BundleActivator {
|
||||
androidServiceRegRef.unregister();
|
||||
iOSServiceRegRef.unregister();
|
||||
windowsServiceRegRef.unregister();
|
||||
|
||||
bundleContext.removeBundleListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bundleChanged(BundleEvent bundleEvent) {
|
||||
int eventType = bundleEvent.getType();
|
||||
String bundleSymbolicName = bundleEvent.getBundle().getSymbolicName();
|
||||
if (SYMBOLIC_NAME_DATA_SOURCE_COMPONENT.equals(bundleSymbolicName) && eventType == BundleEvent.STARTED) {
|
||||
for (DataSourceListener listener : this.getDataSourceListeners()) {
|
||||
listener.notifyObserver();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void registerDataSourceListener(DataSourceListener listener) {
|
||||
dataSourceListeners.add(listener);
|
||||
}
|
||||
|
||||
private List<DataSourceListener> getDataSourceListeners() {
|
||||
return dataSourceListeners;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user