IBM BPM, V8.0.1, All platforms > Authoring services in Integration Designer > Developing monitor models > Create monitor models > Authoring XPath functions > Examples of XPath functions
Example of a mathematical function
Mathematical functions are one of several XPath 2.0 functions supported in model expressions in IBM Business Monitor. Define mathematical XPath functions for use in monitor model XPath expressions.
The following code exemplifies the use of the mathematical user-defined XPath function:
import java.math.BigDecimal; import java.math.BigInteger; import com.ibm.wbimonitor.xml.expression.udf.XPathFunction; public class Examples { public static final String NAMESPACE = "http://www.jimbo.org/beverages/functions"; private static int UnitsPerCase[] = { 24, 12, 24, 32, 24, 12, 24, 32, 24, 24, 24, 24,}; private static double UnitCosts[] = { 1.25, 2.25, 0.75, 0.50, 2.00, 3.00, 1.25, 1.00, 3.00, 4.00, 2.00, 1.50,}; private static double MarkUpPercentage[] = { .75, .75, .75, .75, .85, .85, .85, .85, 1.0, 1.0, 1.0, 1.0,}; @XPathFunction( namespaceName = NAMESPACE, localName = "determineExpectedProfit", description = "(units, cases) Determine the expected profit for this order.", isSelfContained = true, isDeterministic = false ) public static BigDecimal determineExpectedProfit(final BigInteger units, final BigInteger cases) { // a) determine how many units there are // b) determine per unit price // c) determine markup value // d) determine rawCost ( NumberOfUnits times unit price) // e) tack on mark-up int NumberOfCases = cases.intValue(); int Units = units.intValue()-1; int Units_per_Case = UnitsPerCase[Units]; double unitCost = UnitCosts[Units]; double markUpRate = MarkUpPercentage[Units]; int NumberOfUnits = NumberOfCases * Units_per_Case; double rawCost = NumberOfUnits * unitCost; double PriceToCharge = (rawCost * markUpRate) + rawCost; return new BigDecimal(PriceToCharge);} }