🥥Method level declaration
LiteFlow supports method-level declarative features since v2.9.0.
The method level declaration allows users to define multiple components in a class through annotations, which is more flexible.
If you have a lot of components and want to avoid the problem of having too many classes defined, then this feature is very suitable for this need.
You can define multiple components in a bean like this:
@LiteflowComponent
public class CmpConfig {
//Definition of common components
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a")
public void processA(NodeComponent bindCmp) {
...
}
//Definition of switch components
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeId = "b", nodeType = NodeTypeEnum.SWITCH)
public void processB(NodeComponent bindCmp) {
...
}
//Definition of if components
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "c", nodeType = NodeTypeEnum.IF)
public boolean processC(NodeComponent bindCmp) {
...
}
//Definition of for components
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeId = "d", nodeType = NodeTypeEnum.FOR)
public int processD(NodeComponent bindCmp) {
...
}
//Definition of while components
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeId = "e", nodeType = NodeTypeEnum.WHILE)
public int processE(NodeComponent bindCmp) {
...
}
//Definition of break components
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeId = "f", nodeType = NodeTypeEnum.BREAK)
public int processF(NodeComponent bindCmp) {
...
}
}
notice1
It should be noted here that for the method-level declaration feature, the nodeId
on the @LiteflowMethod
annotation must be written.
The nodeType
on the common component can be omitted because it has a default value, but for the sake of clarity, it is recommended that you add nodeType = NodeTypeEnum.COMMON
.
notice2
When you define a method yourself, the return value should be the same as the return value of the corresponding method in the conventional component. For example, the process
method of ordinary components does not return, such as the processIf
method of IF components, which returns a boolean value.
If you write it wrong, a little exception will occur, which may increase your troubleshooting time.
The methods for other components are also declared in a similar way. For example, I define 2 components in a class, and each component implements 3 methods, which can be written as follows:
@LiteflowComponent
public class CmpConfig {
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS, nodeId = "a", nodeType = NodeTypeEnum.COMMON)
public void processA(NodeComponent bindCmp) {
...
}
@LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "a", nodeType = NodeTypeEnum.COMMON)
public boolean isAccessA(NodeComponent bindCmp){
...
}
@LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS, nodeId = "a", nodeType = NodeTypeEnum.COMMON)
public void onSuccessA(NodeComponent bindCmp){
...
}
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_IF, nodeId = "f", nodeType = NodeTypeEnum.IF)
public boolean processF(NodeComponent bindCmp) {
...
}
@LiteflowMethod(value = LiteFlowMethodEnum.IS_ACCESS, nodeId = "f", nodeType = NodeTypeEnum.IF)
public boolean isAccessF(NodeComponent bindCmp){
...
}
@LiteflowMethod(value = LiteFlowMethodEnum.ON_SUCCESS, nodeId = "f", nodeType = NodeTypeEnum.IF)
public void onSuccessF(NodeComponent bindCmp){
...
}
}