Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Archived » M2M (model-to-model transformation) » [QVTo] Access EMF model enum value
[QVTo] Access EMF model enum value [message #543841] Wed, 30 June 2010 17:59 Go to next message
Ryan is currently offline RyanFriend
Messages: 74
Registered: July 2009
Location: Indiana
Member
I've got a transform from one EMF model to another. I have an EMF enum (say days of the week, Sunday =0, etc.), and in the transform, I need access to the integer value of the enum. How do I access this in the qvto transform?
Re: [QVTo] Access EMF model enum value [message #544092 is a reply to message #543841] Thu, 01 July 2010 14:51 Go to previous messageGo to next message
Ryan is currently offline RyanFriend
Messages: 74
Registered: July 2009
Location: Indiana
Member
So I've figured a way around the lack of this feature, but it introduces the possibility of errors during maintenance because the int value is now defined in two locations instead of one

query CALENDAR::Day::intValue() : Integer {
    var value : Integer := 0;

    switch {
        case (self = Day::Sunday) value := 0;
        case (self = Day::Monday) value := 1;
        case (self = Day::Tuesday) value :=2;
        .
        .
        .
    };

    return value;
}


Anyone have a better idea?
Re: [QVTo] Access EMF model enum value [message #544529 is a reply to message #543841] Sat, 03 July 2010 12:00 Go to previous messageGo to next message
Oliver is currently offline OliverFriend
Messages: 13
Registered: January 2010
Location: Germany
Junior Member
I've assumed WeekDay::Sarurday is instance of Ecore::EEnumLiteral, but without success.
modeltype EcoreMM "strict" uses ecore('http://www.eclipse.org/emf/2002/Ecore');
// ...
var eEnumLiteral : EEnumLiteral := myClass.myAttribute.oclAsType(EcoreMM::EEnumLiteral);
log(eEnumLiteral.value.toString());


The output is "<Invalid>" Sad

Ciao
Olli
Re: [QVTo] Access EMF model enum value [message #544551 is a reply to message #543841] Sat, 03 July 2010 15:45 Go to previous messageGo to next message
Ryan is currently offline RyanFriend
Messages: 74
Registered: July 2009
Location: Indiana
Member
Thank Olli, that's along the lines of what I was looking for, a shame it doesn't work. It looks like what you came up with would be closer to a real solution. Yes, it's an EEnumLiteral.
Re: [QVTo] Access EMF model enum value [message #544577 is a reply to message #543841] Sun, 04 July 2010 07:48 Go to previous messageGo to next message
Oliver is currently offline OliverFriend
Messages: 13
Registered: January 2010
Location: Germany
Junior Member
A partial success:
var eEnum : EEnum := TestMM::WeekDay.oclAsType(EcoreMM::EEnum);
log(eEnum.getEEnumLiteralByLiteral("saturday").value.toString());


WeekDay:Sturday is not instance of EEnumLiteral but WeekDay is instance of EEnumerator.

So only a partial solution, becouse I don't have an idea, to get the literal string of the WeekDay:Sturday.

Ciao
Olli

Re: [QVTo] Access EMF model enum value [message #548159 is a reply to message #544577] Tue, 20 July 2010 20:43 Go to previous message
Ryan is currently offline RyanFriend
Messages: 74
Registered: July 2009
Location: Indiana
Member
log(eEnum.getEEnumLiteralByLiteral(self.weekday.repr()).value.toString());


That seems to work. I'm curious what "self.weekday.repr()" returns, the name or the literal? And does it pull that representation out of the model, or out of your translated .properties files?
Previous Topic:Transformation between UML Profiles
Next Topic:[Xtend] Problem with a specific transformation
Goto Forum:
  


Current Time: Wed Apr 21 21:30:28 GMT 2021

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

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

Back to the top