value info is no longer needed

This commit is contained in:
paul-loedige 2021-01-04 23:20:46 +01:00
parent 4ca7f99941
commit b2f263e5ed
2 changed files with 0 additions and 70 deletions

View File

@ -70,52 +70,6 @@ public class XMLHandler implements IXML {
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.
* @param deviceName the name of the relevant device

View File

@ -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
public void TestInput_SimplePort(){
try{