Skip to main content



      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 17:48 Go to next message
Eclipse UserFriend
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 03:17 Go to previous messageGo to next message
Eclipse UserFriend
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 10:58 Go to previous message
Eclipse UserFriend
Thanks a lot, it works fine! Smile
Previous Topic:index inside for
Next Topic:[Xpand] Access ClassAttribute before DEFINE Class
Goto Forum:
  


Current Time: Mon Jul 07 08:36:18 EDT 2025

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

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

Back to the top