Merging changes of dulitha

Merge branch 'dulichan-master'
revert-70aa11f8
Geeth Munasinghe 10 years ago
commit b3caf026a9

@ -18,7 +18,6 @@ package org.wso2.carbon.device.mgt.common;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.List; import java.util.List;
import java.util.Map;
@XmlRootElement @XmlRootElement
public class Device { public class Device {
@ -35,7 +34,7 @@ public class Device {
private String deviceIdentifier; private String deviceIdentifier;
private String owner; private String owner;
private List<Feature> features; private List<Feature> features;
private Map<String, String> properties; private List<Device.Property> properties;
@XmlElement @XmlElement
public int getId() { public int getId() {
@ -146,12 +145,34 @@ public class Device {
} }
@XmlElement @XmlElement
public Map<String, String> getProperties() { public List<Device.Property> getProperties() {
return properties; return properties;
} }
public void setProperties(Map<String, String> properties) { public void setProperties(List<Device.Property> properties) {
this.properties = properties; this.properties = properties;
} }
public static class Property {
private String name;
private String value;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}
} }

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

Loading…
Cancel
Save