Hi Joost. No problems re the names...
I just think its happening there as its the "extractor" generated class causing it.
Any chance you can wrap this up as a unit testable unit so we can try it out and see what/where the cast is happening?
Ta,
Michael
(PS I am offline all week, so don't feel ignored !)
Hi Michael,
The list is defined in terms of the superclass that both classes share. And the previous and next methods both have the superclass as the return type.
So I'd expect
PreventieveInsluitingsTitel(previous==secondPosition [...]
to evaluate to
<instance of superclass> == <instance of subclass>
I'd expect this check to just fail when the objectreferences do not refer to the same object. Not to cause a classcastexception.
But the exception is thrown in the consequence part of the rule during an invocation of modify( ).....
So I'm not sure why this construction would be wrong and what would be the right way to do it.
oh, by the way; sorry for the dutch classnames. That must make the problem harder to understand. In fact it's about convictions and the subclasses are types of convictions.
regards,
Joost2007/1/12, Michael Neale <michael.neale@gmail.com>:In terms of your problem, it seems to be to do with:
PreventieveInsluitingsTitel(previous==secondPosition
the secondPosition is not a compatible class with previous?
I don't have any specific thoughts on computing a sequence in rules, unfortunately... maybe someone else does ? ;)On 1/11/07, Joost de Vries < drools@ziener.org> wrote:Hi,_______________________________________________
I'm new to jBoss Rules and I'm hitting a few snags. I appreciate your insight.
Among other things I want to use business rules to compute the right sequence of actions that conforms to legal business rules.
The only way I could think of to implement this using rules is to use rewriting production rules similar to:
input: ACCAAAC
rule: CA -> AC
My first question is: what other ways are there to compute a sequence that conforms to sequencing business rules?
My second question concerns the nullpointerexceptions and classcastexceptions I'm encountering in my rules.
I've got a sequence of C's who are either B's or A's. I.e. C is the common superclass. This superclass has the methods:
public C getPrevious();
public C getNext();
Actually it's in dutch so it's
public class Straf extends InsluitingsTitel {}
and
public class PreventieveInsluitingsTitel extends InsluitingsTitel {}
and
public abstract class InsluitingsTitel{
public C getPrevious();
public C getNext();
}
The rule is as follows:
rule "WSV 68.1"
when
// any PreventieveInsluitingsTitel should precede all Straf
secondPosition: Straf ( firstPosition: previous )
thirdPosition: PreventieveInsluitingsTitel(previous==secondPosition, fourthPosition:next)
then
System.out.println( "switching wsv 68.1 "+secondPosition+" "+thirdPosition);
thirdPosition.switchWithPrevious();
if(firstPosition!=null){
modify(firstPosition);
}
modify( secondPosition);
modify( thirdPosition);
if(fourthPosition!=null){
//in the next statement a classcastexception is thrown
modify(fourthPosition);
}
end
results in a classcastexception. The sequence is at that moment { Straf, Straf, PreventieveInsluitingsTitel, Straf } and the middle two items are matched by the LHS secondPosition and thirdPosition.
Here's the stacktrace.
java.lang.ClassCastException: org.dji.domein.insgro.Straf
at org.drools.base.org.dji.domein.insgro.PreventieveInsluitingsTitel$getPrevious.getValue(Unknown Source)
at org.drools.base.ClassFieldExtractor.getValue (Unknown Source)
at org.drools.rule.Declaration.getValue(Unknown Source)
at com.sample.Rule_WSV_68_1_0ConsequenceInvoker.evaluate(Rule_WSV_68_1_0ConsequenceInvoker.java:22)
at org.drools.common.DefaultAgenda.fireActivation (Unknown Source)
at org.drools.common.DefaultAgenda.fireNextItem(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules (Unknown Source)
at org.dji.domein.insgro.VolgordeTest.main(VolgordeTest.java:32)
org.drools.spi.ConsequenceException: java.lang.ClassCastException: org.dji.domein.insgro.Straf
at org.drools.common.DefaultAgenda.fireActivation (Unknown Source)
at org.drools.common.DefaultAgenda.fireNextItem(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules(Unknown Source)
at org.drools.common.AbstractWorkingMemory.fireAllRules (Unknown Source)
at org.dji.domein.insgro.VolgordeTest.main(VolgordeTest.java:32)
Caused by: java.lang.ClassCastException: org.dji.domein.insgro.Straf
at org.drools.base.org.dji.domein.insgro.PreventieveInsluitingsTitel$getNext.getValue (Unknown Source)
at org.drools.base.ClassFieldExtractor.getValue(Unknown Source)
at org.drools.rule.Declaration.getValue(Unknown Source)
at com.sample.Rule_WSV_68_1_0ConsequenceInvoker.evaluate(Rule_WSV_68_1_0ConsequenceInvoker.java:22)
... 5 more
Thanks in advance for your insight.
Regards,
--
Joost de Vries
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
Joost de Vries
06 22375323
werk: joost.de.vries@ordina.nl
privé: joost@ziener.org
--
Joost de Vries
06 22375323
werk: joost.de.vries@ordina.nl
privé: joost@ziener.org
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users