ILOG JRules User Guide > Creating Rule Projects > Getting Started > Tutorial: Defining a Vocabulary > Step 4: Extend the Business Object Model

In your vocabulary, you need a term for the age of the customer, but in the BOM there is only a birthDate attribute. You can extend the BOM to add the method that corresponds to your needs in the vocabulary, then map it to the XOM.

To add a method to the BOM:

  1. Select the BOM Entry model then, in the Outline view, click the class RentalAgreement.
  2. In the Members section of the Class page, click New.
  3. In the New Member wizard, select Method.
  4. In the Name field, type getCustomerAge.
    In the Type field, click Browse and select the return type int.
  5. Click OK, then Finish.
  6. The method getCustomerAge now appears in the Members section.
  7. In the Members section, double-click the method getCustomerAge.
  8. In the Member Verbalization section, click Create a default verbalization.
  9. A navigation phrase appears with the verbalization of the method getCustomerAge, generated by default as {customer age} of {this}.
  10. Save your work.

When you save, errors are raised because, although the method you added to the BOM is available to you as a navigation phrase in business rules, it does not map to anything executable at the XOM level. You will fix this later, by mapping the method to the XOM.

For the moment, test your new vocabulary element by creating a rule.

To test the new vocabulary:

  1. Create a rule package named Eligibility.
  2. In the Eligibility package, create a business rule named UnderAge.
  3. In the Code section of the Intellirule Editor, type if and press ENTER.
  4. Type the following (start using the keyboard, then use Content Assist):
   the customer age of the rental agreement is less than 18
then
   make it true that the rental agreement is rejected; 
  1. Press ENTER, then press CTRL+SPACEBAR. In the Content Assist box, select `the session'.
  2. Continue editing the rule to have the following result:
if
   the customer age of the rental agreement is less than 18
then
   make it true that the rental agreement is rejected; 
   the session . displayMessage ( "The rental agreement 
                                                    is rejected.");
As you can see, the vocabulary is not as readable as you would expect. In the next Step of the tutorial, you will see how to refine it.
  1. Save your work.

You are now going to correct the errors that were raised when you added a method to the BOM, by mapping it to the XOM. To map the method to the XOM, you need to associate IRL mapping code to the method, in order to compute the actual age of the customer on the date of the pickup, using his birthday.

To map the business method to the XOM:

  1. Select the BOM Entry model in the Rule Explorer. In the Outline view, click the method getCustomerAge.
    Note
    The Outline view shows the selected element in the rule explorer. To see the BOM outline view, select the BOM in the rule explorer.
  2. Scroll down to the bottom of the BOM Editor, and open the BOM to XOM Mapping section.
  3. In the body field, copy and paste the following code:
Calendar birth = Calendar.getInstance();
Customer cust = this.getCustomer();
    birth.setTime(cust.getBirthDate());
        // Create a calendar object with today's date
    Calendar now = Calendar.getInstance();
    now.setTime(this.getPickupDate());
        // Get age based on year
    int age = now.get(Calendar.YEAR) - birth.get(Calendar.YEAR);
       // Add the tentative age to the date of birth 
       // to get this year's birthday
    birth.add(Calendar.YEAR, age);
        // If this year's birthday has not happened yet, 
        // subtract one from age
    if (now.before(birth)) {
        age--;
    }
       return age;
Errors appear because import statements are missing.
  1. Click Edit the imports.
  2. In the BOM to XOM Mapping section, open Imports, and type:
import carrental.Customer;
import java.util.Calendar; 
  1. On the File menu, click Save, then click the Member tab to reopen the BOM to XOM Mapping section for getCustomerAge.
  2. The errors are now resolved, and the method is now properly mapped to the XOM.
  3. In the Rule Explorer, double-click the rule UnderAge.
  4. As you can see, no more warnings appear in the rule.

In the next Step of the tutorial, you will refine the vocabulary to make rules easier to write and understand.

Next Next: Step 5: Refine the Vocabulary