[rules-users] ClassCastException and other problems
Sibylle Duerr
sibylle.duerr at mymail.ch
Fri Jun 6 03:12:57 EDT 2008
Hi there,
I have three issues, where I'm not sure if these are bugs in drools, or
if this is just the way it has to be.
the used classes in this case are:
Project
Model
ProcessModel extends Model
only the Project is in the working memory, because I didn't want to load
all elements due to performance issues (there can be thousends of
elements to load at startup).
if I have the following rule:
Project($models : models)
ProcessModel($activities : activities) from $models
there happen to be two problems. if the project does not only contain
ProcessModels but also TypeModels or others (all extend Model), this
leads to a ClassCastException.
I can solve this by writing the rule as follows:
Project($models : models)
$m : Model(eval($m instanceof ProcessModel)) from $models
ProcessModel($activities : activities) from $m
but this is not really nice and I hope there is a better solution for
this, is there?
the second problem this rule gives me, is when the set 'models' is
empty. that will also throw an exception. to solve this I write:
$p : Project(eval($p.hasModels()), $models : models)
$m : Model(eval($m instanceof ProcessModel)) from $models
ProcessModel($activities : activities) from $m
and I need to use this in each case where I have possible empty sets.
the last problem I encountered when I tried to load all elements to the
working memory and then redefine some rules. used classes:
Aggregation extends DomainElement
rule:
Aggregation(owner.owner != type.owner)
causes some exception. the root exception is a ClassCastException:
ProxyShadowProxy cannot be cast to Aggregation.
when I rewrite the rule as:
$element : DomainElement(eval($element instanceof Aggregation))
Aggregation(owner.owner != type.owner) from $element
everything works fine. but that again is not a nice solution.
any help?
best regards
sibylle
More information about the rules-users
mailing list