|
@@ -86,14 +86,8 @@ public class FlowBus {
|
|
}
|
|
}
|
|
|
|
|
|
public static void addSpringScanNode(String nodeId, NodeComponent nodeComponent) {
|
|
public static void addSpringScanNode(String nodeId, NodeComponent nodeComponent) {
|
|
- NodeTypeEnum type = null;
|
|
|
|
- if (nodeComponent instanceof NodeSwitchComponent){
|
|
|
|
- type = NodeTypeEnum.SWITCH;
|
|
|
|
- } else if(nodeComponent instanceof NodeIfComponent){
|
|
|
|
- type = NodeTypeEnum.IF;
|
|
|
|
- }else if(nodeComponent instanceof NodeComponent) {
|
|
|
|
- type = NodeTypeEnum.COMMON;
|
|
|
|
- }
|
|
|
|
|
|
+ //根据class来猜测类型
|
|
|
|
+ NodeTypeEnum type = NodeTypeEnum.guessTypeByClazz(nodeComponent.getClass());
|
|
|
|
|
|
if (type == null){
|
|
if (type == null){
|
|
throw new NullNodeTypeException(StrUtil.format("node type is null for node[{}]", nodeId));
|
|
throw new NullNodeTypeException(StrUtil.format("node type is null for node[{}]", nodeId));
|
|
@@ -144,6 +138,48 @@ public class FlowBus {
|
|
addNode(nodeId, name, NodeTypeEnum.IF, cmpClazz, null);
|
|
addNode(nodeId, name, NodeTypeEnum.IF, cmpClazz, null);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void addForNode(String nodeId, String name, String cmpClazzStr){
|
|
|
|
+ Class<?> cmpClazz;
|
|
|
|
+ try{
|
|
|
|
+ cmpClazz = Class.forName(cmpClazzStr);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new ComponentCannotRegisterException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ addNode(nodeId, name, NodeTypeEnum.FOR, cmpClazz, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void addForNode(String nodeId, String name, Class<?> cmpClazz){
|
|
|
|
+ addNode(nodeId, name, NodeTypeEnum.FOR, cmpClazz, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void addWhileNode(String nodeId, String name, String cmpClazzStr){
|
|
|
|
+ Class<?> cmpClazz;
|
|
|
|
+ try{
|
|
|
|
+ cmpClazz = Class.forName(cmpClazzStr);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new ComponentCannotRegisterException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ addNode(nodeId, name, NodeTypeEnum.WHILE, cmpClazz, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void addWhileNode(String nodeId, String name, Class<?> cmpClazz){
|
|
|
|
+ addNode(nodeId, name, NodeTypeEnum.WHILE, cmpClazz, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void addBreakNode(String nodeId, String name, String cmpClazzStr){
|
|
|
|
+ Class<?> cmpClazz;
|
|
|
|
+ try{
|
|
|
|
+ cmpClazz = Class.forName(cmpClazzStr);
|
|
|
|
+ }catch (Exception e){
|
|
|
|
+ throw new ComponentCannotRegisterException(e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ addNode(nodeId, name, NodeTypeEnum.BREAK, cmpClazz, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void addBreakNode(String nodeId, String name, Class<?> cmpClazz){
|
|
|
|
+ addNode(nodeId, name, NodeTypeEnum.BREAK, cmpClazz, null);
|
|
|
|
+ }
|
|
|
|
+
|
|
public static void addCommonScriptNode(String nodeId, String name, String script){
|
|
public static void addCommonScriptNode(String nodeId, String name, String script){
|
|
addNode(nodeId, name, NodeTypeEnum.SCRIPT, ScriptComponent.class, script);
|
|
addNode(nodeId, name, NodeTypeEnum.SCRIPT, ScriptComponent.class, script);
|
|
}
|
|
}
|
|
@@ -156,6 +192,18 @@ public class FlowBus {
|
|
addNode(nodeId, name, NodeTypeEnum.IF_SCRIPT, ScriptIfComponent.class, script);
|
|
addNode(nodeId, name, NodeTypeEnum.IF_SCRIPT, ScriptIfComponent.class, script);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public static void addForScriptNode(String nodeId, String name, String script){
|
|
|
|
+ addNode(nodeId, name, NodeTypeEnum.FOR_SCRIPT, ScriptIfComponent.class, script);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void addWhileScriptNode(String nodeId, String name, String script){
|
|
|
|
+ addNode(nodeId, name, NodeTypeEnum.WHILE_SCRIPT, ScriptIfComponent.class, script);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static void addBreakScriptNode(String nodeId, String name, String script){
|
|
|
|
+ addNode(nodeId, name, NodeTypeEnum.BREAK_SCRIPT, ScriptIfComponent.class, script);
|
|
|
|
+ }
|
|
|
|
+
|
|
private static void addNode(String nodeId, String name, NodeTypeEnum type, Class<?> cmpClazz, String script) {
|
|
private static void addNode(String nodeId, String name, NodeTypeEnum type, Class<?> cmpClazz, String script) {
|
|
try {
|
|
try {
|
|
//判断此类是否是声明式的组件,如果是声明式的组件,就用动态代理生成实例
|
|
//判断此类是否是声明式的组件,如果是声明式的组件,就用动态代理生成实例
|
|
@@ -179,7 +227,7 @@ public class FlowBus {
|
|
//以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置
|
|
//以node方式配置,本质上是为了适配无spring的环境,如果有spring环境,其实不用这么配置
|
|
//这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了
|
|
//这里的逻辑是判断是否能从spring上下文中取到,如果没有spring,则就是new instance了
|
|
//如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance
|
|
//如果是script类型的节点,因为class只有一个,所以也不能注册进spring上下文,注册的时候需要new Instance
|
|
- if (!CollectionUtil.newArrayList(NodeTypeEnum.SCRIPT, NodeTypeEnum.SWITCH_SCRIPT, NodeTypeEnum.IF_SCRIPT).contains(type)){
|
|
|
|
|
|
+ if (!type.isScript()){
|
|
cmpInstances = ListUtil.toList((NodeComponent) ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz));
|
|
cmpInstances = ListUtil.toList((NodeComponent) ContextAwareHolder.loadContextAware().registerOrGet(nodeId, cmpClazz));
|
|
}
|
|
}
|
|
// 去除null元素
|
|
// 去除null元素
|