Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » Polymorphism in XPand
Polymorphism in XPand [message #61459] Sat, 23 May 2009 12:52 Go to next message
No real name is currently offline No real nameFriend
Messages: 61
Registered: July 2009
Member
Hi,

Im trying to use the polymorphism-abillity of XPand but it does not work.
I have a model, which is based on a metamodel, which references the
UML2-metamodel (so it extends this model). Now I have this template:

«IMPORT otml»
«IMPORT uml»

«DEFINE main FOR Model»
«EXPAND showpackages FOREACH this.nestedPackage»
«ENDDEFINE»

«DEFINE showpackages FOR Package»
«EXPAND createFile(this.name) FOREACH this.packagedElement»
«ENDDEFINE»

«DEFINE createFile(String packageName) FOR Team»
«FILE packageName + "\\" + this.name + ".java"»
Team: «this.name»
«ENDFILE»
«ENDDEFINE»

«DEFINE createFile(String packageName) FOR Class»
«FILE packageName + "\\" + this.name + ".java"»
Class: «this.name»
«ENDFILE»
«ENDDEFINE»

«DEFINE createFile(String packageName) FOR PackagableElement»
«FILE packageName + "\\" + this.name + ".txt"»
Else: «this.name»
«ENDFILE»
«ENDDEFINE»

So the right Template "createFile" should be called depending on the
current metamodel-type. But unfortunatly the metamodel-type "Team" (which
extends Class) is ignored, and the createFile for "Class" is used instead.

Here my model file:

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1"
xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
xmlns:otml="http://www.objectteams.org/otml/1.0.0/OTML"
xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
xmi:id="_nmD24UeJEd6Jr-DmR61PUg">
<packagedElement xmi:type="uml:Package" xmi:id="_nmD24keJEd6Jr-DmR61PUg"
name="foo">
<packagedElement xmi:type="uml:Class" xmi:id="_nmD240eJEd6Jr-DmR61PUg"
name="Main"/>
<packagedElement xmi:type="otml:TeamClass"
xmi:id="_nmD25EeJEd6Jr-DmR61PUg" name="ATeam"/>
</packagedElement>
</uml:Model>

What am I doing wrong? The XPand-reference tells me, that the most
specific templates are used: "Xpand will use the corresponding subclass
template, in case the template is called for the superclass.". But that
does not work in my case.

Thanks for any help!
Re: Polymorphism in XPand [message #61484 is a reply to message #61459] Sun, 24 May 2009 18:15 Go to previous messageGo to next message
Sven Efftinge is currently offline Sven EfftingeFriend
Messages: 1823
Registered: July 2009
Senior Member
Usul wrote:

> «DEFINE createFile(String packageName) FOR Team»
> «FILE packageName + "\\" + this.name + ".java"»
> Team: «this.name»
> «ENDFILE»
> «ENDDEFINE»

In the template the name of the type is "Team", ...

> Here my model file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:otml="http://www.objectteams.org/otml/1.0.0/OTML"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_nmD24UeJEd6Jr-DmR61PUg">
> <packagedElement xmi:type="uml:Package"
> xmi:id="_nmD24keJEd6Jr-DmR61PUg" name="foo">
> <packagedElement xmi:type="uml:Class"
> xmi:id="_nmD240eJEd6Jr-DmR61PUg" name="Main"/>
> <packagedElement xmi:type="otml:TeamClass"
> xmi:id="_nmD25EeJEd6Jr-DmR61PUg" name="ATeam"/>
> </packagedElement>
> </uml:Model>

.... but looking at your model the name is "TeamClass".

If this is not the problem, please tell us what 'MetaModel' adapter (the
<metaModel/> element in your workflow) you use (i.e. EMF or UML2).
Also you should get an error marker in the template if you've enabled
the Xpand nature for your project and the Xpand file is in a project's
source folder.

Regards,
Sven
Re: Polymorphism in XPand [message #61508 is a reply to message #61459] Sun, 24 May 2009 20:12 Go to previous messageGo to next message
Karsten Thoms is currently offline Karsten ThomsFriend
Messages: 762
Registered: July 2009
Location: Dortmund, Germany
Senior Member

Usually the right way to extend UML metatypes is not to derive from
them, but rather use the UML profile mechanism. You create stereotypes
that refer to a base metatype (here: stereotype "TeamClass" extending
"Class") and then use the ProfileMetaModel, which would then derive a
virtual TeamClass type that extends the uml::Class type. Basically this
is what you want to achieve.
I'm not sure why your extension does not work, although basically I
think it should do so. However, you should consider to use standard
profiling extensions to extend UML types.

~Karsten

On 23.05.09 14:52, Usul wrote:
> Hi,
>
> Im trying to use the polymorphism-abillity of XPand but it does not
> work. I have a model, which is based on a metamodel, which references
> the UML2-metamodel (so it extends this model). Now I have this template:
>
> «IMPORT otml»
> «IMPORT uml»
>
> «DEFINE main FOR Model»
> «EXPAND showpackages FOREACH this.nestedPackage» «ENDDEFINE»
>
> «DEFINE showpackages FOR Package»
> «EXPAND createFile(this.name) FOREACH this.packagedElement» «ENDDEFINE»
>
> «DEFINE createFile(String packageName) FOR Team»
> «FILE packageName + "\\" + this.name + ".java"»
> Team: «this.name»
> «ENDFILE»
> «ENDDEFINE»
>
> «DEFINE createFile(String packageName) FOR Class»
> «FILE packageName + "\\" + this.name + ".java"»
> Class: «this.name»
> «ENDFILE»
> «ENDDEFINE»
>
> «DEFINE createFile(String packageName) FOR PackagableElement»
> «FILE packageName + "\\" + this.name + ".txt"»
> Else: «this.name»
> «ENDFILE»
> «ENDDEFINE»
>
> So the right Template "createFile" should be called depending on the
> current metamodel-type. But unfortunatly the metamodel-type "Team"
> (which extends Class) is ignored, and the createFile for "Class" is used
> instead.
>
> Here my model file:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <uml:Model xmi:version="2.1"
> xmlns:xmi="http://schema.omg.org/spec/XMI/2.1"
> xmlns:otml="http://www.objectteams.org/otml/1.0.0/OTML"
> xmlns:uml="http://www.eclipse.org/uml2/3.0.0/UML"
> xmi:id="_nmD24UeJEd6Jr-DmR61PUg">
> <packagedElement xmi:type="uml:Package" xmi:id="_nmD24keJEd6Jr-DmR61PUg"
> name="foo">
> <packagedElement xmi:type="uml:Class" xmi:id="_nmD240eJEd6Jr-DmR61PUg"
> name="Main"/>
> <packagedElement xmi:type="otml:TeamClass"
> xmi:id="_nmD25EeJEd6Jr-DmR61PUg" name="ATeam"/>
> </packagedElement>
> </uml:Model>
>
> What am I doing wrong? The XPand-reference tells me, that the most
> specific templates are used: "Xpand will use the corresponding subclass
> template, in case the template is called for the superclass.". But that
> does not work in my case.
>
> Thanks for any help!
>


Need professional support for Xtext, EMF, Eclipse IDE?
Go to: http://devhub.karakun.com
Twitter : @kthoms
Blog : www.karsten-thoms.de
Re: Polymorphism in XPand [message #61546 is a reply to message #61484] Sun, 24 May 2009 22:02 Go to previous messageGo to next message
No real name is currently offline No real nameFriend
Messages: 61
Registered: July 2009
Member
Hi,



>> «DEFINE createFile(String packageName) FOR Team»
>> «FILE packageName + "\" + this.name + ".java"»
>> Team: «this.name»
>> «ENDFILE»
>> «ENDDEFINE»

> In the template the name of the type is "Team", ...

> .... but looking at your model the name is "TeamClass".

Uhh... right. OK, Im sorry. I should have seen this myself. Thanks a
lot!


> If this is not the problem, please tell us what 'MetaModel' adapter (the
> <metaModel/> element in your workflow) you use (i.e. EMF or UML2).
> Also you should get an error marker in the template if you've enabled
> the Xpand nature for your project and the Xpand file is in a project's
> source folder.

Good hint, thanks! I had my Xpand-file in a folder called-template. I
put it in the src-folder and now I have better code-checking. Good. That
leads to another problem, but that is a different post.

Thank you!
Re: Polymorphism in XPand [message #61563 is a reply to message #61508] Sun, 24 May 2009 22:07 Go to previous message
No real name is currently offline No real nameFriend
Messages: 61
Registered: July 2009
Member
Hi Karsten,

thank you for replying. Sven already solved my problem, which was based
on a rather stupid mistake from me.

> Usually the right way to extend UML metatypes is not to derive from
> them, but rather use the UML profile mechanism. You create stereotypes
> that refer to a base metatype (here: stereotype "TeamClass" extending
> "Class") and then use the ProfileMetaModel, which would then derive a
> virtual TeamClass type that extends the uml::Class type. Basically this
> is what you want to achieve.

Unfortunatly, I did not create that meta-model myself. So I dont have any
say in this. But as I understood, UML-profiles didn't suffice in that
case. I don't have any example right now, but as far as I remember, the
reason for not using UML-profiles were, that some important extentions
couln't be realized with them.


Thank you
Previous Topic:[Announce] M2T XPAND 0.7.0RC1 is available
Next Topic:XPand: String concatination
Goto Forum:
  


Current Time: Fri Mar 29 08:49:39 GMT 2024

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

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

Back to the top