Search in sources :

Example 56 with DataType

use of com.serotonin.m2m2.DataType in project openj9 by eclipse.

the class StructurePointer method getStructureFields.

public StructureField[] getStructureFields() {
    List<StructureField> fields = new LinkedList<StructureField>();
    Class<?> working = this.getClass();
    while (working != null) {
        GeneratedPointerClass classAnnotation = working.getAnnotation(GeneratedPointerClass.class);
        if (null == classAnnotation) {
            break;
        }
        for (Method thisMethod : working.getMethods()) {
            if (thisMethod.isAnnotationPresent(GeneratedFieldAccessor.class)) {
                GeneratedFieldAccessor fieldAnnotation = thisMethod.getAnnotation(GeneratedFieldAccessor.class);
                Field offsetField = null;
                try {
                    offsetField = classAnnotation.structureClass().getField(fieldAnnotation.offsetFieldName());
                } catch (SecurityException e) {
                    throw new Error("Unexpected security exception", e);
                } catch (NoSuchFieldException e) {
                    // This will happen if we reach for a field that doesn't exist on this level
                    continue;
                }
                int offset = -1;
                try {
                    offset = offsetField.getInt(null);
                } catch (Exception e) {
                    throw new Error(e);
                }
                DataType result = null;
                CorruptDataException cde = null;
                try {
                    result = (DataType) thisMethod.invoke(this);
                } catch (IllegalArgumentException e) {
                    throw new RuntimeException(e);
                } catch (IllegalAccessException e) {
                    throw new RuntimeException(e);
                } catch (InvocationTargetException e) {
                    Throwable cause = e.getCause();
                    if (cause instanceof CorruptDataException) {
                        cde = (CorruptDataException) cause;
                    } else {
                        throw new RuntimeException(e);
                    }
                }
                fields.add(new StructureField(thisMethod.getName(), fieldAnnotation.declaredType(), offset, result, cde));
            }
        }
        working = working.getSuperclass();
    }
    Collections.sort(fields);
    StructureField[] result = new StructureField[fields.size()];
    fields.toArray(result);
    return result;
}
Also used : GeneratedPointerClass(com.ibm.j9ddr.GeneratedPointerClass) Method(java.lang.reflect.Method) CorruptDataException(com.ibm.j9ddr.CorruptDataException) GeneratedFieldAccessor(com.ibm.j9ddr.GeneratedFieldAccessor) LinkedList(java.util.LinkedList) CorruptDataException(com.ibm.j9ddr.CorruptDataException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Field(java.lang.reflect.Field) DataType(com.ibm.j9ddr.vm29.j9.DataType)

Example 57 with DataType

use of com.serotonin.m2m2.DataType in project ma-modules-public by infiniteautomation.

the class MultiPointStatisticsStreamTest method createDataPoint.

protected DataPointVO createDataPoint(int dataSourceId, DataType dataType, int defaultCacheSize) {
    DataPointVO vo = new DataPointVO();
    vo.setPointLocator(new MockPointLocatorVO(dataType, true));
    vo.setXid(DataPointDao.getInstance().generateUniqueXid());
    vo.setName("Test point");
    vo.setLoggingType(LoggingTypes.ALL);
    vo.setDataSourceId(dataSourceId);
    vo.setDefaultCacheSize(defaultCacheSize);
    // TODO initial cache size
    DataPointDao.getInstance().insert(vo);
    return vo;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)

Example 58 with DataType

use of com.serotonin.m2m2.DataType in project ma-modules-public by infiniteautomation.

the class MockPointLocatorModel method toVO.

@Override
public MockPointLocatorVO toVO() {
    MockPointLocatorVO vo = new MockPointLocatorVO();
    vo.setDataType(DataType.fromName(dataType));
    vo.setSettable(settable);
    return vo;
}
Also used : MockPointLocatorVO(com.serotonin.m2m2.vo.dataPoint.MockPointLocatorVO)

Example 59 with DataType

use of com.serotonin.m2m2.DataType in project ma-modules-public by infiniteautomation.

the class VirtualPointLocatorVO method createRuntime.

@Override
public PointLocatorRT<VirtualPointLocatorVO> createRuntime() {
    ChangeTypeRT changeType = getChangeType().createRuntime();
    String startValue = getChangeType().getStartValue();
    DataValue startObject;
    if (dataType == DataType.BINARY)
        startObject = BinaryValue.parseBinary(startValue);
    else if (dataType == DataType.MULTISTATE) {
        try {
            startObject = MultistateValue.parseMultistate(startValue);
        } catch (NumberFormatException e) {
            startObject = new MultistateValue(0);
        }
    } else if (dataType == DataType.NUMERIC) {
        try {
            startObject = NumericValue.parseNumeric(startValue);
        } catch (NumberFormatException e) {
            startObject = new NumericValue(0);
        }
    } else {
        if (startValue == null)
            startObject = new AlphanumericValue("");
        else
            startObject = new AlphanumericValue(startValue);
    }
    return new VirtualPointLocatorRT(this, changeType, startObject, isSettable());
}
Also used : AlphanumericValue(com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue) DataValue(com.serotonin.m2m2.rt.dataImage.types.DataValue) VirtualPointLocatorRT(com.serotonin.m2m2.virtual.rt.VirtualPointLocatorRT) ChangeTypeRT(com.serotonin.m2m2.virtual.rt.ChangeTypeRT) NumericValue(com.serotonin.m2m2.rt.dataImage.types.NumericValue) MultistateValue(com.serotonin.m2m2.rt.dataImage.types.MultistateValue)

Example 60 with DataType

use of com.serotonin.m2m2.DataType in project ma-modules-public by infiniteautomation.

the class VirtualPointLocatorVO method jsonRead.

@Override
public void jsonRead(JsonReader reader, JsonObject jsonObject) throws JsonException {
    if (jsonObject.containsKey("dataType")) {
        this.dataType = readDataType(jsonObject);
    }
    JsonObject ctjson = jsonObject.getJsonObject("changeType");
    if (ctjson == null)
        throw new TranslatableJsonException("emport.error.missingObject", "changeType");
    String text = ctjson.getString("type");
    if (text == null)
        throw new TranslatableJsonException("emport.error.missing", "type", ChangeTypeVO.CHANGE_TYPE_CODES.getCodeList());
    changeTypeId = ChangeTypeVO.CHANGE_TYPE_CODES.getId(text);
    if (changeTypeId == -1)
        throw new TranslatableJsonException("emport.error.invalid", "changeType", text, ChangeTypeVO.CHANGE_TYPE_CODES.getCodeList());
    reader.readInto(getChangeType(), ctjson);
}
Also used : JsonObject(com.serotonin.json.type.JsonObject) TranslatableJsonException(com.serotonin.m2m2.i18n.TranslatableJsonException)

Aggregations

ArrayList (java.util.ArrayList)26 DataValue (com.serotonin.m2m2.rt.dataImage.types.DataValue)23 PointValueTime (com.serotonin.m2m2.rt.dataImage.PointValueTime)17 DataType (com.serotonin.m2m2.DataType)14 HashMap (java.util.HashMap)14 ShouldNeverHappenException (com.serotonin.ShouldNeverHappenException)13 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)11 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)11 AlphanumericValue (com.serotonin.m2m2.rt.dataImage.types.AlphanumericValue)10 MultistateValue (com.serotonin.m2m2.rt.dataImage.types.MultistateValue)10 NumericValue (com.serotonin.m2m2.rt.dataImage.types.NumericValue)10 DataType (org.osate.aadl2.DataType)10 DataType (ucar.ma2.DataType)10 BinaryValue (com.serotonin.m2m2.rt.dataImage.types.BinaryValue)9 IOException (java.io.IOException)9 DataImplementation (org.osate.aadl2.DataImplementation)9 ResultTypeException (com.serotonin.m2m2.rt.script.ResultTypeException)8 File (java.io.File)7 ScriptError (com.serotonin.m2m2.rt.script.ScriptError)6 ScriptPermissionsException (com.serotonin.m2m2.rt.script.ScriptPermissionsException)6