Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » BasicEMap not an InternalEObject?
BasicEMap not an InternalEObject? [message #415783] Sun, 06 January 2008 22:05 Go to next message
Eclipse UserFriend
Originally posted by: eclipse.efef.dk

org.eclipse.emf.common.util.BasicEMap cannot be cast to
org.eclipse.emf.ecore.InternalEObject

Can be reproduced by this small example

(using EMF ecore 2.3.1.v200709252135).

What am I doing wrong? (I suppose I should get the EMap from somewhere
else, a factory probably, but it fails me, so the BasicEMap seemed like
a nice shortcut).

Cheers,
/\/ikolaj

=========== BEGIN MapContainer ========================================
package test;

import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EObject;

/**
* @author berntsen
* @model
* <!-- begin-model-doc -->
* <!-- end-model-doc -->
*
*/
public interface MapContainer extends EObject {

/**
* @model containment="true"
*
* @return
*/
EMap<String, String> getStrStrMap();

/**
* Sets the value of the '{@link test.MapContainer#getStrStrMap <em>Str
Str Map</em>}' containment reference.
* <!-- begin-user-doc -->
* <!-- end-user-doc -->
* @param value the new value of the '<em>Str Str Map</em>' containment
reference.
* @see #getStrStrMap()
* @generated
*/
void setStrStrMap(EMap<String, String> value);
}
=========== END MapContainer ========================================


=========== BEGIN Driver ========================================
package driver;

import org.eclipse.emf.common.util.BasicEMap;
import org.eclipse.emf.common.util.EMap;

import test.MapContainer;
import test.TestFactory;

public class Driver {

public static void main(String[] args) {
MapContainer mapContainer = TestFactory.eINSTANCE.createMapContainer();
System.out.println(mapContainer.getStrStrMap()); // null
// so we want to create an EMap:

EMap<String, String> strStrEMap = new BasicEMap<String, String>();
strStrEMap.put("1", "2");

mapContainer.setStrStrMap(strStrEMap);

System.out.println(mapContainer);
}
}

=========== END Driver ========================================

=========== BEGIN system.out ========================================
null
Exception in thread "main" java.lang.ClassCastException:
org.eclipse.emf.common.util.BasicEMap cannot be cast to
org.eclipse.emf.ecore.InternalEObject
at test.impl.MapContainerImpl.setStrStrMap(MapContainerImpl.jav a:101)
at driver.Driver.main(Driver.java:19)
=========== END system.out ========================================
Re: BasicEMap not an InternalEObject? [message #415785 is a reply to message #415783] Sun, 06 January 2008 23:48 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
Bernsten,

No, a basic EMap is a collection, not an EObject. The value returned
(EObject.eGet()) for a many-valued features
(EStructuralFeature.isMany()) cannot be cast to EObject. I have no
idea what kind of model could a resulted in the API you are showing.
Could you share the model that gives rise to such a thing?


berntsen wrote:
> org.eclipse.emf.common.util.BasicEMap cannot be cast to
> org.eclipse.emf.ecore.InternalEObject
>
> Can be reproduced by this small example
>
> (using EMF ecore 2.3.1.v200709252135).
>
> What am I doing wrong? (I suppose I should get the EMap from somewhere
> else, a factory probably, but it fails me, so the BasicEMap seemed like
> a nice shortcut).
>
> Cheers,
> /\/ikolaj
>
> =========== BEGIN MapContainer ========================================
> package test;
>
> import org.eclipse.emf.common.util.EMap;
> import org.eclipse.emf.ecore.EObject;
>
> /**
> * @author berntsen
> * @model
> * <!-- begin-model-doc -->
> * <!-- end-model-doc -->
> *
> */
> public interface MapContainer extends EObject {
>
> /**
> * @model containment="true"
> *
> * @return
> */
> EMap<String, String> getStrStrMap();
>
> /**
> * Sets the value of the '{@link test.MapContainer#getStrStrMap <em>Str
> Str Map</em>}' containment reference.
> * <!-- begin-user-doc -->
> * <!-- end-user-doc -->
> * @param value the new value of the '<em>Str Str Map</em>' containment
> reference.
> * @see #getStrStrMap()
> * @generated
> */
> void setStrStrMap(EMap<String, String> value);
> }
> =========== END MapContainer ========================================
>
>
> =========== BEGIN Driver ========================================
> package driver;
>
> import org.eclipse.emf.common.util.BasicEMap;
> import org.eclipse.emf.common.util.EMap;
>
> import test.MapContainer;
> import test.TestFactory;
>
> public class Driver {
>
> public static void main(String[] args) {
> MapContainer mapContainer = TestFactory.eINSTANCE.createMapContainer();
> System.out.println(mapContainer.getStrStrMap()); // null
> // so we want to create an EMap:
>
> EMap<String, String> strStrEMap = new BasicEMap<String, String>();
> strStrEMap.put("1", "2");
>
> mapContainer.setStrStrMap(strStrEMap);
>
> System.out.println(mapContainer);
> }
> }
>
> =========== END Driver ========================================
>
> =========== BEGIN system.out ========================================
> null
> Exception in thread "main" java.lang.ClassCastException:
> org.eclipse.emf.common.util.BasicEMap cannot be cast to
> org.eclipse.emf.ecore.InternalEObject
> at test.impl.MapContainerImpl.setStrStrMap(MapContainerImpl.jav a:101)
> at driver.Driver.main(Driver.java:19)
> =========== END system.out ========================================
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: BasicEMap not an InternalEObject? [message #415805 is a reply to message #415785] Mon, 07 January 2008 22:19 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipse.efef.dk

Dear Ed,

Ed Merks wrote:
> Bernsten,

Berntsen, or just /\/ikolaj ;)

> No, a basic EMap is a collection, not an EObject. The value returned

Hm. never thought of that, but I would have assumed the E- was for
EObject, nevermind.

> (EObject.eGet()) for a many-valued features
> (EStructuralFeature.isMany()) cannot be cast to EObject. I have no
> idea what kind of model could a resulted in the API you are showing.

Basically, I just like to be able to annotate stuff with key-value pairs
when modelling. Nothing really deep. Guess it could be Lists og
Entry-like things instead. An intuitive motivation could that when
using, e.g. hibernate (using the really nice teneo, for example) to
persist the model to a RDBMS with cascade fetch, it probaby yields
faster sql (I must confess, I never verified this hunch) to have the key
values in a Map (possibly Map<key, List<value>>). Even without the RDBMS
mapping, it is easier to write more optimal code (accepting the
performance hit of having read almost everything in, DOM-style), when
using Maps in the model, when the purpose of the Map/List thing is to
find something using the properties, rather than doint something to the
whole collection.

If you, with your heavy modelling experience, can tell me I am astray in
my above intuitive ideas, I would appreciate advice.

> Could you share the model that gives rise to such a thing?

Simply the interface, MapContainer, below. That is just an example, but
I would like to be able to use EMap<k,v> in my models.

Can you point to a proper way use EMap<k,v> in an EMF model? Defined in
a java interface, and a way to contstruct the EMap by hand, if the
generated java code does not initialise the get'ter with an EMap (as
does the similar construction List<MyKVEntry<K,V>> [1]).

[1] I have not actually used List<MyKVEntry<K,V>>, rather I have
resorted to a quick and dirty List<StringStringEntry> which does indeed
come initialised with a EList in the getter.

Thanks for your time,
/\/ikolaj

>
>
> berntsen wrote:
>> org.eclipse.emf.common.util.BasicEMap cannot be cast to
>> org.eclipse.emf.ecore.InternalEObject
>>
>> Can be reproduced by this small example
>>
>> (using EMF ecore 2.3.1.v200709252135).
>>
>> What am I doing wrong? (I suppose I should get the EMap from somewhere
>> else, a factory probably, but it fails me, so the BasicEMap seemed like
>> a nice shortcut).
>>
>> Cheers,
>> /\/ikolaj
>>
>> =========== BEGIN MapContainer ========================================
>> package test;
>>
>> import org.eclipse.emf.common.util.EMap;
>> import org.eclipse.emf.ecore.EObject;
>>
>> /**
>> * @author berntsen
>> * @model
>> * <!-- begin-model-doc -->
>> * <!-- end-model-doc -->
>> *
>> */
>> public interface MapContainer extends EObject {
>>
>> /**
>> * @model containment="true"
>> *
>> * @return
>> */
>> EMap<String, String> getStrStrMap();
>>
>> /**
>> * Sets the value of the '{@link test.MapContainer#getStrStrMap
>> <em>Str
>> Str Map</em>}' containment reference.
>> * <!-- begin-user-doc -->
>> * <!-- end-user-doc -->
>> * @param value the new value of the '<em>Str Str Map</em>'
>> containment
>> reference.
>> * @see #getStrStrMap()
>> * @generated
>> */
>> void setStrStrMap(EMap<String, String> value);
>> }
>> =========== END MapContainer ========================================
>>
>>
>> =========== BEGIN Driver ========================================
>> package driver;
>>
>> import org.eclipse.emf.common.util.BasicEMap;
>> import org.eclipse.emf.common.util.EMap;
>>
>> import test.MapContainer;
>> import test.TestFactory;
>>
>> public class Driver {
>>
>> public static void main(String[] args) {
>> MapContainer mapContainer =
>> TestFactory.eINSTANCE.createMapContainer();
>> System.out.println(mapContainer.getStrStrMap()); // null
>> // so we want to create an EMap:
>>
>> EMap<String, String> strStrEMap = new BasicEMap<String,
>> String>();
>> strStrEMap.put("1", "2");
>>
>> mapContainer.setStrStrMap(strStrEMap);
>>
>> System.out.println(mapContainer);
>> }
>> }
>>
>> =========== END Driver ========================================
>>
>> =========== BEGIN system.out ========================================
>> null
>> Exception in thread "main" java.lang.ClassCastException:
>> org.eclipse.emf.common.util.BasicEMap cannot be cast to
>> org.eclipse.emf.ecore.InternalEObject
>> at test.impl.MapContainerImpl.setStrStrMap(MapContainerImpl.jav a:101)
>> at driver.Driver.main(Driver.java:19)
>> =========== END system.out ========================================
>>
>>
Re: BasicEMap not an InternalEObject? [message #415816 is a reply to message #415805] Tue, 08 January 2008 13:15 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33142
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------030903050607090605010208
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Nokolaj,

I have a habit of just copying the name of the sender but try to
remember to look at the signature on the bottom...

More comments below.


berntsen wrote:
> Dear Ed,
>
> Ed Merks wrote:
>
>> Bernsten,
>>
>
> Berntsen, or just /\/ikolaj ;)
>
>
>> No, a basic EMap is a collection, not an EObject. The value returned
>>
>
> Hm. never thought of that, but I would have assumed the E- was for
> EObject, nevermind.
>
I though E for for electronic or was that Eclipse? We certainly were in
e-crazy times as the time EMF was first developed, with all the
e-business and all... And at that time, some folks has this notion,
which seems particularly misguided in hindsight that all other
metamodels (I rather dislike that word because I think a model is a
model and it's hard to argue that some particular thing makes it meta
instead) should extend Ecore and hence we should give the Ecore mode
yucky names so that other models could use the nice names. How lovely
is that?
>
>> (EObject.eGet()) for a many-valued features
>> (EStructuralFeature.isMany()) cannot be cast to EObject. I have no
>> idea what kind of model could a resulted in the API you are showing.
>>
>
> Basically, I just like to be able to annotate stuff with key-value pairs
> when modelling.
Kind of like EAnnotation and its getDetails map...
> Nothing really deep. Guess it could be Lists og
> Entry-like things instead.
An EMap really is just a EList with the extra ability to view and treat
it like map.
> An intuitive motivation could that when
> using, e.g. hibernate (using the really nice teneo
It's awesome hey! We have such a good community and folks like Martin
are exemplary of that.
> , for example) to
> persist the model to a RDBMS with cascade fetch, it probaby yields
> faster sql (I must confess, I never verified this hunch) to have the key
> values in a Map (possibly Map<key, List<value>>).
Such a think can be directly modeled. The map entries are actually
instances of EClass and the key and value features can be any arbitrary
type of feature; and the EMap itself is just a containment list of such
entries.
> Even without the RDBMS
> mapping, it is easier to write more optimal code (accepting the
> performance hit of having read almost everything in, DOM-style), when
> using Maps in the model, when the purpose of the Map/List thing is to
> find something using the properties, rather than doint something to the
> whole collection.
>
The value could even be another contained EObject...
> If you, with your heavy modelling experience, can tell me I am astray in
> my above intuitive ideas, I would appreciate advice.
>
It sounds okay to me. You just have to remember that an EMap is a
collection not a single EObject and that in the modeling since, it's in
fact a containment list of EObject's that implement java.util.Map.Entry.
>
>> Could you share the model that gives rise to such a thing?
>>
>
> Simply the interface, MapContainer, below. That is just an example, but
> I would like to be able to use EMap<k,v> in my models.
>
> Can you point to a proper way use EMap<k,v> in an EMF model?
EAnnotation.getDetails is an example.
> Defined in
> a java interface, and a way to contstruct the EMap by hand, if the
> generated java code does not initialise the get'ter with an EMap (as
> does the similar construction List<MyKVEntry<K,V>> [1]).
>
Basically you need to create a multi-valued containment reference to
some EClass, and that EClass needs to have a feature called "key" and a
feature called "value" and must set the instanceClassName to
java.util.Map$Entry. That's about it. If you construct such a thing
and generated the Java, you can see how it's defined using @model
annotations.
> [1] I have not actually used List<MyKVEntry<K,V>>, rather I have
> resorted to a quick and dirty List<StringStringEntry> which does indeed
> come initialised with a EList in the getter.
>
With Java 5.0 we support things like this on the getter:

* @model
mapType="org.eclipse.emf.ecore.EStringToStringMapEntry<org.eclipse.emf.ecore.EString,
org.eclipse.emf.ecore.EString>"

To do more fancy things, like containment references or multi-valued
features, you'd need to specify such details in the XyzPackage's
accessor the EClass:

* @see java.util.Map.Entry
* @model keyDataType="org.eclipse.emf.ecore.EString"
* valueDataType="org.eclipse.emf.ecore.EString"
* @generated
*/
EClass getEStringToStringMapEntry();

> Thanks for your time,
> /\/ikolaj
>
>
>> berntsen wrote:
>>
>>> org.eclipse.emf.common.util.BasicEMap cannot be cast to
>>> org.eclipse.emf.ecore.InternalEObject
>>>
>>> Can be reproduced by this small example
>>>
>>> (using EMF ecore 2.3.1.v200709252135).
>>>
>>> What am I doing wrong? (I suppose I should get the EMap from somewhere
>>> else, a factory probably, but it fails me, so the BasicEMap seemed like
>>> a nice shortcut).
>>>
>>> Cheers,
>>> /\/ikolaj
>>>
>>> =========== BEGIN MapContainer ========================================
>>> package test;
>>>
>>> import org.eclipse.emf.common.util.EMap;
>>> import org.eclipse.emf.ecore.EObject;
>>>
>>> /**
>>> * @author berntsen
>>> * @model
>>> * <!-- begin-model-doc -->
>>> * <!-- end-model-doc -->
>>> *
>>> */
>>> public interface MapContainer extends EObject {
>>>
>>> /**
>>> * @model containment="true"
>>> *
>>> * @return
>>> */
>>> EMap<String, String> getStrStrMap();
>>>
>>> /**
>>> * Sets the value of the '{@link test.MapContainer#getStrStrMap
>>> <em>Str
>>> Str Map</em>}' containment reference.
>>> * <!-- begin-user-doc -->
>>> * <!-- end-user-doc -->
>>> * @param value the new value of the '<em>Str Str Map</em>'
>>> containment
>>> reference.
>>> * @see #getStrStrMap()
>>> * @generated
>>> */
>>> void setStrStrMap(EMap<String, String> value);
>>> }
>>> =========== END MapContainer ========================================
>>>
>>>
>>> =========== BEGIN Driver ========================================
>>> package driver;
>>>
>>> import org.eclipse.emf.common.util.BasicEMap;
>>> import org.eclipse.emf.common.util.EMap;
>>>
>>> import test.MapContainer;
>>> import test.TestFactory;
>>>
>>> public class Driver {
>>>
>>> public static void main(String[] args) {
>>> MapContainer mapContainer =
>>> TestFactory.eINSTANCE.createMapContainer();
>>> System.out.println(mapContainer.getStrStrMap()); // null
>>> // so we want to create an EMap:
>>>
>>> EMap<String, String> strStrEMap = new BasicEMap<String,
>>> String>();
>>> strStrEMap.put("1", "2");
>>>
>>> mapContainer.setStrStrMap(strStrEMap);
>>>
>>> System.out.println(mapContainer);
>>> }
>>> }
>>>
>>> =========== END Driver ========================================
>>>
>>> =========== BEGIN system.out ========================================
>>> null
>>> Exception in thread "main" java.lang.ClassCastException:
>>> org.eclipse.emf.common.util.BasicEMap cannot be cast to
>>> org.eclipse.emf.ecore.InternalEObject
>>> at test.impl.MapContainerImpl.setStrStrMap(MapContainerImpl.jav a:101)
>>> at driver.Driver.main(Driver.java:19)
>>> =========== END system.out ========================================
>>>
>>>
>>>


--------------030903050607090605010208
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Nokolaj,<br>
<br>
I have a habit of just copying the name of the sender but try to
remember to look at the signature on the bottom...<br>
<br>
More comments below.<br>
<br>
<br>
berntsen wrote:
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">Dear Ed,

Ed Merks wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Bernsten,
</pre>
</blockquote>
<pre wrap=""><!---->
Berntsen, or just /\/ikolaj ;)

</pre>
<blockquote type="cite">
<pre wrap="">No, a basic EMap is a collection, not an EObject. The value returned
</pre>
</blockquote>
<pre wrap=""><!---->
Hm. never thought of that, but I would have assumed the E- was for
EObject, nevermind.
</pre>
</blockquote>
I though E for for electronic or was that Eclipse?&nbsp; We certainly were
in e-crazy times as the time EMF was first developed, with all the
e-business and all...&nbsp; And at that time, some folks has this notion,
which seems particularly misguided in hindsight that all other
metamodels (I rather dislike that word because I think a model is a
model and it's hard to argue that some particular thing makes it meta
instead) should extend Ecore and hence we should give the Ecore mode
yucky names so that other models could use the nice names.&nbsp; How lovely
is that?<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<pre wrap="">(EObject.eGet()) for a many-valued features
(EStructuralFeature.isMany()) cannot be cast to EObject. I have no
idea what kind of model could a resulted in the API you are showing.
</pre>
</blockquote>
<pre wrap=""><!---->
Basically, I just like to be able to annotate stuff with key-value pairs
when modelling. </pre>
</blockquote>
Kind of like EAnnotation and its getDetails map...<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">Nothing really deep. Guess it could be Lists og
Entry-like things instead. </pre>
</blockquote>
An EMap really is just a EList with the extra ability to view and treat
it like map.<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">An intuitive motivation could that when
using, e.g. hibernate (using the really nice teneo</pre>
</blockquote>
It's awesome hey!&nbsp; We have such a good community and folks like Martin
are exemplary of that.<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">, for example) to
persist the model to a RDBMS with cascade fetch, it probaby yields
faster sql (I must confess, I never verified this hunch) to have the key
values in a Map (possibly Map&lt;key, List&lt;value&gt;&gt;). </pre>
</blockquote>
Such a think can be directly modeled.&nbsp; The map entries are actually
instances of EClass and the key and value features can be any arbitrary
type of feature; and the EMap itself is just a containment list of such
entries.<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">Even without the RDBMS
mapping, it is easier to write more optimal code (accepting the
performance hit of having read almost everything in, DOM-style), when
using Maps in the model, when the purpose of the Map/List thing is to
find something using the properties, rather than doint something to the
whole collection.
</pre>
</blockquote>
The value could even be another contained EObject...<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">
If you, with your heavy modelling experience, can tell me I am astray in
my above intuitive ideas, I would appreciate advice.
</pre>
</blockquote>
It sounds okay to me.&nbsp; You just have to remember that an EMap is a
collection not a single EObject and that in the modeling since, it's in
fact a containment list of EObject's that implement java.util.Map.Entry.<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">
</pre>
<blockquote type="cite">
<pre wrap="">Could you share the model that gives rise to such a thing?
</pre>
</blockquote>
<pre wrap=""><!---->
Simply the interface, MapContainer, below. That is just an example, but
I would like to be able to use EMap&lt;k,v&gt; in my models.

Can you point to a proper way use EMap&lt;k,v&gt; in an EMF model?</pre>
</blockquote>
EAnnotation.getDetails is an example.<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap=""> Defined in
a java interface, and a way to contstruct the EMap by hand, if the
generated java code does not initialise the get'ter with an EMap (as
does the similar construction List&lt;MyKVEntry&lt;K,V&gt;&gt; [1]).
</pre>
</blockquote>
Basically you need to create a multi-valued containment reference to
some EClass, and that EClass needs to have a feature called "key" and a
feature called "value" and must set the instanceClassName to
java.util.Map$Entry.&nbsp; That's about it.&nbsp; If you construct such a thing
and generated the Java, you can see how it's defined using @model
annotations.<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">
[1] I have not actually used List&lt;MyKVEntry&lt;K,V&gt;&gt;, rather I have
resorted to a quick and dirty List&lt;StringStringEntry&gt; which does indeed
come initialised with a EList in the getter.
</pre>
</blockquote>
With Java 5.0 we support things like this on the getter:<br>
<br>
&nbsp;&nbsp; * @model
mapType=" org.eclipse.emf.ecore.EStringToStringMapEntry&lt;org.ecl ipse.emf.ecore.EString,
org.eclipse.emf.ecore.EString&gt;"<br>
<br>
To do more fancy things, like containment references or multi-valued
features, you'd need to specify such details in the XyzPackage's
accessor the EClass:<br>
<br>
&nbsp;&nbsp; * @see java.util.Map.Entry<br>
&nbsp;&nbsp; * @model keyDataType="org.eclipse.emf.ecore.EString"<br>
&nbsp;&nbsp; *&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp; valueDataType="org.eclipse.emf.ecore.EString"<br>
&nbsp;&nbsp; * @generated<br>
&nbsp;&nbsp; */<br>
&nbsp; EClass getEStringToStringMapEntry();<br>
<br>
<blockquote cite="mid:4782A584.3070402@efef.dk" type="cite">
<pre wrap="">
Thanks for your time,
/\/ikolaj

