Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » QVT-OML » Code style / Performance / Best practice question
Code style / Performance / Best practice question [message #899259] Tue, 31 July 2012 08:57 Go to next message
Eclipse UserFriend
Hello,

I convert from an input model which has a lot of abstract base classes
and references to those base classes. During the transformation I need
to figure out which concrete derived class is actually referenced. I
found two ways to do that:

Method A:
---------
mapping INMODEL::AbstractBase::theMapping() : OUTMODEL::SomeClass
{
switch {
case (self.oclIsKindOf(INMODEL::ClassA))
attrA := self.oclAsType(INMODEL::ClassA).map someClass();
case (self.oclIsKindOf(INMODEL::ClassB))
attrB := self.oclAsType(INMODEL::ClassB).map otherClass();
}
}


Method B:
---------
mapping INMODEL::AbstractBase::theMapping() : OUTMODEL::SomeClass
{
attrA := self[INMODEL::ClassA]->any(true).map someClass();
attrB := self[INMODEL::ClassB]->any(true).map otherClass()
}


It seems to me that the two methods behave identical. The first one
needs a cast and looks bloatier. The second one seems to be more concise
and does not need a cast. However, the "any(true)" seems a bit awkward.
So my questions really are:

1) which would be preferable in terms of "good QVT coding practice"?

2) which would be preferable in terms of performance?

3) if the answer to 1) is "neither": what would be a better way? Is
there maybe a way that QVT can dynamically choose the the right mapping?

BTW, the output is XML based on XSD. The above code maps to XSD elements
containing an xs:choice, of which there are a lot.

Thanks for any insights!

Marius
Re: Code style / Performance / Best practice question [message #899301 is a reply to message #899259] Tue, 31 July 2012 12:14 Go to previous messageGo to next message
Sebastian Lehrig is currently offline Sebastian LehrigFriend
Messages: 8
Registered: July 2012
Junior Member
Have you checked "Disjunction of Mapping Operations" as described in Section "8.1.13" of the QVT 1.1 Specification?

What you will get is something like (beware, untested code Wink ):
mapping INMODEL::AbstractBase::theMapping() : OUTMODEL::SomeClass disjuncts someClass(), otherClass() {}
mapping INMODEL::ClassA::someClass() : OUTMODEL::SomeClass { ... }
mapping INMODEL::ClassB::otherClass() : OUTMODEL::SomeClass { ... }

Wouldn't this do the job for you?

[Updated on: Tue, 31 July 2012 12:15]

Report message to a moderator

Re: Code style / Performance / Best practice question [message #899724 is a reply to message #899301] Thu, 02 August 2012 06:24 Go to previous message
Eclipse UserFriend
Hi Sebastian,

sorry for the late reply.

On 31.07.2012 14:14, Sebastian Lehrig wrote:
> Have you checked "Disjunction of Mapping Operations" as described in
> Section "8.1.13" of the QVT 1.1 Specification?
>
> What you will get is something like (beware, untested code ;) ):
> mapping INMODEL::AbstractBase::theMapping() : OUTMODEL::SomeClass
> disjuncts someClass(), otherClass() {}
> mapping INMODEL::ClassA::someClass() : JAVA::Field { ... }
> mapping INMODEL::ClassB::otherClass() : JAVA::Field { ... }
>
> Wouldn't this do the job for you?

Totally! I'll try that as soon as I can and will report back!

Thanks,
Marius
Previous Topic:Different versions - same metamodel
Next Topic:Best practice to check OCL invariants from inside QVTo script
Goto Forum:
  


Current Time: Wed Nov 26 19:06:22 GMT 2014

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

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