| ILOG JRules User Guide > Creating Rule Projects > Tasks > Defining How Business Elements Map to the XOM > Mapping a Constructor Call to an Expression |
Mapping a Constructor Call to an Expression |
PREVIOUS NEXT |
You can map a constructor call to any expression.
To map a constructor call to an expression using IRL mapping:
In this example, there is a class Customer in the XOM that contains an age attribute, and a constructor that takes the name of the customer as parameter:
// Execution class
public class Customer {
public Customer(String name);
public int age;
}
In the BOM, there is a different constructor that takes the name and the age of the customer:
public class Customer {
public Customer(String name, int age);
}
The body of the constructor BOM to XOM mapping is expressed as:
Customer result = new Customer(name); result.age = age; return result;
Extender mapping can be used to map a constructor call to an expression.
To map a constructor call to an expression using extender mapping:
create. The return type of the extender method must map to the execution class. If the method is static, its parameters adopt the same execution types as the constructor parameters. In the case of an instance method, the first parameter must be the execution class type followed by the other parameters with execution types, as for a static method.
In this example, the method that is used when the constructor is called is provided as a Java static method called create.
public class ExtCustomer {
public static Customer create(String name, int age) {
Customer c = new Customer(name);
c.setAge(age);
return c;
}
}
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |