| ILOG JRules User Guide > Customizing JRules > Concepts > Custom BOM Value Types |
Custom BOM Value Types |
PREVIOUS NEXT |
ILOG Rule Studio provides you with a mechanism to handle custom value types. Custom BOM value types are types that you define specifically to create a new kind of value. Values are literals of a given type: a Number, a Date, or a String for instance.!
Values are generally entered by a rule author as part of a business rule. The types of values (string, date, and so on) provide services for working with the value. For some values, which have specialized versions of the standard types, for example, the days of the week, you need to define your own services to handle the values properly. Value management allows you to:
You can choose to apply value management to a custom value type, which means that all values of this type are displayed and edited in the same way, or apply value management to specific placeholders in phrases, which correspond to BOM members. This capability allows you to provide, for instance, a list of values in the context of a placeholder in a phrase attached to a BOM member.
If you want to associate value management with a BOM value type, you have to use a value descriptor, and optionally an editor and a translator.
If you want to associate value management with a BOM attribute or with a BOM method argument or return type (which correspond to placeholders in phrases), you need to use a Value Info. The value info groups the services of the value editor, provider, checker, and translator.
A value descriptor is compulsory if you want to associate value management with a BOM class.
The value descriptor allows you to:
A value descriptor is an implementation of the interface ilog.rules.brl.value.descriptor.IlrValueDescriptor.
Some predefined value descriptors are provided in the package ilog.rules.brl.value.descriptor:
IlrValueStringDescriptor, to represent a literal string ("...")
IlrValueNumberDescriptor, to represent a number (Integer and Float)
IlrValueFullDateDescriptor, to represent a full date (date and time)
IlrValueShortDateDescriptor, to represent a short date (only date)
IlrValueTimeDescriptor, to represent a time
A new value descriptor must extend a predefined value descriptor to inherit all of its features. A derived value descriptor must always provide the localized text of the value by overriding getLocalizedText as follows:
public String getLocalizedText(Object value, IlrBRLDefinition definition) {
return IlrValueDescriptorHelper.verbalizeDerivedValue(this,
super.getLocalizedText(value, definition),
definition);
}
Another way to reuse a predefined value descriptor is to add a prefix or suffix to the predefined value descriptor. For example, if you want to use the Number value descriptor to describe a percentage, you add % as a suffix in the label of the Number value descriptor.
The value descriptor IlrDecoratedValueDescriptor allows you to add a prefix or suffix to an existing value descriptor.
You can also define a new type of value and its associated value descriptor with a "stringified" value descriptor or a "numberified" value descriptor. These value descriptors allow you to define a value as a String or a Number prefixed by the type of the value. For instance, if you want to associate specific values to a BOM type Country, you can attach an IlrStringifiedValueDescriptor to this class. Values of this type will have the form the country "US" or the country "Japan" for instance. The value is built from a basic value type (here a String) prefixed with the verbalization of the class (here the country).
A value info is compulsory if you want to associate value management with a BOM member. A value info provides a way to describe a value when it is used in a phrase placeholder. Use a value info when you want to customize the way the value is used, edited, and checked in the context of a placeholder in a specific phrase.
The value info groups the services of the value editor, provider, checker, and translator.
A value info is an implementation of the interface ilog.rules.brl.value.info.IlrValueInfo.
A value editor allows you to edit a value with a dedicated editor.
A value editor is an implementation of the interface ilog.rules.brl.value.editor.IlrValueEditor.
Value editors can be used in all types of rule editors (Intellirule Editor, Guided Editor, or Web Guided Editor).
A value editor is associated with a value descriptor, in order to use the transformation between object and text, and the possibility to provide a default value.
A value editor can be a graphical user interface.
For Rule Studio, the value editor must implement the interface IlrValueEditorComponent. This interface allows you to access a graphical component to edit the value. All graphical user interfaces must use the Swing component in order to be used in the Intellirule Editor and the Guided Editor.
For Rule Team Server, the value editor must implement ilog.rules.webui.IlrWValueEditorComponent.
A value provider allows you to provide a predefined set of values in the drop-down lists of rule editors each time there is a value info associated with a placeholder in a phrase.
The set of predefined values can be hierarchical, and only a leaf value in the hierarchy can be inserted into a rule. The predefined values are calculated on demand. The list of possible values can depend on what the rule author inserted before the value. The context of the value is the node of the Abstract Syntax Tree for the rule where the value is inserted.
A value provider is an implementation of the interface ilog.rules.brl.value.info.IlrValueProvider.
A value provider is automatically defined for enumerated domains in the BOM. As soon as a BOM domain is attached to a BOM class, a BOM attribute or a parameter of a BOM method, the values defined in this domain are automatically available in a business rule through a dedicated value provider.
A value checker allows you to check a value at a specific location in the rule, and report an error, depending on the context. This context is the node that represents the value in the Abstract Syntax Tree of the rule.
A value checker is called before a rule is parsed, but after the abstract syntax tree is built.
If an error is reported, the value checker can populate IlrValueError given as parameter, in order to return the severity and the reason of the error.
A value checker is an implementation of the interface ilog.rules.brl.value.info.IlrValueChecker.
In a business rule language no distinction is made between integer numbers and floating point numbers. A checker is automatically provided for all placeholders in the verbalization of integer BOM method arguments or attributes. If a floating point literal value is used in such a placeholder, an error is reported.
When a BOM enumerated domain is declared on a BOM attribute or for a BOM method argument or return value, a dedicated value checker is automatically provided to check that input values are part of the declared enumerated domain.
A value translator is used when translating a business rule into IRL. It provides a mechanism to generate IRL source code from a literal value.
There are several predefined and preregistered value translators (for strings, dates, numbers, and so on).
A value editor is an implementation of the interface ilog.rules.brl.translation.codegen.IlrValueTranslator.
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |