[rules-users] DSL: Same Constraint - Multiple Declarations

Anders Hansen ahansen1 at yahoo.com
Wed Jun 11 17:30:03 EDT 2008


I'm running into an issue using the same text for constraints on multiple declarations.  The high level concept is that I'm trying to write DSL in a way that allows reuse of various conditions.  For example, I have a Client and that needs a constraint that tests to see if a Client is disabled.  I also want the ability to determine if a Client's child is disabled.  

        There is a Client who is disabled
        
        The Client has a child who is disabled

The thought is that the client is a Client and the child is a Client, so we should be able to write our DSL in a way such that we can reuse the disabled constraint.


        There is a Client
        - who is disabled
        
        The Client has a "Child"
        - who is disabled

I wasn't able to figure out a way to reuse the constraint directly.  However, to accomplish some level of reuse I've written the following DSL definitions:

[condition][Client]There is a Client=$client: Client()
[condition][Client]- who is disabled=disabled == true

[condition][Relationship]The Client has a {type}=exists ($relationship: Relationship(type=={type}, $relative: client) from $client.relationships)
[condition][Relationship]- who is disabled=$relative.disabled == true

This way the "who is disabled" constraint can at least be applied to Clients of differing relationships to the client, e.g. Spouse, Child, Parent, etc.  I thought that by using the second "[]" (e.g. [Client]) it would indicate that the constraint should only be applied to a Client.  In addition, I thought that the constraints themselves only apply to the declaration directly above.  However, when I attempt this I can the following error:

org.drools.rule.InvalidRulePackage: Unable to create Field Extractor for 'disabled' of '[ClassObjectType class=Relationship]'

It appears that the "- who is disabled" I attempted to attach "There is a Client" is also applying to the "The Client has a {type}"  statement?  If I modify constraint attached to the second statement to use "that" instead of "who" then it works.

[condition][Relationship]- that is disabled=$relative.disabled == true

Can the same constraint text not be used on multiple declarations?  Am I headed down the wrong path completely?  

It appears from this article: http://blog.athico.com/2008/06/allowing-variable-masks-in-dsl-grammar.html that there are some new things coming that might help me accomplish the re-use I'm looking for.  But, are there any options in version 4?
       
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080611/08bf03bb/attachment.html 


More information about the rules-users mailing list