ILOG JRules User Guide > Customizing JRules > Tasks > Managing BOM Value Types > Creating a Value Provider

A value info is necessary when you want to attach a value provider to a BOM member. The value info interface defines methods for referencing a custom value provider.

To create a value provider:

  1. Implement the interface IlrValueProvider.
  2. Implement the interface IlrValueInfo and declare your value provider class.
  3. Open the BOM Editor in Rule Studio.
  4. In the BOM Editor, open the member for which you define the value info.
  5. In the Custom Properties section, click Add.
  6. A new custom property is created.
  7. For a BOM attribute or a return value, in the Name column, click newProp and type valueInfo. In the Value column, type the key that you will use in Rule Studio and Rule Team Server to reference your value info class.
  8. For a BOM method, in the Name column, click newProp and type valueInfo[<arg index>], <arg index> being the index of the argument for which the value info is used. In the Value column, type the key that you will use in Rule Studio and Rule Team Server to reference your value info class.

You then need to integrate this implementation into Rule Studio and Rule Team Server.

To integrate a value info (and value provider) into Rule Studio:

  1. Create an Eclipse plug-in project using the extension point ilog.rules.studio.model.brl.valueInfo.
  2. In the extension point, use the key attribute to specify the name of the key you used for the property valueInfo, and use the attribute class to specify the fully-qualified name of the value info class.
  3. Note
    We recommend that you use the fully-qualified name of the implementation class as the name of the key attribute. If the key is the same as the fully-qualified name of the implementation class, you do not need to integrate the value info into Rule Team Server, it is done automatically.
  4. Place the value info and value provider classes into the plug-in project.
  5. Select your plug-in project, and, on the File menu, click Export.
  6. In the Export wizard, in the Plug-in Development folder, select Deployable plug-ins and fragments, and then click Next.
  7. In the Available Plug-ins and Fragments section, click Select All.
  8. In the Destination tab, in the Directory field, Browse to the directory <InstallDir>/studio/eclipse.
  9. Click the Options tab and select Package plug-ins as individual JAR archives.
  10. Click Finish.
  11. The value info and value provider are now implemented into your Rule Studio installation.

To integrate a value info (and value provider) into Rule Team Server:

  1. Package a preferences.properties file into the lib directory of the Rule Team Server EAR.
  2. In this file, add a mapping between the key you defined for the valueInfo property in the BOM Editor and your interface implementation.
webui.info.myKey =
      myPackage.MyValueInfoImplementation
  1. Repackage the Rule Team Server EAR. See Customizing Rule Team Server.
  2. The value info (and value provider) is now implemented into your Rule Team Server installation.

Suppose you need to declare a value provider for a role or phrase that represents a city. The predefined cities need to be structured hierachically by state.

To implement this state/city value provider:

  1. Define a class that implements IlrValueProvider:
public interface Named {
    String getName();
}
 
// Represents a city, this city is owned by a state
public class City implements Named {
  public final State state;
  public final String name;
      
  public City(State state, String name) {
    this.state = state;
    this.name = name;
  }    
  
  public String getName() {
    return name;
  }
}
 
// Represents a state, a state has a list of cities
public class State implements Named {
  private final String name;
  public City[] cities;
  
  public State(String name) {      
    this.name = name;		  
  }
  
  public String getName() {
    return name;
  }
}
 
// Represents a hierarchical predefined set of values for cities
// The hierarchy has two levels, at the root level there are states, 
// and each state has a list of cities as children 
public class StateCityValueProvider extends IlrAbstractValueProvider {
  
  // The predefined list of states
  public static State[] STATES;
  
  // Returns the root level of the hierarchy (all the states)
  public Object[] getValues() {
    return STATES;
  }
 
  // Returns the children of a predefined value, 
  // in this case only a state can have children
  public Object[] getChildren(Object parent) {
    return parent instanceof State ? ((State) parent).cities : null;
  }
 
  // Returns the parent of a predefined value, in this case only a city 
  // can have a parent (a state)
  public Object getParent(Object element) {
    return element instanceof City ? ((City) element).state : null;
  }
 
  // Returns true, if a predefined value has children, 
  // in this case only a state can have children
  public boolean hasChildren(Object element) {
    return element instanceof State;
  }
 
  // Returns the text to be displayed 
  // in the drop-down list for that predefined value
  public String getDisplayText(Object element, Locale locale) {
    return ((Named) element).getName();
  }
  
  // Returns the text to be inserted in 
  // the text of the rule for that predefined value.
  // In this case only a city value can be inserted.
  public String getText(Object element, Locale locale) {
    return element instanceof City ? ('"' + ((City) element).name + '"') : null;
  }
  
  // The predefined set of cities is not exclusive
  public boolean isExclusive() {
    return false;
  }  
}
  1. Declare a value info that provides the StateCityValueProvider as value provider:
public class StateCityValueInfo implements IlrValueInfo {
  ...
  public String getValueDescriptor() {
       return IlrValueDescriptorConstants.STRING;
   }
  
  private StateCityValueProvider valueProvider;
  
  public IlrValueProvider getValueProvider() {
    if (valueProvider == null)
      valueProvider = new StateCityValueProvider();
    return valueProvider;
  }
...
}
  1. To attach the value info to the BOM member, for example if you have a class Customer with a method that assigns a city to this customer void setCity(String city), define a custom property valueInfo[<arg index>] on this method:
valueInfo[0] = sample.valueInfo.StateCity
  1. To integrate the value info into Rule Studio, declare an extension point ilog.rules.studio.model.brl.valueInfos:
  2. ID: sample.valueInfo.StateCity
    Key: sample.valueInfo.StateCity
    Class: sample.StateCityValueInfo

Related Concepts

Custom BOM Value Types
Custom BOM Properties

Related Tasks

Creating a Value Descriptor
Creating a Value Editor
Creating a Value Translator
Creating a Value Info
Creating a Value Checker

Related Reference

Business Action Language
IlrValueProvider
IlrValueInfo
ilog.rules.studio.model.brl.valueInfo extension point

Related Samples and Tutorials

Rule Studio Authoring Extensions
Rule Team Server Authoring Extensions