Samples > Rule Engine Integration > How to Run Rules Against XML Objects

This sample shows how to write BAL rules to process XML data. The sample application reads a batch XML file of financial events, executes a set of rules on those events, then outputs a modified event batch to an XML file.

The sample can only be opened and run in Rule Studio.

Key Features

Key features include:

Importing this Sample

To import the xmlbinding sample:

  1. Click File > Import.
  2. In the Import Wizard, select ILOG Rule Studio Samples and Tutorials then click Next.
  3. Select the sample samples > architecture > xmlbinding.
  4. Click Finish.
  5. If one or more files already exist in your workspace, a warning message is displayed indicating the file(s) were not re-imported. Click OK to close the message window.
  6. The imported sample project files are displayed in the Rule Explorer. You should see three new projects:
    - xmlbinding-xom
    - xmlbinding-rules
    - xmlbinding-application

Running this Sample

Start by running the xmlbinding-rules rule project, then run the xmlbinding-application Java Application.

To run the xmlbinding-rules rule project:

  1. Click Run > Run.
  2. Select the Rule Project > xmlbinding-rules launch configuration, then click Run.
  3. Output is displayed in the Console view:
Start processing of a new event of class : financial.CashEvent
 ID_R4
 
 CREDITCARD
 2004-01-23
 null
 false
 123
 -80.0
 EUR
 456
 
Start processing of a new event of class : financial.CashEvent
 ID_R3
 
 TRANSFER
 2004-01-23
 null
 false
 123
 23.0
 EUR
 456
 
Start processing of a new event of class : financial.CashEvent
 ID_R2
 
 CREDIT
 2004-01-16
 null
 false
 456
 150.0
 EUR
 123
 
Start processing of a new event of class : financial.FinancialEvent
 ID_R1
 
 OPENING
 2004-01-14
 null
 false
 123
 
Acknowledge processing of event ID_R2 by event ID1
Start processing of a new event of class : financial.FinancialEvent
 ID1
 ID_R2
 ACKNOWLEDGEMENT
 2004-01-16
 null
 false
 456
 
Finish processing of event ID1
Finish processing of event ID_R2
Start processing of a new event of class : financial.CashEvent
 ID2
 ID_R4
 DEBIT
 2004-01-23
 null
 false
 123
 -80.0
 EUR
 null
 
Start processing of a new event of class : financial.FinancialEvent
 ID3
 ID2
 CASHBACK
 2004-01-23
 null
 false
 123
 
Start processing of a new event of class : financial.CashEvent
 ID4
 ID3
 REFUND
 2004-01-23
 null
 false
 123
 4.000000059604645
 EUR
 null
 
Start processing of a new event of class : financial.CashEvent
 ID5
 ID4
 CREDIT
 2004-01-23
 null
 false
 123
 4.000000059604645
 EUR
 null
 
Acknowledge processing of event ID5 by event ID6
Start processing of a new event of class : financial.FinancialEvent
 ID6
 ID5
 ACKNOWLEDGEMENT
 2004-01-23
 null
 false
 123
 
Finish processing of event ID6
Finish processing of event ID5
Finish processing of event ID4
Finish processing of event ID3
Finish processing of event ID2
Finish processing of event ID_R4
Start processing of a new event of class : financial.CashEvent
 ID8
 ID_R3
 DEBIT
 2004-01-23
 null
 false
 456
 -23.0
 EUR
 null
 
Start processing of a new event of class : financial.CashEvent
 ID7
 ID_R3
 CREDIT
 2004-01-23
 null
 false
 123
 23.0
 EUR
 null
 
Acknowledge processing of event ID8 by event ID9
Start processing of a new event of class : financial.FinancialEvent
 ID9
 ID8
 ACKNOWLEDGEMENT
 2004-01-23
 null
 false
 456
 
Finish processing of event ID9
Finish processing of event ID8
Acknowledge processing of event ID7 by event ID10
Start processing of a new event of class : financial.FinancialEvent
 ID10
 ID7
 ACKNOWLEDGEMENT
 2004-01-23
 null
 false
 123
 
Finish processing of event ID10
Finish processing of event ID7
Finish processing of event ID_R3
Error: event ID_R1 is unprocessed
Balance of account 456 = 358.75 USD
Balance of account 123 = 527.00 EUR

To run the xmlbinding-application Java application:

  1. Click Run > Run.
  2. Select the Java Project > xmlbinding-application launch configuration, then click Run.
  3. Output is displayed in the Console view and is identical to the previous output, with the addition of one extra line:
67 rules fired

Both these launch configurations work in a similar manner. The main difference is that the xmlbinding-rules configuration runs the ilrmain main function, whereas xmlbinding-application runs a java main class.

In each case, the program:

Both launch configurations can be run in debug mode to step through the agenda, browse the contents of the working memory and so on.

Highlights

The model BOM is created from the schema financial.xsd stored in the xmlbinding-xom project. This BOM is verbalized with the default verbalization, and enhanced with a few manual additions that rely on BOM to XOM mappings (for creating events, adding amounts to an account and so on).

The util BOM is created and verbalized using the Helper class in the xmlbinding-xom project. Other virtual members have been added (mainly declare/undeclare methods to support insert/retract in the working memory).

By combining ruleset variables and static BOM methods that use BOM to XOM mapping to encapsulate constructors and the insert keyword, you can create the following type of construction for creating objects with rules:

   set 'new cash event' to a new empty cash event  ;
   set the type of 'new cash event' to "CREDIT" ;
   ...
   insert 'new cash event' ;

Related Concepts

XML Binding
BOM and XOM

Related Tasks

Defining the Execution Object Model

Related Reference

Editing the Verbalization of Ruleset Variables
Editing the Verbalization of Ruleset Parameters

Related Samples and Tutorials

Import Samples and Tutorials Wizard