Search in sources :

Example 1 with Item

use of org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources.Item in project vorto by eclipse.

the class FunctionBlockXmlTemplate method handleOperations.

private void handleOperations(final FunctionBlock functionblock, final Object lwm2mObject, final InvocationContext context) {
    final EList<Operation> operations = functionblock.getOperations();
    for (final Operation operation : operations) {
        if (!context.getMappedElement(operation, STEREOTYPE_RESOURCE).isMapped()) {
            continue;
        }
        final Item item = new Item();
        handleMappingRulesForOperations(lwm2mObject, operation, item, context);
        // handle name
        final String operName = operation.getName();
        // 1:1 mapping
        item.setName(operName);
        // handle operation ==> operations : E
        item.setOperations("E");
        // handle description
        String operDescr = operation.getDescription();
        if (null == operDescr) {
            // as default
            operDescr = "";
        }
        item.setDescription(operDescr);
        // handle operation parameters
        final EList<Param> params = operation.getParams();
        if (!params.isEmpty()) {
            final String errMsg = "Unsupported operation <" + operName + "> with parameter(s) - Generator only supports One-way operations without parameter(s)!";
            throw new IllegalArgumentException(errMsg);
        }
        final ReturnType returnType = operation.getReturnType();
        if (returnType != null) {
            final String errMsg = "Unsupported operation <" + operName + "> with return Type - Generator only supports One-way operations without parameter(s)!";
            throw new IllegalArgumentException(errMsg);
        }
        checkResourceIdConflictAndFillSet(item);
    }
}
Also used : Item(org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources.Item) Param(org.eclipse.vorto.core.api.model.functionblock.Param) Operation(org.eclipse.vorto.core.api.model.functionblock.Operation) ReturnType(org.eclipse.vorto.core.api.model.functionblock.ReturnType)

Example 2 with Item

use of org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources.Item in project vorto by eclipse.

the class FunctionBlockXmlTemplate method addSortedResourceIds.

private void addSortedResourceIds(final String functionBlockName, final Object lwm2mObject) {
    final Resources lwm2mResources = new Resources();
    final List<Item> resourceItems = lwm2mResources.getItem();
    if (resourceIdSet.isEmpty()) {
        final String errMsg = "Empty Function Block <" + functionBlockName + "> (contains no resources)" + STR_ABORT_GENERATOR;
        throw new IllegalArgumentException(errMsg);
    }
    resourceItems.addAll(resourceIdSet);
    lwm2mObject.setResources(lwm2mResources);
}
Also used : Item(org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources.Item) Resources(org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources)

Example 3 with Item

use of org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources.Item in project vorto by eclipse.

the class FunctionBlockXmlTemplate method handleProperties.

private void handleProperties(final Object lwm2mObject, final EList<Property> properties, final String operation, final InvocationContext context) {
    for (final Property property : properties) {
        final Item item = new Item();
        item.setOperations(operation);
        handleMappingRulesForProperties(lwm2mObject, property, item, context);
        // handle mandatory
        final Presence mandatory = property.getPresence();
        if (mandatory == null || !mandatory.isMandatory()) {
            // default mapping
            item.setMandatory(ATTR_MANDATORY_OPTIONAL_VALUE);
        } else {
            item.setMandatory(ATTR_MANDATORY_MANDATORY_VALUE);
        }
        // handle multiplicity
        final boolean multiplicity = property.isMultiplicity();
        if (multiplicity) {
            item.setMultipleInstances(ATTR_MULTIPLE_INSTANCES_MULTIPLE_VALUE);
        } else {
            item.setMultipleInstances(ATTR_MULTIPLE_INSTANCES_SINGLE_VALUE);
        }
        // handle name
        final String statusPropertyName = property.getName();
        // 1:1 mapping
        item.setName(statusPropertyName);
        handleRangeEnumeration(lwm2mObject, property, item);
        // handle type
        final PropertyType type = property.getType();
        if (type instanceof PrimitivePropertyTypeImpl) {
            final String primitiveTypeStr = ((PrimitivePropertyTypeImpl) type).getType().toString();
            final String lwm2mTypeStr = propertyType2Lwm2mType(primitiveTypeStr);
            item.setType(lwm2mTypeStr);
        } else {
            final String errMsg = unsupportedValueForPropertyMsg("PropertyType (Enum/Entity)", property, lwm2mObject);
            throw new IllegalArgumentException(errMsg);
        }
        // handle Description
        String statusPropDescr = property.getDescription();
        if (null == statusPropDescr) {
            // as default
            statusPropDescr = "";
        }
        item.setDescription(statusPropDescr);
        checkResourceIdConflictAndFillSet(item);
    }
}
Also used : Item(org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources.Item) PrimitivePropertyTypeImpl(org.eclipse.vorto.core.api.model.datatype.impl.PrimitivePropertyTypeImpl) Presence(org.eclipse.vorto.core.api.model.datatype.Presence) PropertyType(org.eclipse.vorto.core.api.model.datatype.PropertyType) Property(org.eclipse.vorto.core.api.model.datatype.Property)

Aggregations

Item (org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources.Item)3 Resources (org.eclipse.vorto.codegen.lwm2m.generated.LWM2M.Object.Resources)1 Presence (org.eclipse.vorto.core.api.model.datatype.Presence)1 Property (org.eclipse.vorto.core.api.model.datatype.Property)1 PropertyType (org.eclipse.vorto.core.api.model.datatype.PropertyType)1 PrimitivePropertyTypeImpl (org.eclipse.vorto.core.api.model.datatype.impl.PrimitivePropertyTypeImpl)1 Operation (org.eclipse.vorto.core.api.model.functionblock.Operation)1 Param (org.eclipse.vorto.core.api.model.functionblock.Param)1 ReturnType (org.eclipse.vorto.core.api.model.functionblock.ReturnType)1