use of org.eclipse.leshan.core.model.ResourceModel.Operations in project leshan by eclipse.
the class ResourceModelSerDes method deserialize.
@Override
public ResourceModel deserialize(JsonObject o) {
if (o == null)
return null;
if (!o.isObject())
return null;
int id = o.getInt("id", -1);
if (id < 0)
return null;
String name = o.getString("name", null);
Operations operations = Operations.valueOf(o.getString("operations", null));
String instancetype = o.getString("instancetype", null);
boolean mandatory = o.getBoolean("mandatory", false);
Type type = Type.valueOf(o.getString("type", "").toUpperCase());
String range = o.getString("range", null);
String units = o.getString("units", null);
String description = o.getString("description", null);
return new ResourceModel(id, name, operations, "multiple".equals(instancetype), mandatory, type, range, units, description);
}
use of org.eclipse.leshan.core.model.ResourceModel.Operations in project leshan by eclipse.
the class DDFFileParser method parseResource.
private ResourceModel parseResource(Node item) {
Integer id = Integer.valueOf(item.getAttributes().getNamedItem("ID").getTextContent());
String name = null;
Operations operations = Operations.NONE;
boolean multiple = false;
boolean mandatory = false;
Type type = Type.STRING;
String rangeEnumeration = null;
String units = null;
String description = null;
for (int i = 0; i < item.getChildNodes().getLength(); i++) {
Node field = item.getChildNodes().item(i);
switch(field.getNodeName()) {
case "Name":
name = field.getTextContent();
break;
case "Operations":
String strOp = field.getTextContent();
if (strOp != null && !strOp.isEmpty()) {
operations = Operations.valueOf(strOp);
}
break;
case "MultipleInstances":
multiple = "Multiple".equals(field.getTextContent());
break;
case "Mandatory":
mandatory = "Mandatory".equals(field.getTextContent());
break;
case "Type":
switch(field.getTextContent()) {
case "String":
type = Type.STRING;
break;
case "Integer":
type = Type.INTEGER;
break;
case "Float":
type = Type.FLOAT;
break;
case "Boolean":
type = Type.BOOLEAN;
break;
case "Opaque":
type = Type.OPAQUE;
break;
case "Time":
type = Type.TIME;
break;
case "Objlnk":
type = Type.OBJLNK;
break;
}
break;
case "RangeEnumeration":
rangeEnumeration = field.getTextContent();
break;
case "Units":
units = field.getTextContent();
break;
case "Description":
description = field.getTextContent();
break;
}
}
return new ResourceModel(id, name, operations, multiple, mandatory, type, rangeEnumeration, units, description);
}
Aggregations