mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Expose device type extension dao plugin via device type deployer
This commit is contained in:
parent
f1c6ee7068
commit
9d81ee6cb4
@ -34,6 +34,7 @@
|
||||
*/
|
||||
package org.wso2.carbon.device.mgt.extensions.device.type.template;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.w3c.dom.Document;
|
||||
@ -48,9 +49,11 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
|
||||
import org.wso2.carbon.device.mgt.extensions.spi.DeviceTypeManagerExtensionService;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DataSource;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeManagerExtensionConfig;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Table;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TableConfig;
|
||||
@ -213,6 +216,35 @@ public class DeviceTypeManager implements DeviceManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
setDeviceTypeManagerExtensionServices(deviceTypeConfiguration);
|
||||
}
|
||||
|
||||
private void setDeviceTypeManagerExtensionServices(DeviceTypeConfiguration deviceTypeConfiguration) {
|
||||
DeviceTypeManagerExtensionConfig deviceTypeExtensionConfig = deviceTypeConfiguration.getDeviceTypeExtensionConfig();
|
||||
if (deviceTypeExtensionConfig != null) {
|
||||
String extensionClass = deviceTypeExtensionConfig.getExtensionClass();
|
||||
if (StringUtils.isNotEmpty(extensionClass)) {
|
||||
try {
|
||||
Class<?> clz = Class.forName(extensionClass);
|
||||
DeviceTypeManagerExtensionService deviceTypeManagerExtensionService = (DeviceTypeManagerExtensionService) clz.newInstance();
|
||||
if (deviceTypePluginDAOManager != null) {
|
||||
deviceTypeManagerExtensionService.setDeviceTypePluginDAOManager(deviceTypePluginDAOManager);
|
||||
}
|
||||
} catch (ClassNotFoundException e) {
|
||||
String msg = "Extension class cannot be located";
|
||||
log.error(msg, e);
|
||||
throw new DeviceTypeDeployerPayloadException(msg, e);
|
||||
} catch (IllegalAccessException e) {
|
||||
String msg = "Cannot access the class or its constructor is not accessible.";
|
||||
log.error(msg, e);
|
||||
throw new DeviceTypeDeployerPayloadException(msg, e);
|
||||
} catch (InstantiationException e) {
|
||||
String msg = "Extension class instantiation is failed";
|
||||
log.error(msg, e);
|
||||
throw new DeviceTypeDeployerPayloadException(msg, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -105,6 +105,8 @@ public class DeviceTypeConfiguration {
|
||||
@XmlElementWrapper(name = "StartupOperationConfig")
|
||||
@XmlElement(name = "Operation", required = true)
|
||||
protected List<String> startupOperations;
|
||||
@XmlElement(name = "DeviceTypeManagerExtensionConfig")
|
||||
private DeviceTypeManagerExtensionConfig deviceTypeExtensionConfig;
|
||||
|
||||
public List<String> getOperations() {
|
||||
return operations;
|
||||
@ -402,4 +404,25 @@ public class DeviceTypeConfiguration {
|
||||
public void setStartupOperations(List<String> startupOperations) {
|
||||
this.startupOperations = startupOperations;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of DeviceTypeManagerExtensionConfig
|
||||
*
|
||||
* @return possible object is
|
||||
* {@link DeviceTypeManagerExtensionConfig}
|
||||
*/
|
||||
public DeviceTypeManagerExtensionConfig getDeviceTypeExtensionConfig() {
|
||||
return deviceTypeExtensionConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value for DeviceTypeManagerExtensionConfig
|
||||
*
|
||||
* @param deviceTypeExtensionConfig possible object is
|
||||
* {@link DeviceTypeManagerExtensionConfig}
|
||||
*/
|
||||
public void setDeviceTypeExtensionConfig(
|
||||
DeviceTypeManagerExtensionConfig deviceTypeExtensionConfig) {
|
||||
this.deviceTypeExtensionConfig = deviceTypeExtensionConfig;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,6 +2,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.template.dao;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeDeployerPayloadException;
|
||||
import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
|
||||
|
||||
@ -35,6 +36,19 @@ public class DeviceTypeDAOHandler {
|
||||
}
|
||||
}
|
||||
|
||||
public void openConnection() throws DeviceTypeMgtPluginException {
|
||||
try {
|
||||
Connection conn = currentConnection.get();
|
||||
if (conn != null) {
|
||||
throw new IllegalTransactionStateException("Database connection has already been obtained.");
|
||||
}
|
||||
conn = dataSource.getConnection();
|
||||
currentConnection.set(conn);
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceTypeMgtPluginException("Failed to get a database connection.", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void beginTransaction() throws DeviceTypeMgtPluginException {
|
||||
try {
|
||||
Connection conn = dataSource.getConnection();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user