You can use extender mapping to map an attribute assignment
to a function.
About this task
You can map a BOM attribute to an expression that sets
the value of this attribute at runtime, using extender mapping.
Procedure
To map an attribute to a function using extender mapping:
- In the Outline view, click the class
containing the attribute that you want to map to a function.
- In the BOM Editor, in the BOM to XOM Mapping section,
specify the name of the extender class in the Extender
name field.
- 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.
- Save the BOM.
Results
The attribute is now mapped to a function.
For
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);
}
}