Expression Parsing?

This may be all you need:

public class ExampleParseContext implements ExpressionParseContext {

    private final TagManagerBase tagManagerBase;
    private final FunctionFactory functionFactory;

    public ExampleParseContext(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;
    }

}

You can get references to the FunctionFactory and to the SQLTagsManager from GatewayContext. See GatewayContext#getExpressionFunctionFactory() and GatewayContext#getTagManager().

1 Like