On 4 Jun 2013, at 17:00, rules-users-request(a)lists.jboss.org wrote:
> Send rules-users mailing list submissions to
> rules-users(a)lists.jboss.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
>
https://lists.jboss.org/mailman/listinfo/rules-users
> or, via email, send a message with subject or body 'help' to
> rules-users-request(a)lists.jboss.org
>
> You can reach the person managing the list at
> rules-users-owner(a)lists.jboss.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of rules-users digest..."
>
>
> Today's Topics:
>
> 1. ClassCastException due to binding (bdolbeare)
> 2. Re: Setting a value in LHS (Michael Anstis)
> 3. Re: ClassCastException due to binding (Davide Sottara)
> 4. Re: Setting a value in LHS (Stephen Masters)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Tue, 4 Jun 2013 08:12:09 -0700 (PDT)
> From: bdolbeare <bdolbeare(a)yahoo.com>
> Subject: [rules-users] ClassCastException due to binding
> To: rules-users(a)lists.jboss.org
> Message-ID: <1370358729183-4024115.post(a)n3.nabble.com>
> Content-Type: text/plain; charset=us-ascii
>
> We have a need to support binds for conditional or elements so that we can
> describe why a rule fired in the then clause of a rule. The following DRL
> is a simple example of what we are trying to do. There are two versions of
> our rule in the DRL:
>
> *rule "WORKING: find with or"*: works but only because the first
variable
> we try to bind in the or expression is of type "target" which is a super
> class of the other elements in the or expression.
>
> *rule "BROKEN: find with or"*: causes a class cast exception when the
> "bar" pattern is matched because the then clause tries to store the bar
> object in handle "x" which it thinks is of type "foo".
>
> Is there a way to define the object type for the bind variable?
>
> Is there any other way to make something like this work?
>
>
>
> package tests
>
> import org.apache.log4j.Logger;
>
> global Logger log
>
> declare target
> notreal : boolean
> end
>
> declare foo extends target
> foovalue : String
> end
>
> declare bar extends target
> barvalue : String
> end
>
> rule "insertdata"
> when
> then
> insert(new foo(false, "a"));
> insert(new bar(false, "b"));
> end
>
> rule "WORKING: find with or"
> when
> ( or x: target(notreal)
> x: foo(foovalue == "a")
> x: bar(barvalue == "b")
> )
> then
> log.info("i found object: " + x);
> end
>
> rule "BROKEN: find with or"
> when
> ( or
> x: foo(foovalue == "a")
> x: bar(barvalue == "b")
> )
> then
> log.info("i found object: " + x);
> end
>
>
>
> Exception executing consequence for rule "find with or" in tests:
> java.lang.ClassCastException: tests.bar cannot be cast to tests.foo
> at
>
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:39)
> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1283)
> at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:1209)
> at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1442)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:710)
> at
> org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:674)
> at
>
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:230)
> at
>
org.drools.impl.StatelessKnowledgeSessionImpl.execute(StatelessKnowledgeSessionImpl.java:278)
> at tests.DroolsTest.testStateless(DroolsTest.java:120)
> at tests.DroolsTest.runTest(DroolsTest.java:74)
> at tests.DroolsTest.main(DroolsTest.java:59)
> Caused by: java.lang.ClassCastException: tests.bar cannot be cast to
> tests.foo
> at
>
tests.Rule_find_with_or_411ee1c99de54340945b2b707ad0a576DefaultConsequenceInvoker.evaluate(Unknown
> Source)
> at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:1273)
> ... 9 more
>
>
>
> --
> View this message in context:
http://drools.46999.n3.nabble.com/ClassCastException-due-to-binding-tp402...
> Sent from the Drools: User forum mailing list archive at
Nabble.com.
>
>
> ------------------------------
>
> Message: 2
> Date: Tue, 4 Jun 2013 16:33:11 +0100
> From: Michael Anstis <michael.anstis(a)gmail.com>
> Subject: Re: [rules-users] Setting a value in LHS
> To: "stephen.masters" <stephen.masters(a)me.com>, Rules Users List
> <rules-users(a)lists.jboss.org>
> Message-ID:
> <CAAG9P0uZO_-sskN_1V1uQFXzWuAxCosx=v+i+SVfZ0VHysQKjQ(a)mail.gmail.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> This would need to be provided by the tooling; I don't think it's something
> that's even remotely possible at runtime (unless you stored the field name
> in a Fact and used reflection on the RHS).
>
> That said (and you're going to guess my next comment) this is not provided
> in the guided editors. Depending on how complex your DSLs are and whether
> users need to combine DSL Sentences; IDK if a "cheat" works:
>
> [when]Do something with {field} and {value}=$f : Fact({field}=={value} then
> $f.{field} = {value}
>
> I've not tried it; nor know whether it fits your requirements.. but a hack
> worth trying?
>
>
> On 3 June 2013 17:40, stephen.masters <stephen.masters(a)me.com> wrote:
>
>> Hi folks,
>>
>> Is there a decent way to set a value in the LHS of a rule so that it's
>> available in the RHS?
>>
>> Reason being I have a DSL driving the guided rules editor which will pluck
>> out the value of a field, where the name of that field is driven by a drop
>> down menu enumeration.
>>
>> A change I now have would be a lot easier if I could assign a string to a
>> variable in the LHS, which could be read by the RHS. Otherwise I might need
>> to extend the RHS DSLs to include the same enumeration as the LHS. Which
>> looks a bit redundant for a business user wondering why the need to write
>> the same thing twice.
>>
>> Any thoughts?
>>
>> Steve
>>
>>
>>
>>
>> Sent from Samsung Mobile
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/rules-users
>