Independent XOM rules sample details

You use Rule Designer to run this sample.

Make sure that you are in the Rule perspective before running this sample.

To prepare your environment for the sample:
  1. Adjust the filter settings in the Rule Explorer so that BOM to XOM mapping files are visible:
    1. In the Rule Explorer, open the Filters menu.
    2. Deselect the BOM to XOM mapping files entry in the list of elements to exclude.
    3. Click OK.
  2. For this sample, it is also useful to have multiple consoles visible simultaneously.
    1. Click Window > Preferences.
    2. Select Run/Debug > Launching in the list of options and deselect the Remove terminated launches when a new launch is created option.
    3. Click OK.

Running this sample

To run this sample:

  1. Click Run  > Run Configurations.
  2. Select the Rule Project  > bom2xom-rules launch configuration and click Run.

    This runs the sample with the XOM made of generic objects.

  3. Note how the Console view displays the objects:
    type CashEvent accountID=AC1 amount=-120.0 parentID=null type=DEBIT 
    currency=EUR ...

    This format is the one implemented in the toString() method of the generic objects.

  4. Expand the bom2xom-rules> b2x > financialevent-xom folder in the Rule Explorer and copy the file financial.b2x to the bom folder.
  5. Click Yes to confirm replacement of the existing file.

    The project rebuilds automatically.

  6. Run the bom2xom-rules launch configuration again.

    This time, the sample runs with the XOM made of Java™ regular objects.

  7. Note how the Console view displays the objects:
    Type: DEBIT Date:...

    This format is the one implemented in the toString() method of the financialevent xom objects.

    If you have multiple consoles, you can switch between the two traces and compare the execution results.

  8. Expand the bom2xom-rules> b2x> generic-xom folder in the Rule Explorer and copy the file financial.b2x to the bom folder to revert to the initial configuration.
  9. Click Yes to confirm replacement of the existing file.

    The project rebuilds automatically.

  10. Run each launch configuration again, but this time in debug mode.
  11. Click the Step Into icon to step into the rules, into the BOM to XOM mapping translations, and finally into the Java XOM code.

You see that the XOM code called in each run is different.

How this sample works

The Java XOM is defined in financialevent-xom. The whole model uses interfaces and implementation classes. The interfaces are imported to create the BOM.

The generic XOM is defined in bom2xom-generic-xom. It consists of three classes:

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 with one of the following:

As the Java XOM uses constructors to create objects, and the generic XOM requires the GenericObjectHelper 'static factory' to create objects, the choice is 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 simplicity, both configurations use utility classes for currency and date management that belong to the financialevent-xom XOM project. But these can be different.