Modified BOM core types sample details

You use Rule Designer to run this sample.

Running this sample

To use the run configuration:

  1. Click Run  > Run Configurations. Expand Decision Operation, select the bomextensions launch configuration, and then click Run.
  2. The Console view displays the output that is generated by the rule project.

How this sample works

Development languages do not natively support typed numbers. This means that you can combine values that are expressed in different units. For example, 1 Euro - $1 = 0?.

With the techniques that are described in this sample, you can extend the BOM and vocabulary to support manipulation of typed numbers, such as percentages, currencies, and any other numeric values of a specific type.

The sample provides reusable .bom, .voc and .b2xa files that you can incorporate into or use as templates for your projects:

  • brl_extensions.bom
  • brl_extensions_en.voc
  • brl_extensions.b2xa

This BOM defines a Percentage BOM virtual class, which you can use in the same way as the Number class, except that you cannot use percentage values everywhere in a business rule in place of any other number. Furthermore, you cannot mix a percentage semantically with other numbers. For example, the operation 15% + 18 is meaningless.

As a consequence, the Percentage class redefines most of the operators and phrases that are defined on the Number type: it removes irrelevant operators, decorates the type with a %, and puts a suffix on literal values with this symbol, for example: 15%. The Percentage type maps to the primitive double type using the BOM-to-XOM mapping execution name.

This BOM also defines CurrencyDollar and CurrencyEuro BOM virtual classes, you can also use in the same way as a Number, but which does not extend the Number class (because currency values cannot be used everywhere where a number can). The CurrencyDollar and CurrencyEuro BOM classes map to the primitive double type using the BOM-to-XOM mapping execution name.

The sample also contains a second BOM that demonstrates the use of these Percentage, CurrencyDollar, and CurrencyEuro virtual classes in rules. This BOM includes a simple virtual Item class, which maps to a Map through the BOM-to-XOM mapping mechanism.

The rule project contains just one rule, useExtensions, which uses percentages and currencies in BAL rules. The sole purpose of this rule is to show various ways in which you can express and combine percentages and currency values.

The launch configuration that is provided runs the rule to check that everything is interpreted and run as expected.

To modify the behavior of core BOM classes, the resources folder of the sample contains a boot.bom file, a boot_en.voc file, and a boot.b2xa file, which you can edit and incorporate into your projects. You must open the Java™ perspective to view these files.

Attention: In a rule project, if the boot BOM file is overridden, you must not remove predicates that are attached to the boot type, such as Object.is(), Object.isNot(), or Number.isGreaterThan(). Removing them affects decision table and decision tree features.