Mapping an attribute using extender mapping

You can use extender mapping to map a BOM attribute to an expression and return an attribute value at runtime.

About this task

You can map a BOM attribute to an expression that returns the value of an attribute at runtime, using extender mapping.

Procedure

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 computed value.
  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 get followed by the name of the attribute.

    When the attribute is static, the extender method has no parameter. In the case of an instance attribute, the extender method takes the execution class type as parameter.

  4. Save the BOM.

Results

The attribute is now mapped to a computed value.

For example, the method that is used when the attribute averageItemPrice is accessed is provided as a Java static method named getAverageItemPrice:

public class CartExtender {
  public static double getAverageItemPrice(ShoppingCart cart) {
    if (cart.getNumberOfItems() == 0)
      return 0;
    return cart.getValue()/ cart.getNumberOfItems();    
  }
}