Hi @Kevin.Herron,
thanks, I got it working using this class you wrote and this usage example.
In case if anyone needs a running example, I will leave the following code snippets here:
public class CustomParseContext implements ExpressionParseContext {
private final TagManagerBase tagManagerBase;
private final FunctionFactory functionFactory;
public CustomParseContext(TagManagerBase tagManagerBase, FunctionFactory functionFactory) {
this.tagManagerBase = tagManagerBase;
this.functionFactory = functionFactory;
}
@Override
public Expression createBoundExpression(String path) throws RuntimeException {
try {
TagPath tagPath = TagPathParser.parse(path);
Tag tag = tagManagerBase.getTag(tagPath);
if (tag == null) throw new TagNotFoundException(tagPath);
TagValue tagValue = tag.getAttribute(tagPath.getProperty());
TagListener listener = new TagListener(
tagPath,
tagValue.getValue(),
tagValue.getQuality()
);
Class type = TagProp.Value.equals(tagPath.getProperty()) ?
tag.getDataType().getJavaType() :
tagPath.getProperty().getType();
BoundTagExpression expression = new BoundTagExpression(tagPath);
expression.setType(type);
expression.setTagListenerDelegate(listener);
return expression;
} catch (IllegalArgumentException | IOException | TagNotFoundException e) {
throw new RuntimeException(e);
}
}
@Override
public FunctionFactory getFunctionFactory() {
return functionFactory;
}
}
public class MyComponent extends AbstractVisionPanel {
private final Logger logger = LoggerFactory.getLogger(getClass());
...
@Override
protected void onStartup() {
super.onStartup();
VisionClientContext appContext = getAppContext();
FunctionFactory functionFactory = appContext.getExpressionFunctionFactory();
ClientTagManager tagManager = appContext.getTagManager();
CustomParseContext customParseContext = new CustomParseContext(tagManager, functionFactory);
Parser parser = new ELParserHarness();
String expressionString = "now(1000)";
try {
Expression expression = parser.parse(expressionString, customParseContext);
expression.connect(appContext, () -> {
try {
logger.debug("updating");
String value = TypeUtilities.toString(expression.execute().getValue());
System.out.printf("value = %s\n", value);
} catch (ExpressionException e) {
logger.warn("Error parsing expression '{}'", expressionString);
}
});
expression.startup();
// Execute the expression 'now(1000)' once
System.out.println("execute: " + TypeUtilities.toString(expression.execute().getValue()));
} catch (Exception e) {
logger.error("Error starting ELParser", e);
}
}
...
}
I will mark this question as solved if you don’t mind