The Guided Editor (Rule GUI)

A new feature of the Drools IDE (since version 4) is the guided editor for rules. This is similar to the web based editor that is available in the BRMS. It allows you to build rules in a GUI-driven fashion, based on your object model.

Figure 7.8. The guided editor

The guided editor

To create a rule this way, use the wizard menu. It will create an instance of a .brl file and open it in the guided editor. This editor works based on a .package file in the same directory as the .brl file. In this "package" file you have the package name and import statements - just like you would at the top of a normal DRL file. First time you create a brl rule you will need to populate the package file with the fact classes you are interested in. Once you have this, the guided editor will be able to prompt you with facts and their fields so that you can build rules graphically.

The guided editor works off the model classes (or fact classes) that you configure. It then is able to "render" to DRL the rule that you have entered graphically. You can do this visually - and use it as a basis for learning DRL, or you can use it and build rules of the brl directly. One way to do this is by using the drools-ant module, which is an ant task that creates all the rule assets in a folder, as a rule package, so that you can then deploy it as a binary file. Alternatively, you can use the following snippet of code to convert the brl to a drl rule.

BRXMLPersitence read = BRXMLPersitence.getInstance();
BRDRLPersistence write = BRDRLPersistence.getInstance();
String brl = ... // read from the .brl file as needed...
String outputDRL = write.marshall(read.unmarshal(brl));
// Pass the outputDRL to the PackageBuilder, as usual