Expression Parsing?

Here is what we have done.

  1. Create an object that implements ExpressionParseContext. I am not sure if this is required or not.
public class MyParserContext implements ExpressionParseContext {

	@Override
	public Expression createBoundExpression(String path)
			throws RuntimeException {
		TagPath tagPath;
		try {
			tagPath = TagPathParser.parse(path);
			BoundTagExpression exp = new BoundTagExpression(tagPath);
			exp.setTagListenerDelegate(new TagListener(
					tagPath, null, DataQuality.UNKNOWN));
			return exp;
		} catch (IOException e) {
			return null;
		}
	}

	@Override
	public FunctionFactory getFunctionFactory() {
        return new ClientFunctionFactory(DefaultFunctionFactory.getSharedInstance());
	}

}

After having a reference to the context, try something like this:

Parser parser = new ELParserHarness();
MyParserContext mpc = new MyParserContext();
try {
                LOGGER.debug("This is my lblExpStr: " + lblExpStr);
                lblExp = parser.parse(lblExpStr,mpc);

                lblExp.connect(ctx, new InteractionListener() {
                    @Override
                    public void childInteractionUpdated() {
                        try {
                            LOGGER.debug("updating");
                            String value = lblExp.execute().getValue()
                                    .toString();
                            system.out.println(value);
                        } catch (ExpressionException e) {
                            LOGGER.warn("Error evaluating lblExpStr", e);
                        }
                    }
                });
                //Start the expression, then use it to print the initial text.
                lblExp.startup();
                system.out.println(lblExp.execute().getValue().toString());
            } catch (Exception e) {
                LOGGER.error("Error Starting ELParser", e);
            }

Let me know how well this works for you, I know my source works in my application, but I changed it to be a little more generic for you.

1 Like