Accessing decision engine and related artifacts from ARL mapping code

You can access the decision engine and its related artifacts, by writing ARL mapping code in the BOM-to-XOM mapping section of the BOM Editor.

About this task

The engine and other related artifacts can be accessed directly from the Advanced Rule Language (ARL) mapping code.

Note: You cannot use extender mapping to access the engine, ruleset variables, parameters, and rules.
When you write the ARL mapping code in the Body field, you associate it with a number of classes:
  • The current object, if you write the body for a non-static member.
  • The RunningEngineWithWorkingMemory, which represents the engine that is running.
  • The RuleInstance, which is null if the body is not called within a rule action.
  • The TaskInstance, which is null if the body is not called within a task execution.
  • The $EngineData class, which is a generated class that extends the EngineData interface, and contains the ruleset parameters and variables.
As in Java, when there is no ambiguity, you can directly refer to a member by its name. However, when there is ambiguity, you can follow the Java dot notation for accessing containing instances:
ContainingClass.this.member
The following frequently used packages are imported so that you can declare them in the Import field without ambiguity:
  • java.lang.*
  • com.ibm.rules.engine.runtime.*
  • com.ibm.rules.engine.ruledef.runtime.*
  • com.ibm.rules.engine.ruleflow.runtime.*

Procedure

  1. In the Outline view, click the member that contains the ARL mapping that you want to edit.
  2. In the BOM Editor, open the BOM-to-XOM mapping section, and then go to the ARL statement in the Body field.
  3. You have the following options:
    Option Description
    Accessing running engine members from ARL mapping code

    Use RunningEngineWithWorkingMemory API to access the running engine members.

    You can use ARL mapping to stop the running engine:
    stop("stop by ARL mapping of method M");
    If your API call is ambiguous, it can be written by using the notation for accessing the enclosing class.
    RunningEngineWithWorkingMemory.this.stop("stop by ARL mapping of method M");
    Accessing rule instance from ARL mapping code

    Use RuleInstance API to access the rule instance members.

    You can use ARL mapping to add a trace:
    if (RuleInstance.this != null)
      note("ARL mapping of method M being called by rule "+ ruleName);
    If your API call is ambiguous, it can be written by using the notation for accessing the enclosing class.
    if (RuleInstance.this != null)
      note("ARL mapping of method M being called by rule "+ com.ibm.rules.engine.ruledef.runtime.RuleInstance.this.ruleName);
    Accessing ruleset variables and parameters from ARL mapping code

    Use EngineData API to access the ruleset variables and parameters.

    You can use ARL mapping to get the value of a ruleset parameter:
    param;
    or
    Object v = get("param");

    You might access a variable declared in the top level package the same way. For a variable within a named package, for example variable size in us.california, you might access it by using `pckus.california`.size.

    Note: Adding 'pck' to the name of the top level package, and the usage of back-quotes. Back-quotes allow you to use names that cannot be parsed directly as identifiers.
    Setting ruleset variables and parameters from ARL mapping code

    Use EngineData API to access the ruleset variables and parameters.

    You can use ARL mapping to set the value of a ruleset parameter or variable:
    param = v;
    If your API call is ambiguous, it can be written by using the notation for accessing the enclosing class.$EngineData.this.param = v;. After setting such value, you need to call the update methods of the engine, as when using RetePlus, the engine has to be notified of such a change to reevaluate the candidate rules. This can achieved by calling 2 methods of RunningEngineWithWorkingMemory:
    updateData();
    updateGenerators()

    If those methods are called while using an algorithm that is not RetePlus, they do not have an effect.

    You can modify a variable declared in the top-level package in the same way. For a variable within a named package, for example a variable size in us.california, you can modify it using `pckus.california`.size = 423970;

    Note: Adding 'pck' to the name of the top level package, and the usage of back-quotes. Back-quotes allow you to use names that cannot be parsed directly as identifiers.
  4. Save the BOM.

Results

You access the engine, ruleset variables, parameters, and rules directly from the BOM Editor, in which you edit the ARL mapping code.