🧅Class level declaration
The main purpose of class-level declaration is to make ordinary java beans into components of LiteFlow through annotations. There is no need to inherit classes or implement interfaces.
Since the components of LiteFlow need to be defined by inheriting classes in the conventional way, you cannot inherit the classes of your own business. This feature can solve this problem.
# Declaration of common components
You can declare a common component as follows:
@LiteflowComponent("a")
@LiteflowCmpDefine
public class ACmp{
@LiteflowMethod(LiteFlowMethodEnum.PROCESS)
public void processAcmp(NodeComponent bindCmp) {
System.out.println("ACmp executed!");
}
@LiteflowMethod(LiteFlowMethodEnum.IS_ACCESS)
public boolean isAcmpAccess(NodeComponent bindCmp){
return true;
}
@LiteflowMethod(LiteFlowMethodEnum.BEFORE_PROCESS)
public void beforeAcmp(String nodeId, Slot slot){
System.out.println("before A");
}
@LiteflowMethod(LiteFlowMethodEnum.AFTER_PROCESS)
public void afterAcmp(String nodeId, Slot slot){
System.out.println("after A");
}
@LiteflowMethod(LiteFlowMethodEnum.ON_SUCCESS)
public void onAcmpSuccess(NodeComponent bindCmp){
System.out.println("Acmp success");
}
@LiteflowMethod(LiteFlowMethodEnum.ON_ERROR)
public void onAcmpError(NodeComponent bindCmp){
System.out.println("Acmp error");
}
@LiteflowMethod(LiteFlowMethodEnum.IS_END)
public boolean isAcmpEnd(NodeComponent bindCmp) {
return false;
}
}
Users do not need to inherit NodeComponent
. On the class you define, as long as the class is annotated with LiteflowCmpDefine
, and the corresponding method is annotated with LiteflowMethod
, any custom class can be turned into a component.
The role of LiteFlowMethod
is to map your own defined methods to component methods. The other methods are also defined as such.
Notice1
It should be noted here that most methods must pass the parameter NodeComponent bindCmp
, and there must be only one parameter, otherwise an error will be reported, and beforeProcess
and afterProcess
are still defined according to the previous parameters. Note this, see the example above.
In the past, the this
keyword was used to get the context bean, but now you only need to get it from bindCmp.
The name of the method can be defined any way you want. There is no limit to this.
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.
# Switch component declaration
Declaring the switch component requires adding the NodeTypeEnum.SWITCH
parameter to both the class and the method.
@Component("e")
@LiteflowCmpDefine(NodeTypeEnum.SWITCH)
public class ECmp{
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.SWITCH)
public String processSwitch(NodeComponent bindCmp) throws Exception {
System.out.println("Ecomp executed!");
return "g";
}
}
# If component declaration
Declaring the if component requires adding the NodeTypeEnum.IF
parameter to both the class and the method.
@Component("x")
@LiteflowCmpDefine(NodeTypeEnum.IF)
public class XCmp{
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_SWITCH, nodeType = NodeTypeEnum.IF)
public boolean processIf(NodeComponent bindCmp) throws Exception {
//do your biz
return true;
}
}
# For component declaration
Declaring the For component requires adding the NodeTypeEnum.FOR
parameter to both the class and the method.
@Component("x")
@LiteflowCmpDefine(NodeTypeEnum.FOR)
public class XCmp{
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_FOR, nodeType = NodeTypeEnum.FOR)
public int processFor(NodeComponent bindCmp) throws Exception {
//do your biz
return 10;
}
}
# While component declaration
Declaring the While component requires adding the NodeTypeEnum.WHILE
parameter to both the class and the method.
@Component("x")
@LiteflowCmpDefine(NodeTypeEnum.WHILE)
public class XCmp{
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_WHILE, nodeType = NodeTypeEnum.WHILE)
public boolean processWhile(NodeComponent bindCmp) throws Exception {
//get your while flag
boolean flag = xxxxxx;
return flag;
}
}
# Break component declaration
Declaring the Break component requires adding the NodeTypeEnum.BREAK
parameter to both the class and the method.
@Component("x")
@LiteflowCmpDefine(NodeTypeEnum.BREAK)
public class XCmp{
@LiteflowMethod(value = LiteFlowMethodEnum.PROCESS_BREAK, nodeType = NodeTypeEnum.BREAK)
public boolean processBreak(NodeComponent bindCmp) throws Exception {
//get your break flag
boolean flag = xxxxxx;
return flag;
}
}
# Notice
notice
For other methods in the class, they are declared in the same way as processXxx
.