Example: Implementing a value translator in Rule Designer

As an example of how to implement a value translator, you can define a BOM class to represent a code for a product.

About this task

This example defines a BOM class sample.ProductCode to represent a code for a product. This value type is editable as text in the rule editors. You must generate an instance of this class in IRL by using the stored text.

Procedure

To create a value translator:

  1. Implement the value translator class:
    
    import ilog.rules.brl.translation.codegen.*;
    public final class ProductCodeValueTranslator implements IlrValueTranslator 
    {
        public String translateValue(String value, 
                IlrConcept concept, 
                IlrVocabulary vocabulary) {
            return "new sample.ProductCode(\""+value+"\")";
        }
        public boolean allowValueWrapping() { 
            return false;     
        }
    }
    
  2. Attach the value translator to the BOM class sample.ProductCode by defining a custom property valueTranslator on this class:
    
    valueTranslator = sample.valueTranslator.ProductCode
    
  3. Integrate the value translator in Rule Designer by declaring an extension point ilog.rules.studio.model.brl.valueTranslators:

    ID: sample.valueTranslator.ProductCode

    Key: sample.valueTranslator.ProductCode

    Class: sample.ProductCodeValueTranslator