Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] Cast between two metamodels (How to cast an object from a metamodel class to an other one )
[Acceleo] Cast between two metamodels [message #529628] Mon, 26 April 2010 15:11 Go to next message
Nicolas Guyomar is currently offline Nicolas GuyomarFriend
Messages: 29
Registered: February 2010
Location: Nantes (France)
Junior Member
Hi everyone

I'm trying to generate code from two metamodels, MA and MB.
The problem I'm facing is the following:

I have a class B in MB, which inherits from class A in MA.

I'd like to access some attributes in B, while I'm browsing classes A and B, like a basic Cast in java
Unfortunately, oclAsType() method works fine while I'm using classes from the same Metamodel, not if I want to use it with A and B like :
a.oclAsType(B), I get "Unrecognized variable: (B)" in

[template public write(a : A)]
    [for (n : Node | a.children)]
        [if (n.oclIsKindOf(Attribute))]
             [n.oclAsType(B).write()/]
        [/if] 
     [/for]
[/template]


Is there another way I'm not aware of to do this? maybe not using OCL ?

Regards

Nicolas




Re: [Acceleo] Cast between two metamodels [message #529782 is a reply to message #529628] Tue, 27 April 2010 08:24 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040204020007060002080507
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Hi Nicolas,

I believe OCL is just confused between your metamodels. Would
"a.oclAsType(MB::B)" do the trick?

(I recently made some tweaks in Acceleo so that the use of qualified
names for types will be useless in most cases ... but these changes
haven't been built yet)

Laurent Goubet
Obeo

Nicolas Guyomar wrote:
> Hi everyone
>
> I'm trying to generate code from two metamodels, MA and MB.
> The problem I'm facing is the following:
>
> I have a class B in MB, which inherits from class A in MA.
>
> I'd like to access some attributes in B, while I'm browsing classes A
> and B, like a basic Cast in java
> Unfortunately, oclAsType() method works fine while I'm using classes
> from the same Metamodel, not if I want to use it with A and B like :
> a.oclAsType(B), I get "Unrecognized variable: (B)" in
>
> [template public write(a : A)]
> [for (n : Node | a.children)]
> [if (n.oclIsKindOf(Attribute))]
> [n.oclAsType(B).write()/]
> [/if] [/for]
> [/template]
>
>
> Is there another way I'm not aware of to do this? maybe not using OCL ?
>
> Regards
>
> Nicolas
>
>
>


--------------040204020007060002080507
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------040204020007060002080507--
[Solved] [Acceleo] Cast between two metamodels [message #529799 is a reply to message #529782] Tue, 27 April 2010 09:29 Go to previous messageGo to next message
Nicolas Guyomar is currently offline Nicolas GuyomarFriend
Messages: 29
Registered: February 2010
Location: Nantes (France)
Junior Member
Hi Laurent,

Thank you for your quick answer

The solution you proposed works perfectly, I assume this syntax is pretty common in OCL .. shame on me

Thank you again

Nicolas



Re: [Solved] [Acceleo] Cast between two metamodels [message #529832 is a reply to message #529799] Tue, 27 April 2010 12:03 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------040806090006080500040407
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Nicolas,

It is a common syntax in OCL ... but I doubt many people know all of the
different things we can do with OCL :p.

Laurent Goubet
Obeo

Nicolas Guyomar wrote:
> Hi Laurent,
>
> Thank you for your quick answer
>
> The solution you proposed works perfectly, I assume this syntax is
> pretty common in OCL .. shame on me
>
> Thank you again
>
> Nicolas
>
>


--------------040806090006080500040407
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyIj5PYmVvPC9hPg0KZW1haWw7 aW50ZXJuZXQ6
bGF1cmVudC5nb3ViZXRAb2Jlby5mcg0KdXJsOmh0dHA6Ly93d3cub2Jlby5m cg0KdmVyc2lv
bjoyLjENCmVuZDp2Y2FyZA0KDQo=
--------------040806090006080500040407--
Previous Topic:[Xpand] Write an example conforming to model ?
Next Topic:[MWE] Package with uri 'http://www.eclipse.org/uml2/3.0.0/UML' not found
Goto Forum:
  


Current Time: Fri Apr 26 09:27:28 GMT 2024

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

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

Back to the top