| Samples > Rule Studio Authoring Extensions > How to Generate and Use a Custom Business Rule Language |
How to Generate and Use a Custom Business Rule Language |
PREVIOUS NEXT |
This sample shows you how to extend Rule Studio with a new rule language and make it available for rule authoring. It also shows how to extend the default BAL to meet more advanced or specific needs.
Key features include:
This sample extends the Rule Studio API. The required sample plug-ins are delivered as pre-deployed. If you have not already done so, you must install the samples extension site in Eclipse before running this sample.
To install the plug-in samples extension site:
<InstallDir>/studio/samples/eclipse.
To check that the Custom Business Rule Language Sample feature is enabled:
C:\ILOG\JRules\studio\samples\eclipse and check that Custom Business Rule Language Sample 1.0.0. is listed.
You can now import the sample project files. However, as this sample installs a custom rule model that replaces the default rule model, it is strongly recommended that you install and run it in a separate workspace to avoid any unwanted impact on other rule projects in your default workspace.
To install the custombrl sample:
ILOG Rule Studio Samples and Tutorials.
samples > authoring > custombrl.
custombrl-rules > data > custombrl.brmx.
Before running the sample, you may want to examine the changes made to the rule model.
To examine the changes made to the rule model:
is kind of operator was added by the extended BAL to enable the creation of expressions that test whether a given value is an instance of a given class.
is a kind of has generated an instanceOf test between the value and the BOM class corresponding to the term.
processDebitEventAmount_useNestedIfThenElse.
set 'amount' to ( - the amount of debitevent ) in the currency of
debitevent converted to USD on the date of debitevent ;
set 'balance' to the balance of account in the currency of account
converted to USD on the current date ;
with text "Debit of more than $2000 over account balance: an
operator should watch all transactions on account"
with text "Debit of less than $2000 over account balance:
the debit event is accepted, but recorded" ;
if/then/else constructs are supported in the actions of this extended BAL to enable the creation of complex text-based rules without the need to create several separate rules or a decision tree.
:) is used to start the enumeration of actions after the then and else parts, a hyphen (-) is used to start each enumerated action, and a comma (,) is used to avoid any ambiguity in the nested constructs. This is the same syntax as that used in the standard foreach construct of the BAL.
if {} ... else {} blocks are generated in the actions.
processDenialEvent_useLocalVariables.
declare 'variable' as was added in this extended BAL to support the creation of local variables in actions. After such a declaration, the actions can initialize this variable and refer to it within the same lexical scope.
To run the sample:
custombrl-rules launch configuration, then click Run.
patternmatching-rules project, and the ones in the custombrl-rules project, because the latter references the first.
###> Processing Exception : event DEBIT Event #ID2 Debit of more than $10000
over account balance: the debit event is refused <###
###> Processing Exception : event DEBIT Event #ID5 Debit of more than $2000
over account balance: an operator should watch all transactions on account <###
###> Processing Exception : event DEBIT Event #ID5 Debit in foreign currency :
double-check with the customer <###
Source files for this sample are provided in the custombrl-rules project and in the custombrl Eclipse plug-in.
The following file is provided in the custombrl-rules project:
data/custombrl.brmx: The description of the extension of the model, in order to declare the new type of business rule (ExtendedActionRule). This type use the extended BAL language.
To display the source code of the custombrl sample plug-in:
ilog.rules.studio.samples.custombrl plug-in (be careful not to select ilog.rules.studio.samples.custombrl.source), then click Add.
ExtendedBALCodeGeneratorExtender.java and ExtendedBALNodeTranslators.java The classes that manage the translation to IRL of the Extended BAL language
In order to integrate a new language in Rule Studio, we must associate that new language (Extended BAL) to a new Business Rule type.
To declare that new Business Rule type we have to declare a rule model extension, which we named ExtendedActionRule
We associate the language to this new type using an annotation with id set to language and value set to language/extendedBAL, which is the language ID.
In order to declare the new language, we have to declare and implement an extension in the custombrl plug-in.
This extension implements the ilog.rules.studio.model.brl.languages extension point.
With this extension we declare a new language with its:
ilog.rules.studio.samples.custombrl.ExtendedBAL
Extended BAL
language/extendedBAL
ilog.rules.studio.samples.custombrl.ExtendedBAL
| Copyright © 1987-2008 ILOG S.A. All rights reserved. Legal terms. Documentation homepage. | PREVIOUS NEXT |