Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Class Cast exception thrown for an EMap during model instantiation
icon8.gif  Class Cast exception thrown for an EMap during model instantiation [message #1053441] Sun, 05 May 2013 22:20 Go to next message
Greg Mising name is currently offline Greg Mising name
Messages: 47
Registered: July 2009
Member
I have implemented a reference to a class that I've assigned an instance class name of java.util.Map$Entry, thus using it as an EMap. When I start my editor and run through the wizard it instantiates the model and assigns the root object to the xml serialization object. In doing so it iterates through a tree of all the contents of the model from the root object. This is in the method ResourceImpl.attached( EObject ). The code progresses down to EContentsEList.hasNext() where the following code is called.

else
                  {
                    @SuppressWarnings("unchecked") InternalEList<E> newValueList = (InternalEList<E>)value;
                    valueList = valueInternalEList = newValueList;
                  }


Here the value that is being cast as an InternalEList is the EBasicMap implementation of my Map$Entry reference. This is where it is throwing a class cast exception.

Am I doing something wrong in my design or code or is this a bug in EMF?

Thanks.
Greg
Re: Class Cast exception thrown for an EMap during model instantiation [message #1053457 is a reply to message #1053441] Mon, 06 May 2013 05:56 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26152
Registered: July 2009
Senior Member
Greg,


On 06/05/2013 12:20 AM, Greg Mising name wrote:
> I have implemented a reference to a class that I've assigned an
> instance class name of java.util.Map$Entry, thus using it as an EMap.
What does it's generated implementation look like? Is the reference a
multi-valued containment?
> When I start my editor and run through the wizard it instantiates the
> model and assigns the root object to the xml serialization object. In
> doing so it iterates through a tree of all the contents of the model
> from the root object. This is in the method ResourceImpl.attached(
> EObject ). The code progresses down to EContentsEList.hasNext() where
> the following code is called.
>
>
> else
> {
> @SuppressWarnings("unchecked") InternalEList<E>
> newValueList = (InternalEList<E>)value;
> valueList = valueInternalEList = newValueList;
> }
>
>
> Here the value that is being cast as an InternalEList is the EBasicMap
> implementation of my Map$Entry reference. This is where it is
> throwing a class cast exception.
>
> Am I doing something wrong in my design or code or is this a bug in EMF?
It works for Ecore's EStringToStringMapEntry EClass, so you must have
done something slightly different
>
> Thanks.
> Greg
Re: Class Cast exception thrown for an EMap during model instantiation [message #1053548 is a reply to message #1053457] Mon, 06 May 2013 13:21 Go to previous messageGo to next message
Greg Mising name is currently offline Greg Mising name
Messages: 47
Registered: July 2009
Member
Hi Ed,

Yes, it's a multi-valued containment. I've attached a screenshot of the model objects. LocaleStringMap has an instance class name of java.util.Map$Entry, so the three references are implemented as EMaps.

The three references are initialized as follows:
protected NamedModelObjectImpl() {
		super();
		localeName = new BasicEMap<String,String>();
		localeDescription = new BasicEMap<String,String>();
		localeTooltip = new BasicEMap<String,String>();
	}


Thanks for your help.

Cheers,
Greg
Re: Class Cast exception thrown for an EMap during model instantiation [message #1053563 is a reply to message #1053548] Mon, 06 May 2013 14:32 Go to previous messageGo to next message
Ed Merks is currently offline Ed Merks
Messages: 26152
Registered: July 2009
Senior Member
Greg,

Comments below.

On 06/05/2013 3:21 PM, Greg Mising name wrote:
> Hi Ed,
>
> Yes, it's a multi-valued containment. I've attached a screenshot of the model objects. LocaleStringMap has an instance class name of java.util.Map$Entry, so the three references are implemented as EMaps.
>
> The three references are initialized as follows:
>
> protected NamedModelObjectImpl() {
> super();
> localeName = new BasicEMap<String,String>();
> localeDescription = new BasicEMap<String,String>();
> localeTooltip = new BasicEMap<String,String>();
You hand wrote this? Generated implementations would use EcoreEMap, so
this doesn't look generated.
> }
>
>
> Thanks for your help.
>
> Cheers,
> Greg
Re: Class Cast exception thrown for an EMap during model instantiation [message #1053601 is a reply to message #1053563] Mon, 06 May 2013 16:55 Go to previous message
Greg Mising name is currently offline Greg Mising name
Messages: 47
Registered: July 2009
Member
Ah, now I see my mistake. The hash maps are initialized in the get methods. Thanks. That fixed the problem.
Previous Topic:[Teneo] Using ChangeRecorder and persisting ChangeDescription models
Next Topic:Pasting and ID handling
Goto Forum:
  


Current Time: Fri Oct 31 12:20:19 GMT 2014

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

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