问题
I have a collection of Type Cars which I need to pass from the ILOG Jrules to my Java evaluation method. My Java evaluation method can accept an Object, so a collection can be accepted. I need to process the collection of cars in my Java XOM and then return some output to ILOG. But how do I create a collection of cars from my ILOG JRules? And for DVS testing, how do I pass the collection of cars from my DVS Scenario Excel sheet?
回答1:
To clarify Tito's comment on the first answer: Well, it depends what you want to do. Without any input, it is hard to tell.
Yes, you can send a collection as an InputParameter easily.
BUT, if your business users want to author rules against the items of the collection then use [concept.insert(Object) ish to insert all your items in the working memory]. (if you want to write "if the code of the item is.." without having to say: "definitions set item to an item in the items of the shopping cart" first, for instance),
and DO NOT use any loop in the rule flow.
This is overkilling the perfs.
You can send to JRules a complex structured object if you wish. It is then up to you to manage how you will author rules and split the model, if needed, using pointers to objects, like a ruleset parameter being the collection "items" of your main object "shoppingCart" makes sense?
回答2:
There are 2 questions there...
1/ Why not having a JAVA method typed in your Java? Unless you cannot use Java 5 you should type your collection.
You could have a "virtual method" with a Collection as parameter (simply add a method in your BOM, where it makes sense) and in the B2X try to cast from a collection to an Object.
JRules is not typed because it uses 1.4, so you may be able to do so... Give it a try.
Why would you need to pass in any Collection to your Java? Be careful not to bring back business logic in Java ;-)
2/ DVS... how to say that... Especially with Collection as input and or output... This is shite! This is a crappy piece of code which makes the business users feels happy because they will use Excel to create the test scenario but (my friend) if you are really looking for troubles, then go for it.
Let me clarify that:
Input: you can have complex objects and a collection easily
Output: this is a real pain in the back. But you can have a collection and a sorted one as well, as long as you have a Comparator in the BOM. Complex Objects... Feasible, but this requires lots of tweaks, and this is not documented.
But you will need to do all that (prepare the Excel file) manually :(
Let me give you the salesmen answer: 7.5 will allow you to do so :) Happy ??
Now pragmatically, you can do it but with a lot of "unreadable" code in your stylesheet, meaning that your business users will not be able to use them from scratch. Maybe some of your IT team will not be able to use it. Far too much hassle. And you will have to prevent Business Users from modifying the code of the stylesheet...
Due to this hassle, this is absolutely NOT documented, and if you really want to do that, I may have to look at an example I think I have, or you need to have a close contact in the Ilog IT team... Sorry.
来源:https://stackoverflow.com/questions/10233177/how-to-pass-a-collection-from-a-rule-to-a-java-method