How to evaluate OCL expression that is part of the input model [message #1403591] |
Thu, 24 July 2014 14:07 |
Wilbert Alberts Messages: 210 Registered: June 2010 |
Senior Member |
|
|
Hi,
Short:
I'm wondering whether it would be possible to embed an OCL expression in a model and have it evaluated during a QVTo transformation (and obviously how to do that).
Longer:
Suppose a metamodel that allows modeling the presence of Cars.
class Car
{
property licencesplate: EString;
property brand: EString;
property quality: EString;
}
class Model
{
property cars: Car[*] { composes }
}
Now I would like to make a QVTo transformation that adjusts the quality property of the Cars based on their brand. For instance: if the brand is 'Volkswagen' the quality should become: 'great', if the brand is 'Skoda' the quality should bedome 'OK'.
I am able to create such QVTo transformation. However, assume that I want to parameterize this transformation. I create another metamodel called Config.
class Config
{
property value: EString;
property criteria: OCLExpression;
}
class ConfigModel
{
property configs: Config[*] { composes }
}
Now I would like to create a QVTo transformation with the following signature:
transformation AdjustQuality(in mdl: Model, in cfg: ConfigModel, out r:Model);
Within that transformation, a mapping should evaluate a car against the criteria for each Config entry. If the criteria evaluates to true, the quality attribute of the car should be set to the value prescribed in the Config entry. Probably something like:
transformation AdjustQuality(in mdl: Model, in cfg: ConfigModel, out r:Model);
...
mapping Car::Car2Car(in cfg: ConfigModel) : Car{
brand := self.brand;
quality := c.quality;
Config c := cfg.configs->any(criteria.evaluate(self));
licenseplate := self.licenseplate;
}
Note that I assumed that an OCLExpression provides an 'evaluate' operation that accepts the object representing its context.
However, I don't know whether this is possible or how to achieve it. Any thoughts would be welcomed.
Greetings,
Wilbert.
|
|
|
Re: How to evaluate OCL expression that is part of the input model [message #1403770 is a reply to message #1403591] |
Sat, 26 July 2014 15:04 |
Ed Willink Messages: 7670 Registered: July 2009 |
Senior Member |
|
|
Hi
OCLinEcore enables you to embed expressions in models, so invoking the
operation/property will evaluate.
Making an 'evaluate' method visible from OCL is one of many roundtuits;
likely to occur in OCL 2.5 as an apply for a lambda expression.
Regards
Ed Willink
On 24/07/2014 15:07, Wilbert Alberts wrote:
> Hi,
>
> Short:
> I'm wondering whether it would be possible to embed an OCL expression
> in a model and have it evaluated during a QVTo transformation (and
> obviously how to do that).
>
> Longer:
> Suppose a metamodel that allows modeling the presence of Cars.
>
>
> class Car
> {
> property licencesplate: EString;
> property brand: EString;
> property quality: EString;
> }
>
> class Model
> {
> property cars: Car[*] { composes } }
>
>
> Now I would like to make a QVTo transformation that adjusts the
> quality property of the Cars based on their brand. For instance: if
> the brand is 'Volkswagen' the quality should become: 'great', if the
> brand is 'Skoda' the quality should bedome 'OK'.
>
> I am able to create such QVTo transformation. However, assume that I
> want to parameterize this transformation. I create another metamodel
> called Config.
>
>
> class Config
> {
> property value: EString;
> property criteria: OCLExpression;
> }
>
> class ConfigModel
> {
> property configs: Config[*] { composes } }
>
>
> Now I would like to create a QVTo transformation with the following
> signature:
>
> transformation AdjustQuality(in mdl: Model, in cfg: ConfigModel, out
> r:Model);
>
> Within that transformation, a mapping should evaluate a car against
> the criteria for each Config entry. If the criteria evaluates to true,
> the quality attribute of the car should be set to the value prescribed
> in the Config entry. Probably something like:
>
>
> transformation AdjustQuality(in mdl: Model, in cfg: ConfigModel, out
> r:Model);
>
> ...
>
> mapping Car::Car2Car(in cfg: ConfigModel) : Car{
> brand := self.brand;
> quality := c.quality;
>
> Config c := cfg.configs->any(criteria.evaluate(self));
>
> licenseplate := self.licenseplate;
> }
>
>
> Note that I assumed that an OCLExpression provides an 'evaluate'
> operation that accepts the object representing its context.
>
> However, I don't know whether this is possible or how to achieve it.
> Any thoughts would be welcomed.
>
> Greetings,
> Wilbert.
>
|
|
|
|
Powered by
FUDForum. Page generated in 0.13963 seconds