|
|
Re: Polymorphism in XPand [message #61508 is a reply to message #61459] |
Sun, 24 May 2009 20:12 |
|
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 #61563 is a reply to message #61508] |
Sun, 24 May 2009 22:07 |
No real name 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
|
|
|
Powered by
FUDForum. Page generated in 0.03216 seconds