Read Rule Utility:
The method readRule is a utility for reading and compiling a rule file that was generated automatically by the Eclipse Drools Workbench; in general your projects will have one or more rules files that you will load as in this example. In method readRule we opened an input stream reader on the source code for the example Drools rule file Sample.drl. Drools have the ability to modify the rule syntax to create Domain Specific Languages (DSLs) that match your application or business domain. This can be very useful if you want domain experts to create rules since they can “use their own language.” We will not cover custom DSLs in this chapter but the Drools documentation covers this in detail. Here is the rest of the definition of method readRule:
The readRule utility method can be copied to new rule projects that are not created using the Eclipse Drools Workbench and modified as appropriate to get you started with the Java “boilerplate” required by Drools. This implementation uses Drools defaults, the most important being the “conflict resolution strategy” that defaults to first checking the most recently modified working memory POJO objects to see which rules can fire. This produces a depth-first search behavior. We will modify the readRule utility method later in Section 5.4 when we will need to change this default Drools reasoning behavior from depth first to breadth-first search.
We will need a Plain Old Java Object (POJO) class to represent messages in the example rule set. This demo class was generated by the Eclipse Drools Workbench:
public static class Message {
public static final int HELLO = 0;
public static final int GOODBYE = 1;
private String message;
private int status;
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public int getStatus() {
return this.status;
}
public void setStatus( int status ) {
this.status = status;
}
}
}
No comments:
Post a Comment