!102 优化QLExpress的Runner初始化

Merge pull request !102 from zendwang/dev
This commit is contained in:
铂赛东 2022-09-07 03:25:15 +00:00 committed by Gitee
commit 3d692be995
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 21 additions and 20 deletions

View File

@ -42,7 +42,26 @@ public class LiteFlowChainELBuilder {
private final List<Condition> finallyConditionList;
//EL解析引擎
private final ExpressRunner expressRunner;
private final static ExpressRunner EXPRESS_RUNNER = new ExpressRunner();;
static {
//初始化QLExpress的Runner
EXPRESS_RUNNER.addFunction("THEN", new ThenOperator());
EXPRESS_RUNNER.addFunction("WHEN", new WhenOperator());
EXPRESS_RUNNER.addFunction("SWITCH", new SwitchOperator());
EXPRESS_RUNNER.addFunction("PRE", new PreOperator());
EXPRESS_RUNNER.addFunction("FINALLY", new FinallyOperator());
EXPRESS_RUNNER.addFunction("IF", new IfOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod("ELSE", Object.class, new ElseOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod("ELIF", Object.class, new ElifOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod("to", Object.class, new ToOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod("tag", Object.class, new TagOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod("any", Object.class, new AnyOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod("id", Object.class, new IdOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod("ignoreError", Object.class, new IgnoreErrorOperator());
EXPRESS_RUNNER.addFunctionAndClassMethod("threadPool", Object.class, new ThreadPoolOperator());
EXPRESS_RUNNER.addFunction("node", new NodeOperator());
}
public static LiteFlowChainELBuilder createChain() {
return new LiteFlowChainELBuilder();
@ -53,24 +72,6 @@ public class LiteFlowChainELBuilder {
conditionList = new ArrayList<>();
preConditionList = new ArrayList<>();
finallyConditionList = new ArrayList<>();
//初始化QLExpress的Runner
expressRunner = new ExpressRunner();
expressRunner.addFunction("THEN", new ThenOperator());
expressRunner.addFunction("WHEN", new WhenOperator());
expressRunner.addFunction("SWITCH", new SwitchOperator());
expressRunner.addFunction("PRE", new PreOperator());
expressRunner.addFunction("FINALLY", new FinallyOperator());
expressRunner.addFunction("IF", new IfOperator());
expressRunner.addFunctionAndClassMethod("ELSE", Object.class, new ElseOperator());
expressRunner.addFunctionAndClassMethod("ELIF", Object.class, new ElifOperator());
expressRunner.addFunctionAndClassMethod("to", Object.class, new ToOperator());
expressRunner.addFunctionAndClassMethod("tag", Object.class, new TagOperator());
expressRunner.addFunctionAndClassMethod("any", Object.class, new AnyOperator());
expressRunner.addFunctionAndClassMethod("id", Object.class, new IdOperator());
expressRunner.addFunctionAndClassMethod("ignoreError", Object.class, new IgnoreErrorOperator());
expressRunner.addFunctionAndClassMethod("threadPool", Object.class, new ThreadPoolOperator());
expressRunner.addFunction("node", new NodeOperator());
}
//在parser中chain的build是2段式的因为涉及到依赖问题以前是递归parser
@ -105,7 +106,7 @@ public class LiteFlowChainELBuilder {
//解析el成为一个Condition
//为什么这里只是一个Condition而不是一个List<Condition>
//这里无论多复杂的外面必定有一个最外层的Condition所以这里只有一个内部可以嵌套很多层这点和以前的不太一样
Condition condition = (Condition) expressRunner.execute(elStr, context, errorList, true, true);
Condition condition = (Condition) EXPRESS_RUNNER.execute(elStr, context, errorList, true, true);
//从condition的第一层嵌套结构里拿出Pre和Finally节点
//为什么只寻找第一层而不往下寻找了呢