ILOG JRules User Guide > Creating Rule Projects > Tasks > Defining How Business Elements Map to the XOM > Implementing Synthetic Objects

A synthetic object allows you to simulate the state of real objects. Like a real object, a synthetic object can store attributes. SDO (Service Data Objects) is an example of a synthetic objects framework.

You can use synthetic objects instead of regular Java objects as application data that is used for execution. You can then use BOM to XOM mapping to implement a complete business object model using only synthetic objects.

To implement synthetic objects using IRL mapping:

  1. In the Outline view, click the class that you want to implement as a synthetic object.
  2. In the BOM Editor, in the BOM to XOM Mapping section, define the mapping of the class and all its members as shown in the example below.
  3. Save the BOM.
  4. The class is now implemented as a synthetic object.

In the following example, the java.util.Map interface is used to implement synthetic objects, where attributes are stored as key-value pairs. Therefore, there is only the regular java.util.Map interface in the XOM.

In the BOM, there is a business class Customer defined as:

Class Customer {
  Customer(String name);
  readonly String name;
  int money;
}

For the name attribute, the getter part of the BOM to XOM mapping is expressed as:

return (String)this.get("name");

For the money attribute, assuming there is always an entry money in the Map containing an Integer, the getter part of the BOM to XOM mapping is expressed as:

return ((Integer)this.get("money")).intValue();

And the setter part is expressed as:

this.put("money",new Integer(value));

Because the same execution class (java.util.Map in this example) may be used for more than one business class, you need to distinguish which instances belong to which business class. This information must be stored in the Map when objects are constructed, and is used by the tester.

To do this, the BOM to XOM mapping body for the constructor would be expressed as:

Map result = new HashMap(3);
result.put("name", name);
result.put("money",new Integer(0)); 
// as assumed, it always contain an Integer
result.put("className", "Customer");
return result;

The tester part of the BOM to XOM mapping for the class Customer uses the className entry to differentiate java.util.Maps:

return "Customer".equals(this.get("className"));

Extender mapping can be used to implement synthetic objects.

To implement synthetic objects using extender mapping:

  1. In the Outline view, click the class that you want to implement as a synthetic object.
  2. In the BOM Editor, in the BOM to XOM Mapping section, specify the name of your extender class in the Extender name field.
  3. In the BOM to XOM Mapping section, specify the name of the execution class in the Execution name field (java.util.Map in the example below).
  4. Define the extender class to provide the mappings for all members of the BOM class, as shown in the example below.
  5. Save the BOM.
  6. The method call is now mapped to an expression.

In this example, the extender class defines all the necessary mappings to the java.util.Map interface.

public class CustomerExtender {
  public static String getName(Map customer) {
    return (String) customer.get("name");
  }
 
  public static int getMoney(Map customer) {
    return ((Integer) customer.get("money")).intValue();
  }
 
  public static void setMoney(Map customer, int value) {
    customer.put("money", new Integer(value));
  }
 
  public static Map create(String name) {
    Map result = new HashMap(3);
    result.put("name", name);
    result.put("money", new Integer(0));
    // as assumed it always contains an Integer
    result.put("className", "Customer");
    return result;
  }
 
  public static boolean tester(Map customer) {
    return "Customer".equals(customer.get("className"));
  }
}

Related Concepts

Business Object Model (BOM)
Execution Object Model (XOM)
BOM and XOM

Related Tasks

Defining How Business Elements Map to the XOM
Managing XOM Changes in the BOM

Related Reference

BOM Editor
ILOG Rule Language

Related Samples and Tutorials

Tutorial: Defining a Vocabulary