Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Serialization problem concerning Maps
Serialization problem concerning Maps [message #552429] Thu, 12 August 2010 08:27 Go to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 71
Registered: July 2009
Member
I want to serialize my model to XMI. In my model there are maps which I want to serialize, too. I want to save the key and the value of each map entry. How can I do this?

I use the resource set. I do it like that:

ResourceSet resourceSet = new ResourceSetImpl();
resourceSet.getResourceFactoryRegistry().getExtensionToFactoryMap().put("xmi", new XMIResourceFactoryImpl());
Resource resource = resourceSet.createResource(URI.createFileURI("some file name"));
resource.getContents().add(form);
resource.save(null);


So far no problem but my maps store only the keys.

One map is defined as Java interface like this:

/**
 * @model
 */
public interface Variables extends EObject {

 /**
  * @return
  * @model mapType="HashMap" keyType="String" valueType="VartabEntry" containment="true"
     */
 EMap<String, VartabEntry> getVartabEntriesMap();


And VartabEntry is defined like this:

/**
 * @model
 */
public interface VartabEntry extends EObject  {
    
    /**
     * @return
     * @model
     */
    String getEnglishName();

   /**
     * @return
     * @model
     */
    String getName();

   ... and more attributes.


And I got following XMI part in my file:

  <variables>
    <vartabEntriesMap key="0:grust"/>
    <vartabEntriesMap key="0:gruppe"/>
    <vartabEntriesMap key="0:grbez"/>
    <vartabEntriesMap key="0:dnr"/>
    <vartabEntriesMap key="0:dbez"/>
    <vartabEntriesMap key="0:ozeilen"/>
    <vartabEntriesMap key="0:sn"/>

...
  </variables>



How can I tell EMF to store also the VartabEntry instances in the XMI file?

With regards,
Udo
Re: Serialization problem concerning Maps [message #552565 is a reply to message #552429] Thu, 12 August 2010 16:01 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30559
Registered: July 2009
Senior Member
Udo,

Comments below.

Udo wrote:
> I want to serialize my model to XMI. In my model there are maps which
> I want to serialize, too. I want to save the key and the value of each
> map entry. How can I do this?
>
> I use the resource set. I do it like that:
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xmi",
> new XMIResourceFactoryImpl());
> Resource resource = resourceSet.createResource(URI.createFileURI("some
> file name"));
> resource.getContents().add(form);
> resource.save(null);
>
>
> So far no problem but my maps store only the keys.
>
> One map is defined as Java interface like this:
>
>
> /**
> * @model
> */
> public interface Variables extends EObject {
>
> /**
> * @return
> * @model mapType="HashMap" keyType="String" valueType="VartabEntry"
> containment="true"
> */
> EMap<String, VartabEntry> getVartabEntriesMap();
Did you look at the FAQ how to do this?
>
>
> And VartabEntry is defined like this:
>
>
> /**
> * @model
> */
> public interface VartabEntry extends EObject {
> /**
> * @return
> * @model
> */
> String getEnglishName();
>
> /**
> * @return
> * @model
> */
> String getName();
>
> ... and more attributes.
>
You'd not define an explicit interface for the map entry. Did you
look at how EAnnotation.getDetails works?
>
> And I got following XMI part in my file:
>
>
> <variables>
> <vartabEntriesMap key="0:grust"/>
> <vartabEntriesMap key="0:gruppe"/>
> <vartabEntriesMap key="0:grbez"/>
> <vartabEntriesMap key="0:dnr"/>
> <vartabEntriesMap key="0:dbez"/>
> <vartabEntriesMap key="0:ozeilen"/>
> <vartabEntriesMap key="0:sn"/>
>
> ..
> </variables>
>
>
>
> How can I tell EMF to store also the VartabEntry instances in the XMI
> file?
>
> With regards,
> Udo
>
Re: Serialization problem concerning Maps [message #553052 is a reply to message #552565] Mon, 16 August 2010 09:30 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 71
Registered: July 2009
Member
Hi Ed,

comments below.

Ed Merks wrote on Thu, 12 August 2010 12:01
Udo,

Comments below.

Udo wrote:
> I want to serialize my model to XMI. In my model there are maps which
> I want to serialize, too. I want to save the key and the value of each
> map entry. How can I do this?
>
> I use the resource set. I do it like that:
>
>
> ResourceSet resourceSet = new ResourceSetImpl();
> resourceSet.getResourceFactoryRegistry().getExtensionToFacto ryMap().put( "xmi",
> new XMIResourceFactoryImpl());
> Resource resource = resourceSet.createResource(URI.createFileURI("some
> file name"));
> resource.getContents().add(form);
> resource.save(null);
>
>
> So far no problem but my maps store only the keys.
>
> One map is defined as Java interface like this:
>
>
> /**
> * @model
> */
> public interface Variables extends EObject {
>
> /**
> * @return
> * @model mapType="HashMap" keyType="String" valueType="VartabEntry"
> containment="true"
> */
> EMap<String, VartabEntry> getVartabEntriesMap();
Did you look at the FAQ how to do this?

As I understand the FAQ I did the right thing with my "@model" annotations.
EMF generated the class EStringToVartabEntryMapEntryImpl.

Do I have to add some methods to that generated class?

My ecore model looks like this (for the generated class):

  <eClassifiers xsi:type="ecore:EClass" name="EStringToVartabEntryMapEntry" instanceClassName="java.util.Map$Entry">
    <eStructuralFeatures xsi:type="ecore:EAttribute" name="key" eType="ecore:EDataType platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//EString"/>
    <eStructuralFeatures xsi:type="ecore:EReference" name="value" eType="#//VartabEntry"/>
  </eClassifiers>


Is this correct?

>
>
> And VartabEntry is defined like this:
>
>
> /**
> * @model
> */
> public interface VartabEntry extends EObject {
> /**
> * @return
> * @model
> */
> String getEnglishName();
>
> /**
> * @return
> * @model
> */
> String getName();
>
> ... and more attributes.
>
You'd not define an explicit interface for the map entry. Did you
look at how EAnnotation.getDetails works?

I do not understand, why I should not define an interface for my "value" type. What should I implement to serialize that correctly. I saw that EAnnotation.getDetails tries to get the serialized form of my value type but where do I specify it?
>
> And I got following XMI part in my file:
>
>
> <variables>
> <vartabEntriesMap key="0:grust"/>
> <vartabEntriesMap key="0:gruppe"/>
> <vartabEntriesMap key="0:grbez"/>
> <vartabEntriesMap key="0:dnr"/>
> <vartabEntriesMap key="0:dbez"/>
> <vartabEntriesMap key="0:ozeilen"/>
> <vartabEntriesMap key="0:sn"/>
>
> ..
> </variables>
>
>
>
> How can I tell EMF to store also the VartabEntry instances in the XMI
> file?
>
> With regards,
> Udo
>

Re: Serialization problem concerning Maps [message #553098 is a reply to message #553052] Mon, 16 August 2010 13:27 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30559
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070502020401070906050607
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Udo,

Comments below.

Udo wrote:
> Hi Ed,
> comments below.
>
> Ed Merks wrote on Thu, 12 August 2010 12:01
>> Udo,
>>
>> Comments below.
>>
>> Udo wrote:
>> > I want to serialize my model to XMI. In my model there are maps
>> which > I want to serialize, too. I want to save the key and the
>> value of each > map entry. How can I do this?
>> >
>> > I use the resource set. I do it like that:
>> >
>> >
>> > ResourceSet resourceSet = new ResourceSetImpl();
>> > resourceSet.getResourceFactoryRegistry().getExtensionToFacto
>> ryMap().put( "xmi", > new XMIResourceFactoryImpl());
>> > Resource resource =
>> resourceSet.createResource(URI.createFileURI("some > file name"));
>> > resource.getContents().add(form);
>> > resource.save(null);
>> >
>> >
>> > So far no problem but my maps store only the keys.
>> >
>> > One map is defined as Java interface like this:
>> >
>> >
>> > /**
>> > * @model
>> > */
>> > public interface Variables extends EObject {
>> >
>> > /**
>> > * @return
>> > * @model mapType="HashMap" keyType="String"
>> valueType="VartabEntry" > containment="true"
>> > */
>> > EMap<String, VartabEntry> getVartabEntriesMap();
>> Did you look at the FAQ how to do this?
>>
>> As I understand the FAQ I did the right thing with my "@model"
>> annotations.
The FAQ looked like this.

/**
* @model keyType="java.lang.String" valueType="java.lang.String"
*/
Map<String, String> getScoScoMap();


And EAnnotation.details looks like this:

/**
* @model
mapType="org.eclipse.emf.ecore.EStringToStringMapEntry<org.eclipse.emf.ecore.EString,
org.eclipse.emf.ecore.EString>"
*/
EMap<String, String> getDetails();

Things to note are fully qualified names. In fact, note that in
EAnnotation, the fully qualified names are Ecore names, not Java names.
There's also no use of containment='true'.
>> EMF generated the class EStringToVartabEntryMapEntryImpl.
Yes, but there is no EStringToVartabMapEntry interface. I.e., there's
nothing like your VartabEntry.
>>
>> Do I have to add some methods to that generated class?
>>
>> My ecore model looks like this (for the generated class):
>>
>>
>> <eClassifiers xsi:type="ecore:EClass"
>> name="EStringToVartabEntryMapEntry"
>> instanceClassName="java.util.Map$Entry">
>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="key"
>> eType="ecore:EDataType
>> platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//E String "/>
>> <eStructuralFeatures xsi:type="ecore:EReference" name="value"
>> eType="#//VartabEntry"/>
>> </eClassifiers>
>>
>>
>> Is this correct?
You don't want the value to be of type VartabEntry though do you? I
assume you want it to be string like in the FAQ example and in EAnnotation.
>>
>> >
>> >
>> > And VartabEntry is defined like this:
>> >
>> >
>> > /**
>> > * @model
>> > */
>> > public interface VartabEntry extends EObject {
>> > /**
>> > * @return
>> > * @model
>> > */
>> > String getEnglishName();
>> >
>> > /**
>> > * @return
>> > * @model
>> > */
>> > String getName();
>> >
>> > ... and more attributes.
>> >
>> You'd not define an explicit interface for the map entry. Did you
>> look at how EAnnotation.getDetails works?
>>
>> I do not understand, why I should not define an interface for my
>> "value" type. What should I implement to serialize that correctly. I
>> saw that EAnnotation.getDetails tries to get the serialized form of
>> my value type but where do I specify it?
>> >
>> > And I got following XMI part in my file:
>> >
>> >
>> > <variables>
>> > <vartabEntriesMap key="0:grust"/>
>> > <vartabEntriesMap key="0:gruppe"/>
>> > <vartabEntriesMap key="0:grbez"/>
>> > <vartabEntriesMap key="0:dnr"/>
>> > <vartabEntriesMap key="0:dbez"/>
>> > <vartabEntriesMap key="0:ozeilen"/>
>> > <vartabEntriesMap key="0:sn"/>
>> >
>> > ..
>> > </variables>
>> >
>> >
>> >
>> > How can I tell EMF to store also the VartabEntry instances in the
>> XMI > file?
>> >
>> > With regards,
>> > Udo
>> >
>
>

--------------070502020401070906050607
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Udo,<br>
<br>
Comments below.  <br>
<br>
Udo wrote:
<blockquote cite="mid:i4b0ge$jc7$1@build.eclipse.org" type="cite">Hi
Ed, <br>
comments below.
<br>
<br>
Ed Merks wrote on Thu, 12 August 2010 12:01
<br>
<blockquote type="cite">Udo,
<br>
<br>
Comments below.
<br>
<br>
Udo wrote:
<br>
&gt; I want to serialize my model to XMI. In my model there are maps
which &gt; I want to serialize, too. I want to save the key and the
value of each &gt; map entry. How can I do this?
<br>
&gt;
<br>
&gt; I use the resource set. I do it like that:
<br>
&gt;
<br>
&gt;
<br>
&gt; ResourceSet resourceSet = new ResourceSetImpl();
<br>
&gt;   resourceSet.getResourceFactoryRegistry().getExtensionToFacto
ryMap().put( "xmi", &gt; new XMIResourceFactoryImpl());
<br>
&gt; Resource resource =
resourceSet.createResource(URI.createFileURI("some &gt; file name"));
<br>
&gt; resource.getContents().add(form);
<br>
&gt; resource.save(null);
<br>
&gt;
<br>
&gt;
<br>
&gt; So far no problem but my maps store only the keys.
<br>
&gt;
<br>
&gt; One map is defined as Java interface like this:
<br>
&gt;
<br>
&gt;
<br>
&gt; /**
<br>
&gt; * @model
<br>
&gt; */
<br>
&gt; public interface Variables extends EObject {
<br>
&gt;
<br>
&gt; /**
<br>
&gt;  * @return
<br>
&gt;  * @model mapType="HashMap" keyType="String"
valueType="VartabEntry" &gt; containment="true"
<br>
&gt;     */
<br>
&gt; EMap&lt;String, VartabEntry&gt; getVartabEntriesMap();
<br>
Did you look at the FAQ how to do this?
<br>
<br>
As I understand the FAQ I did the right thing with my "@model"
annotations.  <br>
</blockquote>
</blockquote>
The FAQ looked like this.<br>
<blockquote>
<pre class="source-java5"><span class="coMULTI">/**
* @model keyType="java.lang.String" valueType="java.lang.String"
*/</span>
Map&lt;String, String&gt; getScoScoMap<span class="br0">(</span><span
class="br0">)</span>;
</pre>
</blockquote>
And EAnnotation.details looks like this:<br>
<blockquote>  /**<br>
   * @model
mapType=" org.eclipse.emf.ecore.EStringToStringMapEntry&lt;org.ecl ipse.emf.ecore.EString,
org.eclipse.emf.ecore.EString&gt;"<br>
   */<br>
  EMap&lt;String, String&gt; getDetails();<br>
</blockquote>
Things to note are fully qualified names.  In fact, note that in
EAnnotation, the fully qualified names are Ecore names, not Java
names.  There's also no use of containment='true'.<br>
<blockquote cite="mid:i4b0ge$jc7$1@build.eclipse.org" type="cite">
<blockquote type="cite"> EMF generated the class
EStringToVartabEntryMapEntryImpl.
<br>
</blockquote>
</blockquote>
Yes, but there is no EStringToVartabMapEntry interface.   I.e., there's
nothing like your VartabEntry.
<blockquote cite="mid:i4b0ge$jc7$1@build.eclipse.org" type="cite">
<blockquote type="cite"><br>
Do I have to add some methods to that generated class?
<br>
<br>
My ecore model looks like this (for the generated class):
<br>
<br>
<br>
  &lt;eClassifiers xsi:type="ecore:EClass"
name="EStringToVartabEntryMapEntry"
instanceClassName="java.util.Map$Entry"&gt;
<br>
    &lt;eStructuralFeatures xsi:type="ecore:EAttribute" name="key"
eType="ecore:EDataType
platform:/plugin/org.eclipse.emf.ecore/model/Ecore.ecore#//E String "/&gt;
<br>
    &lt;eStructuralFeatures xsi:type="ecore:EReference" name="value"
eType="#//VartabEntry"/&gt;
<br>
  &lt;/eClassifiers&gt;
<br>
<br>
<br>
Is this correct?
<br>
</blockquote>
</blockquote>
You don't want the value to be of type VartabEntry though do you?  I
assume you want it to be string like in the FAQ example and in
EAnnotation.<br>
<blockquote cite="mid:i4b0ge$jc7$1@build.eclipse.org" type="cite">
<blockquote type="cite"><br>
&gt;
<br>
&gt;
<br>
&gt; And VartabEntry is defined like this:
<br>
&gt;
<br>
&gt;
<br>
&gt; /**
<br>
&gt; * @model
<br>
&gt; */
<br>
&gt; public interface VartabEntry extends EObject  {
<br>
&gt;       /**
<br>
&gt;     * @return
<br>
&gt;     * @model
<br>
&gt;     */
<br>
&gt;    String getEnglishName();
<br>
&gt;
<br>
&gt;   /**
<br>
&gt;     * @return
<br>
&gt;     * @model
<br>
&gt;     */
<br>
&gt;    String getName();
<br>
&gt;
<br>
&gt;   ... and more attributes.
<br>
&gt;
<br>
You'd not define an explicit interface for the map entry.    Did you
look at how EAnnotation.getDetails works?
<br>
<br>
I do not understand, why I should not define an interface for my
"value" type. What should I implement to serialize that correctly. I
saw that EAnnotation.getDetails tries to get the serialized form of my
value type but where do I specify it?
<br>
&gt;
<br>
&gt; And I got following XMI part in my file:
<br>
&gt;
<br>
&gt;
<br>
&gt;  &lt;variables&gt;
<br>
&gt;    &lt;vartabEntriesMap key="0:grust"/&gt;
<br>
&gt;    &lt;vartabEntriesMap key="0:gruppe"/&gt;
<br>
&gt;    &lt;vartabEntriesMap key="0:grbez"/&gt;
<br>
&gt;    &lt;vartabEntriesMap key="0:dnr"/&gt;
<br>
&gt;    &lt;vartabEntriesMap key="0:dbez"/&gt;
<br>
&gt;    &lt;vartabEntriesMap key="0:ozeilen"/&gt;
<br>
&gt;    &lt;vartabEntriesMap key="0:sn"/&gt;
<br>
&gt;
<br>
&gt; ..
<br>
&gt;  &lt;/variables&gt;
<br>
&gt;
<br>
&gt;
<br>
&gt;
<br>
&gt; How can I tell EMF to store also the VartabEntry instances in the
XMI &gt; file?
<br>
&gt;
<br>
&gt; With regards,
<br>
&gt; Udo
<br>
&gt;
<br>
</blockquote>
<br>
<br>
</blockquote>
</body>
</html>

--------------070502020401070906050607--
Re: Serialization problem concerning Maps [message #553948 is a reply to message #553098] Thu, 19 August 2010 13:51 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 71
Registered: July 2009
Member
Hi Ed,

I think you got me wrong.

I do want to have a map which has keys of type String and values of type VartabEntry. The only thing which I do not understand is how do I tell the generated class EStringToVartabEntryMapEntryImpl to serialize its keys AND values. It serializes only its keys, which are serialized correctly.

Or can I not use a map like I want to use?

Regards,
Udo
Re: Serialization problem concerning Maps [message #553961 is a reply to message #553948] Thu, 19 August 2010 14:18 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30559
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020801050208000902000106
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit

Udo,

Comments below.

Udo wrote:
> Hi Ed,
>
> I think you got me wrong.
>
> I do want to have a map which has keys of type String and values of
> type VartabEntry.
Oh.
> The only thing which I do not understand is how do I tell the
> generated class EStringToVartabEntryMapEntryImpl to serialize its keys
> AND values. It serializes only its keys, which are serialized correctly.
I see nothing that should prevent that feature from being serialized.
You're sure it's actually populated with non-null values?
>
> Or can I not use a map like I want to use?
The Change model has maps with references so it should work...

* @model
mapType="org.eclipse.emf.ecore.change.EObjectToChangesMapEntry <org.eclipse.emf.ecore.EObject,
org.eclipse.emf.ecore.change.FeatureChange>"
* @generated
*/
EMap<EObject, EList<FeatureChange>> getObjectChanges();

Check during serialization if eIsSet is being called for the value
feature of the map entry and if it's returning true. It should be
serialized in that case.
>
> Regards,
> Udo
>

--------------020801050208000902000106
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Udo,<br>
<br>
Comments below.<br>
<br>
Udo wrote:
<blockquote cite="mid:i4jcsc$agh$1@build.eclipse.org" type="cite">Hi
Ed,
<br>
<br>
I think you got me wrong.
<br>
<br>
I do want to have a map which has keys of type String and values of
type VartabEntry.</blockquote>
Oh.<br>
<blockquote cite="mid:i4jcsc$agh$1@build.eclipse.org" type="cite"> The
only thing which I do not understand is how do I tell the generated
class EStringToVartabEntryMapEntryImpl to serialize its keys AND
values. It serializes only its keys, which are serialized correctly.
<br>
</blockquote>
I see nothing that should prevent that feature from being serialized. 
You're sure it's actually populated with non-null values?<br>
<blockquote cite="mid:i4jcsc$agh$1@build.eclipse.org" type="cite"><br>
Or can I not use a map like I want to use?
<br>
</blockquote>
The Change model has maps with references so it should work...<br>
<blockquote>   * @model
mapType=" org.eclipse.emf.ecore.change.EObjectToChangesMapEntry&lt ;org.eclipse.emf.ecore.EObject,
org.eclipse.emf.ecore.change.FeatureChange&gt;"<br>
   * @generated<br>
   */<br>
  EMap&lt;EObject, EList&lt;FeatureChange&gt;&gt; getObjectChanges();<br>
</blockquote>
Check during serialization if eIsSet is being called for the value
feature of the map entry and if it's returning true.  It should be
serialized in that case.<br>
<blockquote cite="mid:i4jcsc$agh$1@build.eclipse.org" type="cite"><br>
Regards,
<br>
Udo
<br>
<br>
</blockquote>
</body>
</html>

--------------020801050208000902000106--
Re: Serialization problem concerning Maps [message #555600 is a reply to message #553961] Fri, 27 August 2010 09:48 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 71
Registered: July 2009
Member
Hi Ed,

Quote:
Check during serialization if eIsSet is being called for the value
feature of the map entry and if it's returning true. It should be
serialized in that case.



I checked the method eIsSet of my EStringToVartabEntryMapEntryImpl and it returns true. I did this by overwriting the method eIsSet in that class and checking the name of the feature and value of the super.eIsSet() method. The value feature returns true.

My output still looks like this:

 <variables>
    <vartabEntriesMap key="0:grust"/>
    <vartabEntriesMap key="0:gruppe"/>
    <vartabEntriesMap key="0:grbez"/>
    <vartabEntriesMap key="0:dnr"/>
    <vartabEntriesMap key="0:dbez"/>
    <vartabEntriesMap key="0:ozeilen"/>
...


Still only keys.

Do you have any ideas what I could do wrong?

Re: Serialization problem concerning Maps [message #555664 is a reply to message #555600] Fri, 27 August 2010 14:12 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30559
Registered: July 2009
Senior Member
Udo,

The debugger is doing to answer your questions faster than me. Monitor
what happens in XMLSaveImpl.saveFeatures for your map entry instances.
Pay particular attention to the processing of the features where there
is a guard like this

if (kind != TRANSIENT && shouldSaveFeature(o, f))


Udo wrote:
> Hi Ed,
>
> Quote:
>> Check during serialization if eIsSet is being called for the value
>> feature of the map entry and if it's returning true. It should be
>> serialized in that case.
>
>
> I checked the method eIsSet of my EStringToVartabEntryMapEntryImpl and
> it returns true. I did this by overwriting the method eIsSet in that
> class and checking the name of the feature and value of the
> super.eIsSet() method. The value feature returns true.
>
> My output still looks like this:
>
>
> <variables>
> <vartabEntriesMap key="0:grust"/>
> <vartabEntriesMap key="0:gruppe"/>
> <vartabEntriesMap key="0:grbez"/>
> <vartabEntriesMap key="0:dnr"/>
> <vartabEntriesMap key="0:dbez"/>
> <vartabEntriesMap key="0:ozeilen"/>
> ..
>
>
> Still only keys.
> Do you have any ideas what I could do wrong?
>
>
Re: Serialization problem concerning Maps [message #638066 is a reply to message #555664] Tue, 09 November 2010 18:55 Go to previous messageGo to next message
Udo Walker is currently offline Udo WalkerFriend
Messages: 71
Registered: July 2009
Member
Hi Ed,

I found a solution but I don't know how to do it with annotations in my
interfaces.

If I open the *.ecore file and go to the value feature of the map and
change the containment from (default) "false" to "true" then the value
which is my from EMF generated object is also saved.

How can I tell the EMF generator with Java annotations that the value of
my map needs the containment attribute set to "true"?

Here is the snippet from my ecore file:

<eClassifiers xsi:type="ecore:EClass" name="VartabEntryMap"
instanceClassName="java.util.Map$Entry">
<eStructuralFeatures
xsi:type="ecore:EAttribute"
name="key"
eType="ecore:EDataType
http://www.eclipse.org/emf/2002/Ecore#//EString"/>
<eStructuralFeatures
xsi:type="ecore:EReference"
name="value"
eType="#//VartabEntry"
containment="true"/>
</eClassifiers>

The second last line is the important one. How to do that in Java
annotations?

Udo


Am 27.08.2010 16:12, schrieb Ed Merks:
> Udo,
>
> The debugger is doing to answer your questions faster than me. Monitor
> what happens in XMLSaveImpl.saveFeatures for your map entry instances.
> Pay particular attention to the processing of the features where there
> is a guard like this
>
> if (kind != TRANSIENT && shouldSaveFeature(o, f))
>
>
> Udo wrote:
>> Hi Ed,
>>
>> Quote:
>>> Check during serialization if eIsSet is being called for the value
>>> feature of the map entry and if it's returning true. It should be
>>> serialized in that case.
>>
>>
>> I checked the method eIsSet of my EStringToVartabEntryMapEntryImpl and
>> it returns true. I did this by overwriting the method eIsSet in that
>> class and checking the name of the feature and value of the
>> super.eIsSet() method. The value feature returns true.
>>
>> My output still looks like this:
>>
>>
>> <variables>
>> <vartabEntriesMap key="0:grust"/>
>> <vartabEntriesMap key="0:gruppe"/>
>> <vartabEntriesMap key="0:grbez"/>
>> <vartabEntriesMap key="0:dnr"/>
>> <vartabEntriesMap key="0:dbez"/>
>> <vartabEntriesMap key="0:ozeilen"/>
>> ..
>>
>>
>> Still only keys.
>> Do you have any ideas what I could do wrong?
>>
>>
Re: Serialization problem concerning Maps [message #638266 is a reply to message #638066] Wed, 10 November 2010 14:38 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30559
Registered: July 2009
Senior Member
Udo,

Comments below.


Udo Walker wrote:
> Hi Ed,
>
> I found a solution but I don't know how to do it with annotations in
> my interfaces.
You can always generate the code to see what @model annotations are
generated. Delete the method and let it me regenerated if necessary.
>
> If I open the *.ecore file and go to the value feature of the map and
> change the containment from (default) "false" to "true" then the value
> which is my from EMF generated object is also saved.
>
> How can I tell the EMF generator with Java annotations that the value
> of my map needs the containment attribute set to "true"?
I'm not sure what you did that made if false. There is a FAQ about this.
>
> Here is the snippet from my ecore file:
>
> <eClassifiers xsi:type="ecore:EClass" name="VartabEntryMap"
> instanceClassName="java.util.Map$Entry">
> <eStructuralFeatures
> xsi:type="ecore:EAttribute"
> name="key"
> eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"/>
> <eStructuralFeatures
> xsi:type="ecore:EReference"
> name="value"
> eType="#//VartabEntry"
> containment="true"/>
> </eClassifiers>
>
> The second last line is the important one. How to do that in Java
> annotations?
>
> Udo
>
>
> Am 27.08.2010 16:12, schrieb Ed Merks:
>> Udo,
>>
>> The debugger is doing to answer your questions faster than me. Monitor
>> what happens in XMLSaveImpl.saveFeatures for your map entry instances.
>> Pay particular attention to the processing of the features where there
>> is a guard like this
>>
>> if (kind != TRANSIENT && shouldSaveFeature(o, f))
>>
>>
>> Udo wrote:
>>> Hi Ed,
>>>
>>> Quote:
>>>> Check during serialization if eIsSet is being called for the value
>>>> feature of the map entry and if it's returning true. It should be
>>>> serialized in that case.
>>>
>>>
>>> I checked the method eIsSet of my EStringToVartabEntryMapEntryImpl and
>>> it returns true. I did this by overwriting the method eIsSet in that
>>> class and checking the name of the feature and value of the
>>> super.eIsSet() method. The value feature returns true.
>>>
>>> My output still looks like this:
>>>
>>>
>>> <variables>
>>> <vartabEntriesMap key="0:grust"/>
>>> <vartabEntriesMap key="0:gruppe"/>
>>> <vartabEntriesMap key="0:grbez"/>
>>> <vartabEntriesMap key="0:dnr"/>
>>> <vartabEntriesMap key="0:dbez"/>
>>> <vartabEntriesMap key="0:ozeilen"/>
>>> ..
>>>
>>>
>>> Still only keys.
>>> Do you have any ideas what I could do wrong?
>>>
>>>
>
Previous Topic:Ecore Model
Next Topic:Creating Children You Didn't Know Existed revisited
Goto Forum:
  


Current Time: Wed Oct 23 12:25:33 GMT 2019

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

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

Back to the top