mirror of
https://gitee.com/dromara/liteFlow.git
synced 2026-05-14 12:12:08 +08:00
增加了自定义parser的扩展
This commit is contained in:
@@ -51,14 +51,17 @@ public class FlowExecutor {
|
||||
XmlFlowParser parser = null;
|
||||
for(String path : rulePath){
|
||||
try {
|
||||
if(isZKConfig(path)) {
|
||||
if(isLocalConfig(path)) {
|
||||
parser = new LocalXmlFlowParser();
|
||||
}else if(isZKConfig(path)){
|
||||
if(StringUtils.isNotBlank(zkNode)) {
|
||||
parser = new ZookeeperXmlFlowParser(zkNode);
|
||||
}else {
|
||||
parser = new ZookeeperXmlFlowParser();
|
||||
}
|
||||
}else {
|
||||
parser = new LocalXmlFlowParser();
|
||||
}else if(isClassConfig(path)) {
|
||||
Class c = Class.forName(path);
|
||||
parser = (XmlFlowParser)c.newInstance();
|
||||
}
|
||||
parser.parseMain(path);
|
||||
} catch (Exception e) {
|
||||
@@ -75,6 +78,18 @@ public class FlowExecutor {
|
||||
return m.find();
|
||||
}
|
||||
|
||||
private boolean isLocalConfig(String path) {
|
||||
Pattern p = Pattern.compile("^[\\w\\/]+(\\/\\w+)*\\.xml$");
|
||||
Matcher m = p.matcher(path);
|
||||
return m.find();
|
||||
}
|
||||
|
||||
private boolean isClassConfig(String path) {
|
||||
Pattern p = Pattern.compile("^\\w+(\\.\\w+)*$");
|
||||
Matcher m = p.matcher(path);
|
||||
return m.find();
|
||||
}
|
||||
|
||||
public void reloadRule(){
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.thebeastshop.liteflow.parser;
|
||||
|
||||
public abstract class ClassXmlFlowParser extends XmlFlowParser {
|
||||
@Override
|
||||
public void parseMain(String path) throws Exception {
|
||||
String content = parseCustom();
|
||||
parse(content);
|
||||
}
|
||||
|
||||
public abstract String parseCustom();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package com.thebeastshop.liteflow.test;
|
||||
|
||||
import com.thebeastshop.liteflow.parser.ClassXmlFlowParser;
|
||||
|
||||
public class TestCustomParser extends ClassXmlFlowParser {
|
||||
|
||||
@Override
|
||||
public String parseCustom() {
|
||||
System.out.println("进入自定义parser,这里只做进入作用,不返回具体xml");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -28,4 +28,13 @@
|
||||
</property>
|
||||
<property name="zkNode" value="/lite-flow/customFlow"/>这个不配置就用默认的/lite-flow/flow节点
|
||||
</bean> -->
|
||||
|
||||
<!-- 这种是自定义Class方式配置 -->
|
||||
<!-- <bean id="flowExecutor" class="com.thebeastshop.liteflow.core.FlowExecutor">
|
||||
<property name="rulePath">
|
||||
<list>
|
||||
<value>com.thebeastshop.liteflow.test.TestCustomParser</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean> -->
|
||||
</beans>
|
||||
Reference in New Issue
Block a user