Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » How to evaluate OCL expression that is part of the input model
How to evaluate OCL expression that is part of the input model [message #1403591] Thu, 24 July 2014 14:07 Go to next message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 169
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 Go to previous messageGo to next message
Ed Willink is currently offline Ed WillinkFriend
Messages: 5891
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.
>
Re: How to evaluate OCL expression that is part of the input model [message #1404100 is a reply to message #1403770] Tue, 29 July 2014 15:29 Go to previous message
Wilbert Alberts is currently offline Wilbert AlbertsFriend
Messages: 169
Registered: June 2010
Senior Member
Hi Ed,

Thanks for the reply. I solved in a satisfying, though not perfect, way. In case anyone is interested:

I changed the Config class into:
class Config
{
  property value: EString;
  property criteria: String;
  operation applies(t : Car) : Boolean;
}

The applies method can be invoked from the qvto transformation AdjustQuality. However, I need to implement the applies method. Its implementation instantiates an OCL environment, parses the criteria and evaluates its result against the Car 't'. (Details can be found in the OCL help embedded in eclipse.)

Satisfactory but not perfect in the sense that I had to change the generated code but OK for now.

Thanks,
Wilbert
Previous Topic:Obtain URI from evaluation environment in RC4
Next Topic:Run exported transformation
Goto Forum:
  


Current Time: Fri May 25 18:59:37 GMT 2018

Powered by FUDForum. Page generated in 0.01955 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top