If you can't insert the NameValue objects at all because you are using
somebody else's code to setup the initial facts you can use another rule to
do this for you:-
rule "insert NameValues"
salience -100
when
$l : LineItem( )
then
for(int i = 0, NameValue[] nvs = $l.getNameValueArray(); i <
nvs.length; i++) {
insert(nvs[i]);
}
end
rule "process NameValues"
salience -90
when
$nv : NameValue( )
then
...
end
Depending on what you want to do with NameValue (i.e. simply count them or
apply a function to a value) you could try looking at "collect" or
"accumulate" but I doubt this is what you are after.
Lastly you can always iterate over them in the RHS of a rule - but without
inserting them into working memory you'll never be able to write rules to
handle them.
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Bhattacharya,
Sougata
Sent: 03 October 2007 14:26
To: Rules Users List
Subject: RE: [rules-users] Arrays help
Your assumption is correct, but how do I iterate throw the array
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Anstis, Michael
(M.)
Sent: Wednesday, October 03, 2007 6:52 PM
To: Rules Users List
Subject: RE: [rules-users] Arrays help
Do you mean you cannot insert NameValue facts into working memory?
If this is the case, then you might have to use eval or MVEL dialect. Based
upon your model below I assumed you could insert NameValues:-
LineItem-->getParameters() returns Parameter[]
Parameter->getNameValueArray() return NameValue[]
Each NameValue has name and value attribute
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Bhattacharya,
Sougata
Sent: 03 October 2007 13:23
To: Rules Users List
Subject: RE: [rules-users] Arrays help
Yes that's the simple one, but I can't send the NameValue, I will send only
the LineItem
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Anstis, Michael
(M.)
Sent: Wednesday, October 03, 2007 5:36 PM
To: Rules Users List
Subject: RE: [rules-users] Arrays help
I forgot to mention, this assumes you want to maintain the relationships. If
you're not interested in these but merely want to process all NameValue
objects then a simple rule works fine:-
rule "don't worry about preserving relationships"
when
$n : NameValue ( )
then
.....
end
Simply assert all NameValue objects.
_____
From: Anstis, Michael (M.)
Sent: 03 October 2007 12:48
To: 'Rules Users List'
Subject: RE: [rules-users] Arrays help
There are a number of ways...
Java dialect [requires LineItem, Parameter and NameValue to be asserted into
working memory]
rule "a - requires object model change for parent property"
when
$l : LineItem( )
$p : Parameter ( parent == $l )
$n : NameValue( parent == $p )
then
...
end
rule "b"
when
$n : NameValue( )
$p : Parameter ( nameValues contains $n )
$l : LineItem( parameters contains $p )
then
...
end
MVEL dialect
rule "c"
dialect mvel
when
$n :
my-mvel-syntax-lets-me-down-but-I-know-you-can-traverse-object-graphs-using-
it
then
...
end
_____
From: rules-users-bounces(a)lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Bhattacharya,
Sougata
Sent: 03 October 2007 12:37
To: Rules Users List
Subject: [rules-users] Arrays help
Hi All,
I have a object graph like this
LineItem has array of Parameter and each Parameter has array of NameValue
and Namevalue object has name and value.
Now I have LineItem object in working memory, how to test the value of each
value of NameValue object.
LineItem-->getParameters() returns Parameter[]
Parameter->getNameValueArray() return NameValue[]
Each NameValue has name and value attribute
Any help?
Ta
Sougata
This message contains information that may be privileged or confidential and
is the property of the Capgemini Group. It is intended only for the person
to whom it is addressed. If you are not the intended recipient, you are not
authorized to read, print, retain, copy, disseminate, distribute, or use
this message or any part thereof. If you receive this message in error,
please notify the sender immediately and delete all copies of this message.
This message contains information that may be privileged or confidential and
is the property of the Capgemini Group. It is intended only for the person
to whom it is addressed. If you are not the intended recipient, you are not
authorized to read, print, retain, copy, disseminate, distribute, or use
this message or any part thereof. If you receive this message in error,
please notify the sender immediately and delete all copies of this message.
This message contains information that may be privileged or confidential and
is the property of the Capgemini Group. It is intended only for the person
to whom it is addressed. If you are not the intended recipient, you are not
authorized to read, print, retain, copy, disseminate, distribute, or use
this message or any part thereof. If you receive this message in error,
please notify the sender immediately and delete all copies of this message.