问题
I'm using ODM 8.5 (the JRules successor). In my Java domain, I have a three-character String field
that represents a number, "000" to "999". I'd like to have a decision table that represents logic like:
if field is between "000" and "012" then set the result to "tiny"
if field is between "013" and "060" then set the result to "less tiny"
...
IBM's documentation on defining columns states - "A condition statement is an incomplete BAL predicate expression...". Is there anything in the BAL that does the kind of String comparison I want to do? If not, is it possible to call a function defined in the IRL from the BAL? If so, how? I'm also open to other suggestions on how to handle this simple problem in ODM (without changing the existing Java XOM). Right now, it looks to me that I can't use an ODM decision table, although the underlying logic seems well-suited to a decision table.
回答1:
This answer is heavily based on Justin Phillips's nice answer to this question, updated for ODM 8.5. Please plus up his answer.
The main idea is to create a function in the Business Object Model (BOM) that can be called from your rules. To add a BOM function:
- Right click the
bom
folder in the Eclipse rules project. - Select
New -> BOM Entry
from the menu. - Select the
Create an empty BOM entry
option and then clickFinish
. - Double click the new BOM entry to bring up the BOM editor view, and
then click
New Class
. - Enter the class name and then click
Finish
. - Double click the new BOM class from the list, then under
the
Members
section, click theNew
button. - In the
New Member
dialog, select theMethod
option, enter aName
(isBetween
), returnType
for the method (boolean
), and add three String parameters (testee
- the value being tested,min
andmax
). Click theFinish
button. - Double click the new method under the
Members
section, and select theStatic
andFinal
options. - Click the Create link under the "Member Verbalization" section and fill in the Template text box with
{0} is between {1,min} to {2,max}
- Under the
BOM to XOM Mapping
section, enter your Java code.
Execution name
to the value void
in the "BOM to XOM Mapping" section. This indicates that the BOM class is not linked to a Java class (XOM).
The verbalization for the newly created member should now be accessible when filling out the Test
in the Condition Column
for the decision table.
来源:https://stackoverflow.com/questions/22996144/how-to-define-a-function-for-use-in-an-odm-decision-table-w-o-changing-the-xom