Example: Redefinition of the root structure of a business rule language

As an example of implementing a new root node, you can add a root node for the Business Query Language (BQL). You must also provide a root node translator.

Deprecated feature:

Deprecation icon Support for custom business rule languages is deprecated in V8.8.1. This feature will be removed in a future release of the product. See Deprecated features for migration details.

If you want to provide a new root node for the abstract syntax, that is, if you want to create a completely new rule language, you must provide a specific root node translator.

The root node translator is in charge of creating the IlrRuleStatement instance, and completing the structure by calling context.processNode on the subnodes.

For example, you implement the root node (T-class-rule) of the Business Query Language (BQL) as follows:

public static class ClassRuleNodeTranslator implements IlrNodeTranslator
{
  public IlrStatement process(IlrSyntaxTree.Node node,
                              IlrTranslationContext context) {
    // BQL generates one rule
    IlrRuleStatement rule = new IlrRuleStatement(node);
    IlrIntermediateForm iform = context.getIntermediateForm();
    iform.setRuleStatement(rule);
    
    // Binding is implicit in BQL
    IlrConcept ruleQueryConcept = 
                context.getVocabulary().getConcept("bql.RuleQuery");
    rule.addConditionStatement(new IlrSimpleBindingStatement(node, 
                                      "ruleQuery", ruleQueryConcept));
    
    // Process class condition
    IlrSyntaxTree.Node classCondNode = node.getSubNode("class-condition");

    // Process the condition part
    context.setCurrentRulePart(IlrTranslationContext.CONDITIONS_PART);
    IlrConditionStatement condStmt = 
           (IlrConditionStatement) context.processNode(classCondNode);
    if (condStmt != null)
      rule.addConditionStatement(condStmt);
      
    // Process the action part
    context.setCurrentRulePart(IlrTranslationContext.ACTIONS_PART);

    IlrSyntaxTree.Node actionsNode = node.getSubNode("actions");
    if (actionsNode != null)
    {
      IlrActionStatement actionStmt = 
        (IlrActionStatement) context.processNode(actionsNode);
      if (actionStmt != null)
        rule.addActionStatement(actionStmt);
    }      
    return rule;
  }
}