Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Persisting EAnnotations into an XMI file
Persisting EAnnotations into an XMI file [message #1697243] Tue, 02 June 2015 16:11 Go to next message
diophant diophant is currently offline diophant diophantFriend
Messages: 2
Registered: June 2015
Junior Member
Hi everyone

How do I get EAnnotations persisted into an XMI file as this example with an instance of an Eclipse UML Class shows:

org.eclipse.uml2.uml.Class _class = UMLFactory.eINSTANCE.createClass();
_class.setName("MyClass");
EcoreUtil.setAnnotation(_class, "myAnnotation", "myKey", "myValue");
ResourceSet resourceSet = new ResourceSetImpl();
Resource resource = resourceSet.createResource(URI.createFileURI("model.xmi"));
resource.getContents().add(_class);
try {
resource.save(new HashMap<String, String>());
} catch (IOException e) {
// Handle exception
}

Resulting XMI file:

<uml:Class xmi:version="20131001" xmlns:xmi=... xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML" xmi:id="_QHJAcQgwEeWapOrjTLkrLA" name="MyClass">
<eAnnotations xmi:id="_QHKOkAgwEeWapOrjTLkrLA" source="http://myAnnotation">
<details xmi:id="_QHKOkQgwEeWapOrjTLkrLA" key="myKey" value="myValue"/>
</eAnnotations>
</uml:Class>

However, this only seems to work with UML objects (instances of EClasses defined within the Eclipse UML meta model).
If I define my own EClass in my own Ecore model and although I set "org.eclipse.emf.ecore.impl.EModelElementImpl" as value for the "Root Extends Class" property of the corresponding generator model (which basically adds the capability to the generated classes to hold EAnnotations), EAnnotations are not persisted for any instance of that EClass.

<myModel:MyClass xmi:version="2.0" xmlns:xmi=... xmlns:myModel="http://myModel" id="myInstance"/>
^^^^^^^^^ eAnnotations element is missing!

Any hints?

Thanks!
Re: Persisting EAnnotations into an XMI file [message #1697259 is a reply to message #1697243] Tue, 02 June 2015 19:10 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33216
Registered: July 2009
Senior Member
Comments below.

On 02/06/2015 7:58 PM, diophant diophant wrote:
> Hi everyone
>
> How do I get EAnnotations persisted into an XMI file as this example
> with an instance of an Eclipse UML Class shows:
>
> org.eclipse.uml2.uml.Class _class = UMLFactory.eINSTANCE.createClass();
> _class.setName("MyClass");
> EcoreUtil.setAnnotation(_class, "myAnnotation", "myKey", "myValue");
> ResourceSet resourceSet = new ResourceSetImpl();
> Resource resource =
> resourceSet.createResource(URI.createFileURI("model.xmi"));
> resource.getContents().add(_class);
> try {
> resource.save(new HashMap<String, String>());
> } catch (IOException e) {
> // Handle exception
> }
>
> Resulting XMI file:
>
> <uml:Class xmi:version="20131001" xmlns:xmi=...
> xmlns:uml="http://www.eclipse.org/uml2/5.0.0/UML"
> xmi:id="_QHJAcQgwEeWapOrjTLkrLA" name="MyClass">
> <eAnnotations xmi:id="_QHKOkAgwEeWapOrjTLkrLA"
> source="http://myAnnotation">
> <details xmi:id="_QHKOkQgwEeWapOrjTLkrLA" key="myKey"
> value="myValue"/>
> </eAnnotations>
> </uml:Class>
>
> However, this only seems to work with UML objects (instances of
> EClasses defined within the Eclipse UML meta model).
It only works for subclasses of EModelElement.
> If I define my own EClass in my own Ecore model and although I set
> "org.eclipse.emf.ecore.impl.EModelElementImpl" as value for the "Root
> Extends Class"
You must not do that. The Root Extends Class must be purely an
implementation class that doesn't have modeled state.
> property of the corresponding generator model (which basically adds
> the capability to the generated classes to hold EAnnotations),
> EAnnotations are not persisted for any instance of that EClass.
You can extend EModelElement explicitly, but that's not recommend.
>
> <myModel:MyClass xmi:version="2.0" xmlns:xmi=...
> xmlns:myModel="http://myModel" id="myInstance"/>
> ^^^^^^^^^ eAnnotations element is missing!
>
> Any hints?

Best you define your own annotation representation in your own model,
i.e., copy the pattern that you see in Ecore, but don't extend Ecore.
>
> Thanks!


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Persisting EAnnotations into an XMI file [message #1697314 is a reply to message #1697259] Wed, 03 June 2015 06:29 Go to previous message
diophant diophant is currently offline diophant diophantFriend
Messages: 2
Registered: June 2015
Junior Member
Thank you very much for your help!
Previous Topic:ClassifierId across different but related models
Next Topic:container vs containment
Goto Forum:
  


Current Time: Thu Sep 19 04:06:34 GMT 2024

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

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

Back to the top