[rules-users] DRL Pattern match to subclass?
Kris Nuttycombe
kris.nuttycombe at gmail.com
Fri Aug 7 12:37:44 EDT 2009
On Fri, Aug 7, 2009 at 10:33 AM, Kris
Nuttycombe<kris.nuttycombe at gmail.com> wrote:
> Hi, all,
>
> I'm trying to figure out a way to perform the following pattern match
> in a "when" clause in a drl file. This is with Drools 4.x
>
> I have the following parameterized class (boilerplate omitted):
>
> abstract class Property<T> {
> public String getName() {
> //...
> }
>
> public abstract T getValue();
> }
>
> and subclasses such as
>
> class BigDecimalProperty extends Property<BigDecimal> {
> public BigDecimal getValue() {
> //...
> }
> }
>
> I then have an interface as such:
>
> public interface Propertied {
> public Set<Property<?>> getProperties();
> }
>
> and an implementing class:
>
> class Plan implements Propertied {
> //...
> }
>
> In my rules file, I would like to be able to perform the following
> pattern match:
>
> rule "Ensure that plan minimum commitment has been met."
> agenda-group "evaluate-balance"
> when
> $plan: Plan()
> $minCommitProperty: BigDecimalProperty(name ==
> "minimum_commitment", $minCommitment : value) from $plan.properties
> then
> //...
> end
>
> Of course, this results in a runtime rule compilation exception
> complaining of type mismatch. Is there any better way to encode this
> match than to add all properties to the working memory, match the
> desired property as a first-class object, then match against the plan
> with Plan(properties contains $minCommitProperty)?
One addendum - this isn't really a desirable approach since it would
mean I would have to segment my working memory on a plan-by-plan
basis, as various different minimum commitments.
Kris
More information about the rules-users
mailing list