Visual Rules Solution Java Integration Interface <2>—Java class calls native calls

Specify the rule compilation file directory, and call the rule compilation file under the default version in the specified directory, which is the version default. If there is no specified version, the internal convention of VisualRules calls the rule compilation file under the version default. For example, the specified directory is E:\ rscfile, the default version directory E:\rscfile\default.

Add a java test class Add a java class named Test1.java
to the java project and edit the content as follows:
package com.flagleader;
import java.io.File;
import java.util.List;
import com.flagleader.engine. RuleEngine;
import com.flagleader.engine.RuleEngineException;
import com.flagleader.engine.RuleEngineFactory;
import com.flagleader.engine.RuleEngineManager;
/**
* Call the compiled file under the default file in the specified directory
* The RuleEngine is used, which Interface can only be used for local calls
* @author Administrator
*/
public class Test1 {
public static void main(String[] args) {
try {
//The specified directory for the compilation file, the default version directory is the default
RuleEngineManager.getInstance().init(new File("e:\\rscfile"));
//Factory mode, this interface can only be used for local calls
RuleEngine engine = RuleEngineFactory.newInstance().getRuleEngine();
//Pass parameters in the form of dto as rules
Student student = new Student(1,"Li Li",12,'male',"sixth grade","none") ;
//Execute the rule, where "student.add" is the full name of the rule, and student is the incoming parameter
engine.executeBeans("student.add", student);
//After executing the rule, get data, "studentList" must be the same as The variable name of the memory table data in the rule is the same.
List list=engine.getListList("studentList");

1. Version: The version here refers to the file in the specified directory
2. Rule compilation file: This rule package external call name

// due to The list<list> type is used in the rules, and two conversions are required.
List list1=(List)list.get(0);
//The number of loops is the number of fields in the object
for (int i = 0; i < 6; i++) {
System.out.print(list1.get(i)+"\t");
}
} catch (RuleEngineException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}


Execute java test class

Click to execute After that, you can see the following results:





it means that the student.add rule package has been called, and according to the passed parameters, the returned processing results are displayed in the form of list<list>.
Similarly, any other java class can complete the work of calling the rule package by adding the above code.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326757047&siteId=291194637