Visual Rules Solution Java Integration Interface <4>—Java Class Calls Locally Calls the Specified Version

Specify the rule to compile the file directory, call the compiled file of the default file in the specified directory, not only the specified file \default, if the specified directory is E:\rscfile, then the default file directory refers to E:\rscfile\default, in order to be able to call different versions of the file For the compiled file with the same name, you can choose a directory, such as E:\rscfile\1.1 or E:\rscfile\1.2, so that the compiled file under 1.1 or 1.2 will be executed.

Add a java test class Add a java class named Test3.java
to the java project, and edit the content as follows:
package com.flagleader;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.flagleader.engine.RuleEngine;
import com.flagleader.engine.RuleEngineException;
import com.flagleader.engine.RuleEngineFactory;
import com.flagleader.engine.RuleEngineManager;
import com.flagleader.engine.RuleService;
import com.flagleader. engine.RuleServiceException;
import com.flagleader.engine.impl.LocalRuleServiceFactory;
/**
* Call the compiled file under the default file in the specified directory
* Use RuleEngine, this interface can only be used for local calls
* You can specify which version of the compiled file to execute in the directory.
* Such as RuleEngineFactory.getInstance("1.1").getRuleEngine();
* @author Administrator
*/
public class Test3 {
public static void main(String[] args) {
try {
// The specified directory of the compiled file, the default version directory is specified Default
RuleEngineManager.getInstance().init(new File("e:\\rscfile"));
// Factory mode, this interface can only be used for local calls, 1.1 in getInstance("1.1") is specified The file name in the directory
RuleEngine engine = RuleEngineFactory.getInstance("1.1").getRuleEngine();
// Passing parameters in the form of dto as a rule
Student student = new Student(1, "Li Li", 12, 'male', " sixth grade", "none");
// enforce the rules, where "student.
engine.executeBeans("student.add", student);
// Determine if engine.get("studentList") is a collection type
// After executing the rule, get the data, "studentList" must be the same as the memory table data in the rule The variable names are the same.
List list = engine.getListList("studentList");
// Since the list<list> type is used in the rules, two conversions are required.
List list1 = (List) list.get(0);
// Loop The number of times 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 the java test class After
clicking execute, you can see the following results:



After clicking execute, you can see the following results:



The student.add rule package has been called, and According to the incoming 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=326918234&siteId=291194637