Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » M2T (model-to-text transformation) » [Acceleo] how to get the ID of an EObject
icon5.gif  [Acceleo] how to get the ID of an EObject [message #761698] Tue, 06 December 2011 22:48 Go to next message
pessi mistisch is currently offline pessi mistischFriend
Messages: 6
Registered: October 2011
Junior Member
I need the id of an Element (the one that I can see in the XML serialization of a model).

Basically I tried the following approach: (without getting errors but also without getting the ID):

[module generate('myMetamodel') /]
[query public getID(aElement : Element) : String = invoke('org.eclipse.emf.ecore.util.EcoreUtil','getID(org.eclipse.emf.ecore.EObject)', Sequence{aElement})/]

[template public MyTemplate(aSpecialElement: SpecialElement)]
[aSpecialElement.getID() /]
[aSpecialElement.myAttributeName /]
[/template]


(where "aSpecialElement" is a specialization of "aElement")

The assigned "MyAttributeName" appears, so I think there is no problem with the remainder of my code.

What is my fault or is there an easier way that I have overseen?

Any help is greatly appreciated!
Thanks.
Re: [Acceleo] how to get the ID of an EObject [message #761882 is a reply to message #761698] Wed, 07 December 2011 08:17 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
Hi,

There are two kind of "ID" for an EObject : the ID attribute, which can be retrieved with EcoreUtil.getID and corresponds to an attribute you've set as being the identifier of your object in the genmodel; or the XMI ID which appears in the serialized model as
xmi:id="..."
.

I believe what you seek is the second form, yet you're trying to access it through the first's accessor. Neither Acceleo nor EMF provide easy access to the XMI ID, you need a Java method that does the following :

public String getXMIID(EObject eObject) {
    if (eObject.eResource() instanceof XMIResource) {
        return ((XMIResource)eObject.eResource()).getID(eObject);
    }
    return "";
}


Laurent Goubet
Obeo
icon7.gif  Re: [Acceleo] how to get the ID of an EObject [message #762144 is a reply to message #761882] Wed, 07 December 2011 15:58 Go to previous message
pessi mistisch is currently offline pessi mistischFriend
Messages: 6
Registered: October 2011
Junior Member
Thanks a lot, it works fine! Smile
Previous Topic:index inside for
Next Topic:[Xpand] Access ClassAttribute before DEFINE Class
Goto Forum:
  


Current Time: Tue Apr 23 17:36:39 GMT 2024

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

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

Back to the top