Declaring ownership relations on BOM classes to simplify rules

You can declare an ownership relation between BOM classes to simplify rules that refer to these elements.

About this task

In the BOM editor, you use the ownershipRelation property to declare an ownership relation between elements. You can then access these elements in the rules through this relation.

Procedure

  1. Open the BOM Editor in Rule Designer.
  2. In the BOM Editor, open the class that stands for the owned element in the ownership relation that you want to declare.
  3. In the Custom Properties section, click Add.

    A new custom property is created.

  4. In the Name column, click newProp and type ownershipRelation.
  5. In the Value column, type <class name>.<attribute name>, where <class name> is the fully qualified name of the owner class, and <attribute name> is the name of the attribute of the owner class that constitutes the ownership relation between the owner class and the owned class.
    For example, if you want to declare that the class Vehicle in the com.ibm.rules package is owner of the class Coverage, type com.ibm.rules.Vehicle.coverages.

Example

In the following example, the Policy class contains vehicles members, which are defined in the Vehicle class. The following rule contains a definition that explicitly defines a relation between these elements, and instances of the vehicle object are accessed by using this relation in the condition part of the rule:
definitions
    set 'the policy' to a policy;
    set 'the vehicle' to a vehicle in the vehicles of 'the policy';
if
    the age of 'the vehicle' is at least 5
then
    print "This vehicle is too old." ;
You can simplify this rule by declaring that the Vehicle class is owned by the Policy class directly in the BOM elements. To do so, you add the ownershipRelation property to the custom properties of the Vehicle class, and set its value to com.ibm.rules.Policy.vehicles. You can now write a simplified version of the rule:
definitions
    set 'the vehicle' to a vehicle;
if
    the age of 'the vehicle' is at least 5
then
    print "This vehicle is too old." ;

Here the definition clause does not contain an in or from construct, and the instances are accessed through the ownership relation. The rule is evaluated for each vehicle in the list of vehicles of each policy that is available in the working memory. When no ownership relation is defined, and no in or from constructs are used, rules can only access instances that are directly available in the working memory.

You can write an even shorter version of the rule by using the automatic variable for the vehicle:

if
    the age of the vehicle is at least 5
then
    print "This vehicle is too old." ;