Search in sources :

Example 1 with Event

use of org.eclipse.vorto.core.api.model.functionblock.Event 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;
    }
}
Also used : Status(org.eclipse.vorto.core.api.model.functionblock.Status) Configuration(org.eclipse.vorto.core.api.model.functionblock.Configuration) LWM2M(org.eclipse.vorto.codegen.lwm2m.generated.LWM2M) Fault(org.eclipse.vorto.core.api.model.functionblock.Fault) FunctionblockModel(org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel) Event(org.eclipse.vorto.core.api.model.functionblock.Event) Object(org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object) Property(org.eclipse.vorto.core.api.model.datatype.Property) FunctionBlock(org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)

Aggregations

LWM2M (org.eclipse.vorto.codegen.lwm2m.generated.LWM2M)1 Object (org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object)1 Property (org.eclipse.vorto.core.api.model.datatype.Property)1 Configuration (org.eclipse.vorto.core.api.model.functionblock.Configuration)1 Event (org.eclipse.vorto.core.api.model.functionblock.Event)1 Fault (org.eclipse.vorto.core.api.model.functionblock.Fault)1 FunctionBlock (org.eclipse.vorto.core.api.model.functionblock.FunctionBlock)1 FunctionblockModel (org.eclipse.vorto.core.api.model.functionblock.FunctionblockModel)1 Status (org.eclipse.vorto.core.api.model.functionblock.Status)1