| Samples > Rule-Based Programming > How to Write Rules Independently of the Execution Model |
How to Write Rules Independently of the Execution Model |
PREVIOUS NEXT |
This sample shows how to use the Business Object Model (BOM) to Execution Object Model (XOM) mapping mechanism to isolate rules from the "physical" execution layer.
The same rules can sometimes be applied on different execution applications and platforms. For example:
In this sample, a single BOM is mapped to two very different XOMs.
The BOM was initially designed for regular Java static classes and has been remapped to a model made of generic objects (also called synthetic, or dynamic objects) made of key-value properties, such as hash maps. The same BAL rules can be executed on the two execution layers.
The sample is derived from the engine > patternmatching sample (the Java XOM is shared, and the rules have been rewritten in BAL). The execution results are the same.
Key features include:
To import the bom2xom sample:
samples > engine > bom2xom sample.
The imported sample project files are displayed in the Rule Explorer.
Make sure that you are in the Rule Perspective before running this sample.
To prepare your environment for the sample:
BOM to XOM mapping files entry in the list of elements to exclude.
To run the sample:
Rule Project > bom2xom-rules launch configuration and click Run.
b2x > financialevent-xom folder in the Rule Explorer and copy the file financial.b2x to the bom folder.
bom2xom-rules launch configuration again.
bom2xom > generic-xom folder in the Rule Explorer and copy the file financial.b2x to the bom folder to revert to the initial configuration.
You will see that the XOM code invoked in each run is different.
The Java XOM is defined in financialevent-xom. The whole model is based on interfaces and implementation classes. The interfaces have been imported to create the BOM.
The generic XOM is defined in bom2xom-genericxom. It consists of three classes:
GenericObject interface that describes the contract of a generic object. In contrast to a Map contract, it adds:
getInt/setInt, getDouble/setDouble, etc.
GenericObject instances.
getType() and isOfType(String) methods, to support object models with inheritance.
GenericObjectImpl implementation of GenericObject:
HashMap.
GenericObjectHelper described below.
GenericObjectHelper helper class that implements the type system and creates generic objects:
GenericObject implementation class, for the creation of objects.
subtype->supertype. The types are stored statically in this class, and are themselves instances of GenericObject.
model.properties file if the file is present in the classpath.
The generic XOM is completed by an adapter XOM, called bom2xom-extenderxom, which is specific to this sample and is defined in the bom2xom-extenderxom project. This provides an extender class for one of the BOM classes, and a model.properties that models the extension relationship between CashEvent and FinancialEvent classes.
As a generic object model does not support behavioral methods (that is, methods other than accessors and mutators), these methods are implemented either with:
Account.addBalance BOM methods.
bom2xom-extenderxom project. For example, see the EventDispatcher class: the exception and send methods are delegated to the DispatcherExtender class, with static methods.
As the Java XOM uses constructors to create objects, and the generic XOM requires the GenericObjectHelper 'static factory' to create objects, the choice has been to create static BOM 'create' methods on each BOM class. These methods are translated into calls to the appropriate constructors in the case of the Java XOM, and into calls to the GenericObjectHelper.create(String type) static method in the case of the generic XOM.
For the sake of simplicity, both configurations use utility classes for currency and date management that belong to the financialevent-xom XOM project. But these could have been different as well.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |