Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Map in Map ArrayStoreException
Map in Map ArrayStoreException [message #949253] Thu, 18 October 2012 21:08 Go to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Hello,

I don't know what exactly happened, but at the moment I can't use EMap in EMap any longer.
I used the recipe http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_create_a_Map_in_EMF.3F

EMap<String, EMap<String, FieldData>> headerData = command.getHeaderData();
BasicEMap<String, FieldData> hData = new BasicEMap<String, FieldData>();
FieldData d = DataFactory.eINSTANCE.createFieldData();
hData.put(key, d);
// ...
headerData.put(key, hData);


The following code leads into the ArrayStoreException.

I don't understand, why it suddenly stopped working.
Is there a problem with using EMaps in EMaps?
Re: Map in Map ArrayStoreException [message #949260 is a reply to message #949253] Thu, 18 October 2012 21:16 Go to previous messageGo to next message
John M. is currently offline John M.Friend
Messages: 198
Registered: July 2010
Senior Member
Creating an entry of the StringToFieldData solved the problem, but now I have a unchecked cast.
Is there a better solution?
Re: Map in Map ArrayStoreException [message #949607 is a reply to message #949253] Fri, 19 October 2012 05:45 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 26285
Registered: July 2009
Senior Member
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
John,<br>
<br>
Comments below.<br>
<br>
<div class="moz-cite-prefix">On 18/10/2012 11:08 PM, John M. wrote:<br>
</div>
<blockquote cite="mid:k5pr4v$3ni$1@xxxxxxxxe.org" type="cite">Hello,
<br>
<br>
I don't know what exactly happened, but at the moment I can't use
EMap in EMap any longer.
<br>
I used the recipe
<a class="moz-txt-link-freetext" href="http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_create_a_Map_in_EMF.3F">http://wiki.eclipse.org/index.php/EMF-FAQ#How_do_I_create_a_Map_in_EMF.3F</a><br>
<br>
<br>
EMap&lt;String, EMap&lt;String, FieldData&gt;&gt; headerData =
command.getHeaderData();
<br>
BasicEMap&lt;String, FieldData&gt; hData = new
BasicEMap&lt;String, FieldData&gt;();
<br>
FieldData d = DataFactory.eINSTANCE.createFieldData();
<br>
hData.put(key, d);
<br>
// ...
<br>
headerData.put(key, hData);
<br>
<br>
<br>
The following code leads into the ArrayStoreException.
<br>
</blockquote>
You must allow the framework to create right implementation classes
because EMaps are lists and what you do above will try to add the
elements of hData to the head data's value feature, which is
strongly typed to expect map entries that are the right type of
EObject sublcass, i.e., the map entry class for String/FieldData. 
You can only create such things reflectively with
EcoreUtil.create(EClass) but them must do an unsafe cast:  This
should work better without such casts.<br>
<blockquote>headerData.put(key, ECollections.emptyEMap());<br>
EMap&lt;String, FieldData&gt;&gt; hData = headerData.get(key);<br>
hData.put(key, d);<br>
</blockquote>
<br>
<blockquote cite="mid:k5pr4v$3ni$1@xxxxxxxxe.org" type="cite">
<br>
I don't understand, why it suddenly stopped working.
<br>
Is there a problem with using EMaps in EMaps?
<br>
</blockquote>
<br>
</body>
</html>
Previous Topic:[CDO] Evaluating CDO
Next Topic:DND with InputDialog
Goto Forum:
  


Current Time: Sun Dec 21 03:22:56 GMT 2014

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

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