use of org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo in project org.csstudio.display.builder by kasemir.
the class RulesWidgetProperty method readFromXML.
@Override
public void readFromXML(final ModelReader model_reader, final Element property_xml) throws Exception {
final Iterable<Element> rule_xml = XMLUtil.getChildElements(property_xml, XMLTags.RULE);
final List<RuleInfo> rules = new ArrayList<>();
for (final Element xml : rule_xml) {
String name, prop_id, out_exp_str;
try {
name = xml.getAttribute(XMLTags.NAME);
if (name.isEmpty())
logger.log(Level.WARNING, "Missing rule 'name'");
} catch (Exception ex) {
name = "unknown";
logger.log(Level.WARNING, "Failed to find rule name");
}
try {
prop_id = xml.getAttribute("prop_id");
if (prop_id.isEmpty())
logger.log(Level.WARNING, "Missing rule 'prop_id'");
} catch (Exception e) {
prop_id = "unknown";
logger.log(Level.WARNING, "Failed to find rule prop_id");
}
boolean prop_as_expr = false;
try {
out_exp_str = xml.getAttribute("out_exp");
prop_as_expr = false;
if (out_exp_str.isEmpty())
logger.log(Level.WARNING, "Missing rule 'out_exp'");
else
prop_as_expr = Boolean.parseBoolean(out_exp_str);
} catch (Exception e) {
logger.log(Level.WARNING, "Failed to find rule out_exp");
}
List<ExpressionInfo<?>> exprs;
try {
exprs = readExpressions(model_reader, prop_id, prop_as_expr, xml);
} catch (Throwable ex) {
logger.log(Level.WARNING, "Failure to readExpressions for " + prop_id, ex);
exprs = Collections.emptyList();
}
final List<ScriptPV> pvs = readPVs(xml);
rules.add(new RuleInfo(name, prop_id, prop_as_expr, exprs, pvs));
}
setValue(rules);
}
use of org.csstudio.display.builder.model.rules.RuleInfo.ExpressionInfo in project org.csstudio.display.builder by kasemir.
the class RulesWidgetProperty method readExpressions.
private List<ExpressionInfo<?>> readExpressions(final ModelReader model_reader, final String prop_id, final boolean prop_as_expr, final Element xml) throws Exception {
// Replace "pvSev0" by "pvLegacySev0"?
final boolean patch_severity = model_reader.getVersion().getMajor() < 2;
final List<ExpressionInfo<?>> exprs = new ArrayList<>();
final Iterable<Element> exprs_xml = XMLUtil.getChildElements(xml, "exp");
final String tagstr = (prop_as_expr) ? "expression" : "value";
for (final Element exp_xml : exprs_xml) {
String bool_exp = exp_xml.getAttribute("bool_exp");
if (bool_exp.isEmpty())
logger.log(Level.WARNING, "Missing exp 'bool_exp'");
if (patch_severity && bool_exp.contains("pvSev")) {
logger.log(Level.WARNING, "Patching rule with legacy '" + bool_exp + "' into 'pvLegacySev..'");
bool_exp = PVSEV_PATTERN.matcher(bool_exp).replaceAll("pvLegacySev$1");
}
final Element tag_xml = XMLUtil.getChildElement(exp_xml, tagstr);
// Legacy case where value is used for all value expression
final Element val_xml = (tag_xml == null) ? XMLUtil.getChildElement(exp_xml, "value") : tag_xml;
if (prop_as_expr) {
final String val_str = (val_xml != null) ? XMLUtil.getString(val_xml) : "";
// if (patch_severity && val_str.contains("pvSev")) ..?
// val_str was a Javascript expression,
// now needs to be a python expression.
// -> Not patching for now
exprs.add(new ExprInfoString(bool_exp, val_str));
} else {
final String val_str = (val_xml != null) ? XMLUtil.elementsToString(val_xml.getChildNodes(), false) : "";
final WidgetProperty<?> val_prop = propIDToNewProp(getWidget(), prop_id, val_str);
if (!miscUnknownPropID.getName().equals(val_prop.getName()))
val_prop.readFromXML(model_reader, val_xml);
exprs.add(new ExprInfoValue<>(bool_exp, val_prop));
}
}
return exprs;
}
Aggregations