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;
}
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;
}
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;
}
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());
}
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);
}
Aggregations