-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistrule.drl
More file actions
38 lines (35 loc) · 1.22 KB
/
distrule.drl
File metadata and controls
38 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import dist.common.rules.define.*
import java.util.List
import org.w3c.dom.Document
import org.w3c.dom.Element
import dist.dgp.controller.Person
//在规则文件当中定义的函数
function Element createElement(Document document,Person person){
Element element=document.createElement("person");
element.setAttribute("name",person.getName());
element.setAttribute("birth",person.getAge().toLocaleString());
element.setAttribute("id",person.getId().toString());
element.setAttribute("school",person.getSchool());
return element;
}
rule "DemoCase"
no-loop true
salience 1
date-effective "2015-01-01"
date-expires "2017-01-01"
when
obj:RuleObject(source!=null,source instanceof List)
then
try {
List<Person> list=(List<Person>) obj.getSource();
Document document=CommonUtil.createDocument();
Element root=document.createElement("tree");
for(Person person:list){
root.appendChild(createElement(document,person));
}
document.appendChild(root);
obj.setResult(CommonUtil.XMLToString(document));
} catch (Exception e) {
e.printStackTrace();
}
end