ILOG JRules User Guide > Creating Rule Projects > Tasks > Defining How Business Elements Map to the XOM > Mapping an Attribute Assignment to a Function

You can map a BOM attribute to an expression that sets the value of this attribute at runtime.

To map an attribute assignment to a function using IRL mapping:

  1. In the Outline view, click the attribute that you want to map to a function.
  2. In the BOM Editor, in the BOM to XOM Mapping section, type an IRL statement that sets the value of the attribute in the Setter field. Use this to represent the current object.
  3. Save the BOM.
  4. The attribute setter is now mapped to a function.

In this example, there is a class ShoppingCart in the XOM which contains a method that sets the number of items in a shopping cart and a method that sets the total value of all the items.

// Execution class
public class ShoppingCart {
   public void setValue(int value) ...
   public void setNumberOfItems(int number) ...
}

In the BOM there is an attribute that represents the average item price and which is set using an expression.

// BOM class
public class ShoppingCart {
   public double averageItemPrice;
   ...
}

The expression that sets the value of the attribute is expressed in the body of the attribute setter as:

this.setValue(value*this.getNumberOfItems());

Extender mapping can be used to map an attribute to a computed value.

To map an attribute to a computed value using extender mapping:

  1. In the Outline view, click the class containing the attribute that you want to map to a function.
  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. Define the attribute as a Java static method named set followed by the name of the attribute. When the attribute is static, the extender method takes the execution class corresponding to the attribute type as parameter. In the case of an instance attribute, the extender method takes two parameters: the execution class type, and the execution class corresponding to the attribute type.
  4. Save the BOM.
  5. The attribute is now mapped to a function.

In this example, the method that is used when the attribute averageItemPrice is accessed is provided as a Java static method named setAverageItemPrice.

public class CartExtender {  
  public static void setAverageItemPrice(ShoppingCart cart, double v) {
    cart.setValue(cart.getNumberOfItems()*v);
  }
}

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