propertydefinition

The propertydefinition keyword predeclares the types of rule properties.

Purpose

This keyword is used to predeclare the type of rule properties to make rule properties accessible as regular members of the rule and to make type checking possible.

Context

At the top level of rulesets

Syntax

propertydefinition { Type propertyName; } 

Description

You must define rule properties in the propertydefinition section. For example, if a location property is defined in the propertydefinition section, you can write in a rule selection body:

body = select(?rule)   
 {      
   String location = ?rule.location;
   return location.equals("London");
 }

For hierarchical properties, use the hierarchy name as the property type. The property value is type-checked and considered as a string.

Example

hierarchy Geography
{
  "North America" {
    "USA" "Canada"
  }
}

propertydefinition
{
   Geography location;
   java.time.* effectiveDate;
}

rule usa
{
  property location = "USA"
  property effectiveDate = java.time.*(120000);
  when {
    ...
  }
  then {
    ...
  }
}

function void displayRuleProperties()
{
  IlrRule[] rules = getRulesetI().getAllRules();
  for(int i=0; i<rules.length; i++)
   {
    out.println("Location of " + rules[i].getName() + " is " + 
rules[i].?location);
    out.println("Date of " + rules[i].getName() + " is " + 
rules[i].?effectiveDate);
   }
}

A Geography hierarchy is defined. The propertydefinition section predeclares two properties, location and effectiveDate. The usa rule has two properties: location and effectiveDate. Their values are compatible with the type declared in the propertydefinition statement. The displayRuleProperties function displays the properties of the rules (here only usa), made easily accessible by the propertydefinition statement.