how to create an object (call the constructor) fro

2019-08-20 04:33发布

问题:

I have 2 arraylist of type TYPE1 (let's say it) as ruleset parameters on my Rule Project. One for IN another one for OUT. On my ruleflow I have an initial action task that initializes the OUT ruleset parameter. Since we have an arrayList as input I will have to "iterate" over it which I know how to do it.

My problem comes after. In the next task of my ruleflow I have a rule task where I added all my decision tables that have some preconditions. On most decision tables more than one rule can be fired. What I want to achieve is for each rule fired I want to add a new object of type TYPE1 to the output arraylist. The problem comes here. If I have 3 rules firing I in fact have 3 objects of type TYPE1 being added to the output arraylist but all 3 come with the same values. Looks like all are "pointing" to the same object.

My question is, is there any way on an action column to create a new object (call the constructor) of type TYPE1 so when executing the rest of the actions of the rule it writes on that new object of TYPE1 ? I know I can achieve this if I create as many ruleset variables of type TYPE1 as many rules I have and use each one for each rule, but this way my table gets huge (sideways) and it's not the way we want it.

Both TYPE1 and the arraylists are BOM members.

Edit: Forgot to mention that I'm using RetePlus algorithm, with "none" as exit criteria and ordering and dynamic BAL for the run time rule selection.

I hope I explained myself good enough for someone to be able to help me. Thanks in advance.

回答1:

Here is the technique to achieve what you want, in 3 steps:

In the BOM editor, create a method in the TYPE1 class (or any other class in fact). Set its return type to TYPE1. Call it createTYPE1, for instance. Add as many method arguments as you need to initialize your object. Make it static.

Verbalize it in a way that makes sense for the rule author. Something like : a new TYPE1, with name set to {0}, value set to {1} // this is an example, adapt it to the argument list you want to have.

Implement the method as piece of B2X script:

// calling the appropriate constructor from the XOM class.
return new mypackage.TYPE1(arg1, arg2); 

Save the BOM.

use this new phrase, in constructions like : add a new TYPE1, with name set to "Joe", value set to 12 to the output list;

Typically, you can use it in an action column of a decision table. The editor will map every placeholder of the phrase to a subcolumn.



标签: ibm-odm