use of org.eclipse.vorto.core.api.model.functionblock.FunctionBlock in project vorto by eclipse.
the class FunctionBlockXmlTemplate method getContent.
/**
* Retrieves the content of the XML generation template.
*
* @param model the {@link FunctionblockModel}
* @return generated content for the specified model
*/
public String getContent(final FunctionblockModel model, InvocationContext context) {
// FB name
final String name = model.getName();
try {
final LWM2M lwm2m = new LWM2M();
final List<Object> lwm2mObjects = lwm2m.getObject();
final FunctionBlock functionblock = model.getFunctionblock();
if (functionblock == null) {
throw new RuntimeException("This model has no function block.");
}
final Object lwm2mObject = new Object();
// waiting for Issue in
lwm2mObject.setObjectType("MODefinition");
// https://github.com/OpenMobileAlliance/OMA-LwM2M-Public-Review/issues
lwm2mObject.setName(name);
final IMapped<FunctionblockModel> mappedFunctionblock = context.getMappedElement(model, STEREOTYPE_OBJECT);
lwm2mObject.setObjectID(Integer.parseInt(mappedFunctionblock.getAttributeValue(OBJECT_ID, "0")));
lwm2mObject.setObjectURN(mappedFunctionblock.getAttributeValue(OBJECT_URN, "TBD"));
lwm2mObject.setMultipleInstances(mappedFunctionblock.getAttributeValue(ATTR_MULTIPLE_INSTANCES_MULTIPLE_VALUE, "Single"));
lwm2mObject.setMandatory(mappedFunctionblock.getAttributeValue(ATTRIBUTE_MANDATORY, "Optional"));
lwm2mObject.setDescription1(model.getDescription());
lwm2mObject.setDescription2(mappedFunctionblock.getAttributeValue(ATTRIBUTE_DESCRIPTION2, ""));
// handle config ------------------------------------------------------
final Configuration configuration = functionblock.getConfiguration();
if (configuration != null) {
final EList<Property> configProps = configuration.getProperties();
// configuration ==> operations : RW (default)
handleProperties(lwm2mObject, configProps, "RW", context);
}
// handle status ------------------------------------------------------
final Status status = functionblock.getStatus();
if (status != null) {
final EList<Property> statusProps = status.getProperties();
// status ==> operations : R
handleProperties(lwm2mObject, statusProps, "R", context);
}
// handle operations --------------------------------------------------
handleOperations(functionblock, lwm2mObject, context);
// handle fault -------------------------------------------------------
final Fault fault = functionblock.getFault();
if (fault != null) {
final String errMsg = "Unsupported element <fault>" + STR_ABORT_GENERATOR;
throw new IllegalArgumentException(errMsg);
}
// handle events
final EList<Event> events = functionblock.getEvents();
if (!events.isEmpty()) {
final String errMsg = "Unsupported element <events>" + STR_ABORT_GENERATOR;
throw new IllegalArgumentException(errMsg);
}
addSortedResourceIds(name, lwm2mObject);
lwm2mObjects.add(lwm2mObject);
return handleMarshalling(lwm2m, name);
} catch (final RuntimeException e) {
throw e;
}
}
Aggregations