| ILOG JRules User Guide > Creating Rule Projects > Tasks > Defining How Business Elements Map to the XOM > Accessing Functions from IRL Mapping Code |
Accessing Functions from IRL Mapping Code |
PREVIOUS NEXT |
You can access functions from the IRL mapping code. Extender mapping does not allow you to do this.
To access functions:
IlrContext.invokeFunction to access the function.
For example, suppose you have a BOM class ShoppingCart with an attribute public readonly double averageItemPrice.
In your rule project, there is a function that computes the average price of the items in a shopping cart:
function double computeAveragePrice(ShoppingCart cart) {
if (cart.numberOfItems != 0)
return cart.value / cart.numberOfItems;
return 0;
}
This IRL function is based on the BOM, not the XOM.
To map the averageItemPrice attribute to a call to the computeAveragePrice function, you can write the following IRL mapping code for the attribute averageItemPrice:
Double result = (Double) invokeFunction("computeAveragePriceShopping",
new Object[] {this});
return result.doubleValue();
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |