private Map<String, String> setMotors(final MotorContainer cont, final DataMessageComponent comp) throws DataMessageException { final Map<String, String> ret = new HashMap<String, String>(cont.size()); for (MotorBean mb : cont.getExpressions()) { final String motorPath = SubstituteUtils.substitute(mb.getMotorName(), comp.getScalar()); final String baseUri = TangoUtils.getHardwareAddress(motorPath); String attribute = mb.getAttributeName(); if (attribute == null || "".equals(attribute.trim())) attribute = "Position"; DeviceAttribute value = null; if (!mb.isReadOnly()) { try { final double dbl = ExpressionUtils.evaluateExpression(mb.getExpression(), comp.getScalar()); if (Double.isNaN(dbl) || Double.isInfinite(dbl)) throw new Exception(); value = new DeviceAttribute(attribute, dbl); } catch (Exception e) { final String exp = SubstituteUtils.substitute(mb.getExpression(), comp.getScalar()); value = new DeviceAttribute(attribute, exp); } } try { final TangoConnection connection = TangoConnectionFactory.openConnection(baseUri, attribute); if (value != null) { connection.setValue(value); // Uses remote call for MockMode } try { value = connection.getValue(); } catch (Exception ne) { logger.debug("Error in TangoMotorTransformer " + getName()); logger.debug("Error message: " + ne.getMessage()); logger.debug(ne.getStackTrace().toString()); value = new DeviceAttribute(attribute, 0.0); } try { final String dblString = String.valueOf(value.extractDouble()); ret.put(connection.getName(), dblString); } catch (Exception ne) { ret.put(connection.getName(), String.valueOf(value.extractString())); } } catch (Exception e) { throw createDataMessageException("Cannot connect to " + baseUri, e); } } return ret; }
public void setPreview(boolean isPreview) { if (!isPreview) { final String text = getReplaceText(); if (text == null) return; setText(text, true); setReplaceText(null); } else { EclipseUtils.getActivePage().saveEditor(this, false); final Map<String, String> vars = actor.getExampleValues(); final String text = getText(); setReplaceText(text); final String rep = SubstituteUtils.substitute(text, vars); setText(rep, false); } }