Search in sources :

Example 1 with PropertyType

use of org.eclipse.vorto.core.api.model.datatype.PropertyType 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)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