ready = false; //Stop anyone else from using this
}
// Propagate the update to the target point. Validate that the target point is available.
DataPointRT targetPoint = Common.runtimeManager.getDataPoint(vo.getTargetPointId());
if (targetPoint == null) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("event.pointLink.targetUnavailable"));
return;
}
if (!targetPoint.getPointLocator().isSettable()) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("event.pointLink.targetNotSettable"));
return;
}
int targetDataType = targetPoint.getVO().getPointLocator().getDataTypeId();
if (!StringUtils.isBlank(vo.getScript())) {
ScriptExecutor scriptExecutor = new ScriptExecutor();
Map<String, IDataPointValueSource> context = new HashMap<String, IDataPointValueSource>();
DataPointRT source = Common.runtimeManager.getDataPoint(vo.getSourcePointId());
context.put(CONTEXT_VAR_NAME, source);
try {
PointValueTime pvt = scriptExecutor.execute(vo.getScript(), context, newValue.getTime(),
targetDataType, newValue.getTime());
if (pvt.getValue() == null) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("event.pointLink.nullResult"));
return;
}
newValue = pvt;
}
catch (ScriptException e) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("common.default", e.getMessage()));
return;
}
catch (ResultTypeException e) {
raiseFailureEvent(newValue.getTime(), e.getTranslatableMessage());
return;
}
}
if (DataTypes.getDataType(newValue.getValue()) != targetDataType) {
raiseFailureEvent(newValue.getTime(), new TranslatableMessage("event.pointLink.convertError"));
return;
}
// Queue a work item to perform the update.
Common.backgroundProcessing.addWorkItem(new PointLinkSetPointWorkItem(vo.getTargetPointId(), newValue, this));