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. <br><br> There is a Client who is disabled<br> <br> The Client has a child who is disabled<br><br>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.<br><br><br> There is a Client<br> - who is disabled<br>
<br> The Client has a "Child"<br> - who is disabled<br><br>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:<br><br>[condition][Client]There is a Client=$client: Client()<br>[condition][Client]- who is disabled=disabled == true<br><br>[condition][Relationship]The Client has a {type}=exists ($relationship: Relationship(type=={type}, $relative: client) from $client.relationships)<br>[condition][Relationship]- who is disabled=$relative.disabled == true<br><br>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:<br><br>org.drools.rule.InvalidRulePackage: Unable to create Field Extractor for 'disabled' of '[ClassObjectType class=Relationship]'<br><br>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.<br><br>[condition][Relationship]- that is disabled=$relative.disabled == true<br><br>Can the same constraint text not be used on multiple declarations? Am I headed down the wrong path completely? <br><br>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?<p>