Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [henshin-dev] API: how to use findMatches?

Hi Jens,

if you just want to find matches you don't need a RuleApplication instance. This is how you can do it:

        Rule rule = system.findRuleByName("createAccount");
        Match partialMatch = new MatchImpl(rule);
        partialMatch.setParameterValue(rule.getParameterByName("client"), "Alice");
        partialMatch.setParameterValue(rule.getParameterByName("accountId"), 5);
       
        for (Match match : engine.findMatches(rule, graph, partialMatch)) {
          System.out.println(match);
        }

Note that the acountId parameter must be an integer, and not a string (because the Client.id attribute is of type EInt). In the next version of Henshin we will support types for parameters to avoid these problems.

The code above should give you the following match:

Match for rule 'createAccount':
- parameter 'client' => 'Alice'
- parameter 'accountId' => 5
- node #1 => bank.Bank@747fa2 (dynamic)
- node #2 => bank.Client@14ae2c1 (dynamic, name='Alice')
- node #3 => bank.Manager@4c47db (dynamic, name='John')

Please note that in the next version of Henshin, some of the helper methods will be renamed. Then you will have to write system.getRule(name) instead of findRuleByName() and similarly for other helper methods.

Hope this helps.

Cheers,
Christian


On 07/19/2012 04:20 PM, Jens Bürger wrote:
Am 18.07.2012 18:59, schrieb Christian Krause:
How can I make use of parameters? As far as I see, parameters are
applied to (in this case) a RuleApplication-object, but findMatches()
works directly on the engine?

Since Match extends Assignment you can use the methods in Assignment to
set parameter values. The methods in RuleApplication are just
convinience methods which delegate to the corresponding methods in
Assignment / Match.

So this means if I just want to find matches and do not want to really apply rules, it is sufficient to work on an AssignmentImpl-Object?


Based on the "Bank"-Example, I tried using an assignment but it does not get my any matches. I attached my sourcecode.

Thanks,

Jens



_______________________________________________
henshin-dev mailing list
henshin-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/henshin-dev


Back to the top