</pre>
<blockquote type="cite">
<pre wrap="">
berntsen wrote:
</pre>
<blockquote type="cite">
<pre wrap="">org.eclipse.emf.common.util.BasicEMap cannot be cast to
org.eclipse.emf.ecore.InternalEObject

Can be reproduced by this small example

(using EMF ecore 2.3.1.v200709252135).

What am I doing wrong? (I suppose I should get the EMap from somewhere
else, a factory probably, but it fails me, so the BasicEMap seemed like
a nice shortcut).

Cheers,
/\/ikolaj

=========== BEGIN MapContainer ========================================
package test;

import org.eclipse.emf.common.util.EMap;
import org.eclipse.emf.ecore.EObject;

/**
* @author berntsen
* @model
* &lt;!-- begin-model-doc --&gt;
* &lt;!-- end-model-doc --&gt;
*
*/
public interface MapContainer extends EObject {

/**
* @model containment="true"
*
* @return
*/
EMap&lt;String, String&gt; getStrStrMap();

/**
* Sets the value of the '{@link test.MapContainer#getStrStrMap
&lt;em&gt;Str
Str Map&lt;/em&gt;}' containment reference.
* &lt;!-- begin-user-doc --&gt;
* &lt;!-- end-user-doc --&gt;
* @param value the new value of the '&lt;em&gt;Str Str Map&lt;/em&gt;'
containment
reference.
* @see #getStrStrMap()
* @generated
*/
void setStrStrMap(EMap&lt;String, String&gt; value);
}
=========== END MapContainer ========================================


