|
|
|
@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.util;
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
|
import org.w3c.dom.Document;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
|
|
|
|
|
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;
|
|
|
|
@ -31,8 +32,10 @@ import javax.sql.DataSource;
|
|
|
|
|
import javax.xml.parsers.DocumentBuilder;
|
|
|
|
|
import javax.xml.parsers.DocumentBuilderFactory;
|
|
|
|
|
import java.io.File;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Hashtable;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public final class DeviceManagerUtil {
|
|
|
|
|
|
|
|
|
@ -59,24 +62,22 @@ public final class DeviceManagerUtil {
|
|
|
|
|
public static DataSource resolveDataSource(DataSourceConfig config) {
|
|
|
|
|
DataSource dataSource = null;
|
|
|
|
|
if (config == null) {
|
|
|
|
|
throw new RuntimeException("Device Management Repository data source configuration " +
|
|
|
|
|
"is null and thus, is not initialized");
|
|
|
|
|
throw new RuntimeException(
|
|
|
|
|
"Device Management Repository data source configuration " + "is null and thus, is not initialized");
|
|
|
|
|
}
|
|
|
|
|
JNDILookupDefinition jndiConfig = config.getJndiLookupDefintion();
|
|
|
|
|
if (jndiConfig != null) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Initializing Device Management Repository data source using the JNDI " +
|
|
|
|
|
"Lookup Definition");
|
|
|
|
|
log.debug(
|
|
|
|
|
"Initializing Device Management Repository data source using the JNDI " + "Lookup Definition");
|
|
|
|
|
}
|
|
|
|
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList =
|
|
|
|
|
jndiConfig.getJndiProperties();
|
|
|
|
|
List<JNDILookupDefinition.JNDIProperty> jndiPropertyList = jndiConfig.getJndiProperties();
|
|
|
|
|
if (jndiPropertyList != null) {
|
|
|
|
|
Hashtable<Object, Object> jndiProperties = new Hashtable<Object, Object>();
|
|
|
|
|
for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) {
|
|
|
|
|
jndiProperties.put(prop.getName(), prop.getValue());
|
|
|
|
|
}
|
|
|
|
|
dataSource =
|
|
|
|
|
DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
|
|
|
|
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties);
|
|
|
|
|
} else {
|
|
|
|
|
dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null);
|
|
|
|
|
}
|
|
|
|
@ -130,4 +131,12 @@ public final class DeviceManagerUtil {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static Map<String, String> convertPropertiesToMap(List<Device.Property> properties) {
|
|
|
|
|
Map<String, String> propertiesMap = new HashMap<String, String>();
|
|
|
|
|
for (Device.Property prop : properties) {
|
|
|
|
|
propertiesMap.put(prop.getName(), prop.getValue());
|
|
|
|
|
}
|
|
|
|
|
return propertiesMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|