Try OpenEdge Now
skip to main content
Application Developer's Guide
Using the Rule Wizard framework

Using the Rule Wizard framework

The Rule Wizard Framework facilitates building the wizards that generate rule files for solving a specific business problem. A wizard is a sequence of pages which guides users through defining a rule while they enter data. After data is entered, a rule module addressing the specific business problem is generated. To define a wizard, you must define the data structures required to hold the parameters, the GUI, and the code generation—all contained in a rule template in XML format.
When deciding to build a rule wizard for a specific task, consider the following input components:
*The business problem to solve along with its solution using rules.
*The parameters leading to variations in the rules module which solves the problem.
*The GUI requirements which allow the user to specify values for the parameters mentioned in the above point.
The rule wizard Framework facilitates wizard building by:
*Making possible the building of the wizard GUI without any Java code in some cases or by designing simple components in other cases.
*Providing a powerful macro language (Velocity) in which the rule template writer can express variations of the rules according to the parameters.
After defining the business problem and its solution using parameterized rules, the rule template writer completes the following tasks:
1. Design the data structures or macros holding the parameters.
2. Design the GUI.
3. Write the code generation portion.
The following example illustrates this process without generating valid rule language code, but uses only the data entered by the user. The rule template follows, using the simplest data structure available—a string:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE template SYSTEM "resources/ruleTemplate.dtd" >
<template name="ex1">
<screen number="10">
    <editor macro="text" label="Text"/>
<macro name="text" type="varname"/>
Hello, you entered $text.
Now run the Rule Wizard using this rule template as input:
RuleWizard -t ex1.rtu
where -t option is used for specifying the RuleTemplate file name.
The RuleWizard.cmd file is located in the OEBPS_HOME\bin directory. Assume that the OEBPS_HOME\bin directory is in your PATH and that the sample code is saved in the file ex1.rtu. The extension .rtu stands for "rule template unit."
The <template> tag describes the rule template unit. The <screen> tag represents a step in the wizard. The <macro> tag is the only data structure used in this rule template. Rule Wizard provides some predefined macro types. A macro type defines the data type and also specifies a default editor. For example, the type varname specifies the need for a string conforming to the variable name restriction in the Java language. The editor is a simple JTextField.
The <editor> tag appears in the first step of the wizard, as it is contained on the first screen of the template. A label is specified—in the example, "Text"—and displayed beside the editor requesting the user to enter the required information.
The Text box appears when running the wizard, as shown in Figure 23.
Figure 23. Rule wizard example 1
Click Finish to verify the varname type of the macro you specified as well as the validations performed. If you type a legal value, such as Example and click Finish again, then the following message appears on the console:
Hello, you entered Example.
Notice that, in the code generation portion within the <text> tag, you can retrieve the value of the text macro by writing $text.
To add more steps to the wizard, repeat the process by duplicating the tags shown in the first example. Macro names must be unique in a template, editors must be associated to a macro, and pages are ordered according to the values in their number attribute.
In the case of Schedule Wizard, you can specify the application name while invoking RuleWizard.
For example,
-t %OEBPS_HOME\templates\Schedule.rtu -a Assignment
-e %OEBPS_HOME%\ebmsapps\%app%\rules\SC_instancename_param.rtp.
-t option is used for specifying RuleTemplate file name.
-a option is used for specifying application name.
-e option is used for specifying the ruletemplate parameter file name.
* Composing macros and editors
* Controlling the layout
* Specifying alternatives
* Collecting macros
* Using editors in separate dialogs
* Code generation
* Standard macro types
* How to write additional macros and editors
* Skipping a macro