value info is no longer needed
This commit is contained in:
parent
4ca7f99941
commit
b2f263e5ed
@ -70,52 +70,6 @@ public class XMLHandler implements IXML {
|
|||||||
return returnList;
|
return returnList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* reads the value info from the XML file.
|
|
||||||
* @param deviceName the name of the relevant device
|
|
||||||
* @return the value info as a dictionary {'unit','type','Offset','Factor'}
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Dictionary<String, Object> getValueInfo(final String deviceName) {
|
|
||||||
Dictionary<String, Object> returnDictionary = new Hashtable<>();
|
|
||||||
XPathFactory xPathFactory = XPathFactory.newInstance();
|
|
||||||
XPath xPath = xPathFactory.newXPath();
|
|
||||||
try {
|
|
||||||
XPathExpression xPathExpression = xPath.compile(
|
|
||||||
"//Device[@name='" + deviceName + "']/ValueInfo");
|
|
||||||
Element result = (Element) xPathExpression.evaluate(
|
|
||||||
root, XPathConstants.NODE);
|
|
||||||
returnDictionary.put("type", result.getAttribute("type"));
|
|
||||||
returnDictionary.put("unit", result.getAttribute("unit"));
|
|
||||||
NodeList childNodes = result.getChildNodes();
|
|
||||||
float offset = 0.0f;
|
|
||||||
float factor = 1.0f;
|
|
||||||
for (int i = 0; i < childNodes.getLength(); i++) {
|
|
||||||
switch (childNodes.item(i).getNodeName()) {
|
|
||||||
case "Offset":
|
|
||||||
offset = Float.parseFloat(childNodes.item(i)
|
|
||||||
.getTextContent());
|
|
||||||
break;
|
|
||||||
case "Factor":
|
|
||||||
factor = Float.parseFloat(childNodes.item(i)
|
|
||||||
.getTextContent());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
returnDictionary.put("offset", offset);
|
|
||||||
returnDictionary.put("factor", factor);
|
|
||||||
} catch (XPathExpressionException e) {
|
|
||||||
Log.e(
|
|
||||||
"XMLHandler",
|
|
||||||
"the XPath for getting the value info has errors:"
|
|
||||||
+ e.getMessage()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return returnDictionary;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* reads the port information from the XML file.
|
* reads the port information from the XML file.
|
||||||
* @param deviceName the name of the relevant device
|
* @param deviceName the name of the relevant device
|
||||||
|
@ -43,30 +43,6 @@ public class XMLHandlerUnitTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestInput_SimpleValueInfo(){
|
|
||||||
try{
|
|
||||||
XMLHandler xmlHandler = new XMLHandler(xmlFile);
|
|
||||||
Dictionary<String, Object> valueInfo = xmlHandler.getValueInfo("example");
|
|
||||||
assertEquals("{factor=1.0, type=boolean, unit=, offset=0.0}",valueInfo.toString());
|
|
||||||
}catch(IOException | ParserConfigurationException | SAXException e){
|
|
||||||
System.out.println("XMLHandler failed");
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void TestInput_ComplexValueInfo(){
|
|
||||||
try{
|
|
||||||
XMLHandler xmlHandler = new XMLHandler(xmlFile);
|
|
||||||
Dictionary<String, Object> valueInfo = xmlHandler.getValueInfo("sensorarray");
|
|
||||||
assertEquals("{factor=2.5, type=int, unit=°C, offset=1.2}",valueInfo.toString());
|
|
||||||
}catch(IOException | ParserConfigurationException | SAXException e){
|
|
||||||
System.out.println("XMLHandler failed");
|
|
||||||
assert(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void TestInput_SimplePort(){
|
public void TestInput_SimplePort(){
|
||||||
try{
|
try{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user