=========== BEGIN Driver ========================================
package driver;

import org.eclipse.emf.common.util.BasicEMap;
import org.eclipse.emf.common.util.EMap;

import test.MapContainer;
import test.TestFactory;

public class Driver {

public static void main(String[] args) {
MapContainer mapContainer =
TestFactory.eINSTANCE.createMapContainer();
System.out.println(mapContainer.getStrStrMap()); // null
// so we want to create an EMap:

EMap&lt;String, String&gt; strStrEMap = new BasicEMap&lt;String,
String&gt;();
strStrEMap.put("1", "2");

mapContainer.setStrStrMap(strStrEMap);

System.out.println(mapContainer);
}
}

=========== END Driver ========================================

=========== BEGIN system.out ========================================
null
Exception in thread "main" java.lang.ClassCastException:
org.eclipse.emf.common.util.BasicEMap cannot be cast to
org.eclipse.emf.ecore.InternalEObject
at test.impl.MapContainerImpl.setStrStrMap(MapContainerImpl.jav a:101)
at driver.Driver.main(Driver.java:19)
=========== END system.out ========================================


</pre>
</blockquote>
</blockquote>
</blockquote>
<br>
</body>
</html>

--------------030903050607090605010208--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:publishing ecore models to a website
Next Topic:Why wrapped exceptions?
Goto Forum:
  


Current Time: Fri Apr 26 23:26:40 GMT 2024

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

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

Back to the top