ILOG JRules User Guide > Creating Rule Projects > Tasks > Defining How Business Elements Map to the XOM > Mapping a Constructor Call to an Expression

You can map a constructor call to any expression.

To map a constructor call to an expression using IRL mapping:

  1. In the Outline view, click the constructor that you want to map to an expression.
  2. In the BOM Editor, in the BOM to XOM Mapping section, type the expression as an IRL statement in the Body field.
  3. Save the BOM.
  4. The method call is mapped to the expression.

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:

  1. In the Outline view, click the class containing the constructor that you want to map to a expression.
  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 constructor as a Java static method named 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.
  4. Save the BOM.
  5. The constructor call is now mapped to an expression.

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;
  }
}

Related Concepts

Business Object Model (BOM)
Execution Object Model (XOM)
BOM and XOM

Related Tasks

Defining How Business Elements Map to the XOM
Managing XOM Changes in the BOM

Related Reference

BOM Editor
ILOG Rule Language

Related Samples and Tutorials

Tutorial: Defining a Vocabulary